Log timestamp correction method and device and computer readable storage medium

By establishing a communication connection between the device and the host computer, and using the host computer time to synchronize the device timestamp, it solves the problem of device timing relying on hardware components, reduces hardware costs, improves the accuracy of timestamp correction, and achieves more stable time synchronization. .

CN118748576APending Publication Date: 2024-10-08DIANYUN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410776148.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-10-08

AI Technical Summary

Technical Problem

The timing method of existing equipment relies on hardware components such as RTC modules and NTP protocols, resulting in high hardware costs and strong dependence on hardware and networks, affecting the time accuracy and stability of the equipment.

Method used

By establishing a communication connection between the device and the host computer, and using the host computer time to synchronize the device timestamp, the device hardware cost is reduced, the dependence on the RTC module and NTP is reduced, and the accuracy of the timestamp correction is improved.

Benefits of technology

There is no need to set up the RTC module and NTP protocol, which reduces hardware costs, improves the accuracy of device time and the stability of the connection with the host computer, and ensures the accuracy of log timestamps.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118748576A_ABST
    Figure CN118748576A_ABST
Patent Text Reader

Abstract

The invention provides a log timestamp correction method and device and a computer readable storage medium, and the method comprises the steps: sending a time synchronization request to an upper computer when the device establishes a connection with the upper computer; according to the device starting time and the device current time when the device receives the actual time fed back by the upper computer, a to-be-corrected log needing timestamp correction in the device is determined; the equipment starting time is time information stored before the equipment is shut down last time; and performing timestamp correction on the to-be-corrected log through the actual time and the current time of the equipment when the equipment receives the actual time fed back by the upper computer. According to the method and the device, the communication connection is established between the equipment and the upper computer, and the timestamp of the log to be corrected is corrected based on the difference between the current time of the equipment and the time of the upper computer, so that an RTC module does not need to be arranged at the equipment end, and the hardware cost and the occupied space of the equipment are reduced. And an NTP does not need to be arranged, so that the dependence on hardware is reduced, and the stability of connection with the upper computer is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a log timestamp correction method, device and computer-readable storage medium. Background Art

[0002] Real-time timing is critical for devices. It is critical to ensure that the device can respond to external events, perform scheduled tasks, and maintain time-related operations on time. However, the traditional timing method of the device may rely on external hardware components, such as RTC modules (Real Time Clock, Chinese name: real-time clock module). Although these components can provide accurate time keeping functions, they increase the overall material cost of the device, and in some applications, additional power management circuits may be required to ensure the maintenance of time during power outages, which has a high hardware cost. Summary of the invention

[0003] In view of this, an object of the embodiments of the present application is to provide a log timestamp correction method, device and computer-readable storage medium, which can reduce the hardware cost of the device.

[0004] In a first aspect, an embodiment of the present application provides a log timestamp correction method, comprising: when a device establishes a connection with a host computer, sending a time synchronization request to the host computer; determining the log to be corrected in the device that needs to be timestamp corrected based on the device startup time and the device current time when the device receives the host computer time feedback from the host computer; wherein the device startup time is the time information saved during the last operation of the device; and timestamp correction is performed on the log to be corrected using the host computer time and the device current time when the device receives the host computer time feedback from the host computer.

[0005] In the above implementation process, by establishing a communication connection between the device and the host computer, after the device is started, the device time can be synchronized with the host computer time of the host computer, and the timestamp of the log to be corrected can be corrected based on the difference between the current device time and the host computer time. There is no need to set up an RTC module on the device side, which can reduce the hardware cost of the device and reduce the space occupied by the device. There is no need to set up NTP (Network Time Protocol, Chinese name: full name Network Time Protocol), because NTP requires the device to have stable access to the network and has a strong dependence on hardware and network. It can reduce the dependence on hardware and improve the stability of the connection with the host computer.

[0006] In one embodiment, when the device establishes a connection with a host computer, before sending a time synchronization request to the host computer, the method also includes: when the device is started, determining whether the device stores time information saved during the last operation; if it is determined that the device stores time information saved during the last operation, obtaining the time information and using the time information as the startup time of the device; taking the startup time of the device as the initial time, and performing real-time timing on the device after the device is started.

[0007] In the above implementation process, after the device is started, the time information of the last movement process stored is used as the initial time to perform real-time timing on the device. After the device synchronizes the host computer time, the log timestamp can be corrected according to the difference between the current time of the device and the host computer time, thereby improving the accuracy of the log timestamp and reflecting a more accurate event occurrence time.

[0008] In one embodiment, the log to be corrected in the device that needs to be timestamp corrected is determined based on the device startup time and the device current time when the device receives the host computer feedback host computer time, including: determining the time period from the device startup time to the device current time when the device receives the host computer feedback host computer time as the correction time range; determining the logs in the log list that are within the correction time range as the logs to be corrected; wherein the log list is a list of logs recorded in sequence by the device according to the order in which the logs are generated.

[0009] In the above implementation process, since the device time within the correction time range is obtained in real time based on the time information stored in the device, the device time within the correction time range may have errors, and therefore, the timestamps of the logs generated within the correction time range may also have errors. By correcting the timestamps of the logs within the correction time range as logs to be corrected, the accuracy of the log timestamps can be improved, thereby reflecting a more accurate time of event occurrence.

[0010] In one embodiment, the logs in the log list are recorded in sequence in each list row of the log list in the order in which the logs are generated; determining that the logs in the log list that are in the correction time range are the logs to be corrected includes: confirming the logs in the correction time range in sequence from the beginning to the end of the log list; determining that the list row is located before the time synchronization log and the logs in the correction time range are the logs to be corrected; wherein, the time synchronization log is a log generated when the current time of the device is synchronized with the host computer time fed back by the host computer received by the device.

[0011] In the above implementation process, the logs in the log list are screened from two aspects: the relationship between the log timestamp and the correction time range, and the relationship between the log record position and the time synchronization log position, to determine the log to be corrected, thereby avoiding correcting the timestamp of the log after time synchronization, affecting the accuracy of the log timestamp after time synchronization, and improving the accuracy of the log timestamp correction.

[0012] In one embodiment, the timestamp correction of the log to be corrected is performed using the host computer time and the device current time when the host computer feedbacks the host computer time received by the device, including: calculating the time difference between the device and the host computer according to the host computer time and the device current time when the host computer feedbacks the host computer time received by the device; calculating the actual time when the log to be corrected is generated according to the time difference and the timestamp of the log to be corrected; and updating the timestamp of the log to be corrected according to the actual time.

[0013] In the above implementation process, since the current time of the device and the host computer time are essentially the same time, the actual time when the log to be corrected occurred is deduced based on the time difference between the current time of the device and the host computer time, and the timestamp of the log to be corrected is corrected based on the actual time when the log to be corrected occurred. If the timing device loses time during shutdown, the time can also be restored based on the time difference, which can improve the time accuracy of the device and the accuracy of the log timestamp.

[0014] In one embodiment, the actual time when the log to be corrected is generated is calculated based on the time difference and the timestamp of the log to be corrected, including: determining the synchronization interval to which each log to be corrected belongs respectively, the synchronization interval being the time interval between when the device is started and when the device obtains the host computer time fed back by the host computer; for each log to be corrected, determining the time difference corresponding to the synchronization interval to which the log to be corrected belongs; wherein the time difference corresponding to each synchronization interval is the difference between the host computer time when the device obtains the host computer time fed back by the host computer corresponding to the synchronization time interval and the current time of the device when the device obtains the host computer time fed back by the host computer; the actual time when the log to be corrected is generated is calculated based on the time difference corresponding to the synchronization interval to which the log to be corrected belongs and the timestamp of the log to be corrected.

[0015] In the above implementation process, when the device has multiple start, stop, start, and stop operation processes, the timestamp of the log to be corrected in the operation process can be corrected according to the time difference between the host computer time and the current time of the device in each operation process of the device. Even if the device suddenly shuts down or restarts during operation, the log timestamp of the log to be corrected in each operation process of the device can be corrected, thereby more accurately reflecting the time of event occurrence.

[0016] In the second aspect, an embodiment of the present application also provides a device, including: a communication device and a processor; the communication device is used to send a time synchronization request to the host computer when the device establishes a connection with the host computer; the processor is used to determine the log to be corrected in the device that needs to be timestamped based on the device startup time and the device current time when the device receives the host computer time feedback from the host computer; wherein the device startup time is the time information saved during the last operation of the device; the processor is also used to perform timestamp correction on the log to be corrected using the host computer time and the device current time when the device receives the host computer time feedback from the host computer.

[0017] In the above implementation process, by establishing a communication connection between the device and the host computer, after the device is started, the device time can be synchronized with the host computer time of the host computer, and the timestamp of the log to be corrected can be corrected based on the difference between the current time of the device and the host computer time. There is no need to set up an RTC module (Real TimeClock, Chinese name: real-time clock module) on the device side, which can reduce the hardware cost of the device and reduce the space occupied by the device. There is no need to set up NTP (Network Time Protocol, Chinese name: full name Network Time Protocol), because NTP requires the device to have stable access to the network and has a strong dependence on hardware and network, which can reduce the dependence on hardware and improve the stability of the connection with the host computer.

[0018] In one embodiment, the communication device establishes a connection with the host computer via a universal serial bus.

[0019] In the above implementation process, a connection is established with the host computer through the universal serial bus. Since the universal serial bus does not require additional hardware support and has a small interface, the hardware cost and device size of the device can be reduced. In addition, for devices that have no network connection or are not allowed to connect to the network due to environmental restrictions, the connection with the host computer can also be achieved, increasing the application scenarios of the log timestamp correction method.

[0020] In one embodiment, the device further includes: a memory; the memory is used to store time information during the operation of the device.

[0021] In the above implementation process, a memory is set in the device to store time information during the operation of the device, so that the stored time information can be used as the device startup time during the subsequent operation of the device to time the device. There is no need to set corresponding real-time clock circuits and other hardware in the device, which can reduce the hardware cost of the device.

[0022] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the log timestamp correction method in the above-mentioned first aspect, or any possible implementation of the first aspect are executed.

[0023] In order to make the above-mentioned objects, features and advantages of the present application more obvious and understandable, embodiments are given below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0025] Figure 1 A schematic diagram of the interaction between the host computer and the device provided in the embodiment of the present application;

[0026] Figure 2 A block diagram of a device provided in an embodiment of the present application;

[0027] Figure 3 A flowchart of a log timestamp correction method provided in an embodiment of the present application;

[0028] Figure 4 A schematic diagram of a log list provided for an embodiment of the present application;

[0029] Figure 5 A schematic diagram of log timestamp correction in a log list provided in an embodiment of the present application;

[0030] Figure 6 A schematic diagram of the functional modules of the log timestamp correction device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0031] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings in the embodiments of the present application.

[0032] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0033] The inventor of the present application has found through long-term research that the timing of existing devices usually relies on RTC modules or NTP, etc., among which:

[0034] The RTC module is an independent clock chip that can continue to run when the device is turned off. The RTC module has its own power supply (usually a small battery) to ensure that the time information is not lost even when the main power is turned off. When the device starts, the system can read the current time from the RTC module to ensure the accuracy of the system time. However, the RTC module requires hardware support, which increases the cost and complexity of the design, and the long-term operation of the RTC module depends on the battery power. If the battery is exhausted, the time information may be lost.

[0035] NTP is a protocol used to synchronize computer time on the Internet. Devices can obtain accurate time information from NTP servers by connecting to the network to correct the system clock. This solution requires that the device can access the network and ensure the stability of the network connection to achieve time synchronization. However, NTP relies on network connection, which not only has certain requirements on the hardware and design of the device, but also requires the provision of a stable time synchronization server for the device to synchronize time in real time.

[0036] In view of this, the present application proposes a log timestamp correction method. By establishing a communication connection between the device and the host computer, after the device is started, the device time can be synchronized with the host computer time of the host computer, and based on the difference between the current time of the device and the host computer time, the timestamp of the log to be corrected is corrected. There is no need to set up an RTC module on the device side, which can reduce the hardware cost of the device and reduce the space occupied by the device. There is no need to set up NTP either. Since NTP requires the device to have stable access to the network and has a strong dependence on hardware and the network, it can reduce the dependence on hardware and improve the stability of the connection with the host computer.

[0037] To facilitate understanding of this embodiment, the operating environment of a log timestamp correction method disclosed in the embodiment of the present application is first introduced in detail.

[0038] like Figure 1, which is a schematic diagram of the interaction between the host computer and the device provided in the embodiment of the present application. The host computer is connected to one or more devices for data communication or interaction. The host computer can be a network server, a database server, a personal computer (PC) tablet computer, a smart phone, etc. The device can be a smart phone, a personal digital assistant (PDA), a smart socket, a door access control device, a smart watch, etc.

[0039] To facilitate understanding of this embodiment, first, an electronic device that executes the log timestamp correction method disclosed in the embodiment of the present application is introduced in detail.

[0040] like Figure 2 , which is a block diagram of a device. The device 100 may include a memory 111, a processor 113 and a communication device 115. A person skilled in the art will understand that Figure 2 The structure shown is only for illustration and does not limit the structure of the device 100. For example, the device 100 may also include Figure 2 More or fewer components as shown, or with Figure 2 Different configurations shown.

[0041] The memory 111, processor 113 and communication device 115 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The processor 113 is used to execute the executable module stored in the memory.

[0042] The memory 111 may be, but is not limited to, a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory 111 is used to store programs, and the processor 113 executes the program after receiving the execution instruction. The method executed by the device 100 defined by the process disclosed in any embodiment of the present application can be applied to the processor 113, or implemented by the processor 113.

[0043] The memory 111 here is used to store time information during the operation of the device.

[0044] The processor 113 may be an integrated circuit chip with signal processing capability. The processor 113 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0045] The communication device 115 is used to establish a communication connection with a host computer.

[0046] In one embodiment, the communication device establishes a connection with the host computer via a universal serial bus.

[0047] The device 100 in this embodiment can be used to execute each step in each method provided in the embodiment of the present application. The implementation process of the log timestamp correction method is described in detail below through several embodiments.

[0048] See also Figure 3 , is a flow chart of the log timestamp correction method provided by the embodiment of the present application. Figure 3 The specific process shown is described in detail.

[0049] Step 201: When the device establishes a connection with a host computer, a time synchronization request is sent to the host computer.

[0050] When the device is started, it automatically establishes a connection with the host computer. The host computer time in the host computer is the accurate system time.

[0051] The above time synchronization request can be sent to the host computer immediately when the device establishes a connection with the host computer; it can also be sent to the host computer at a set interval after the device establishes a connection with the host computer; it can also be sent to the host computer under the trigger of a specific trigger event after the device establishes a connection with the host computer. The time synchronization request can be sent to the host computer according to the actual situation.

[0052] Step 202 , according to the device startup time and the device current time when the host computer time is fed back by the host computer and received by the device, determine the log to be corrected in the device that needs to be timestamp corrected.

[0053] The device startup time is the time information saved during the last operation of the device.

[0054] Optionally, the time information saved during the last operation of the device may be the time information when the device was last powered off, the time information when the device was last shut down, or the real-time time information during the last movement of the device, etc. The time information may be selected according to actual conditions.

[0055] The device here does not have a real-time clock module, network time protocol or other time management hardware modules. Each time the device is started, the time information stored in the device is directly used as the device startup time.

[0056] The above-mentioned current time of the device is the device-side time corresponding to when the device receives the host computer time fed back by the host computer.

[0057] It can be understood that after the device is started, the device startup time is used as the initial time to count in real time to obtain the device end time. When the device receives the host computer time, the device end time of the device corresponds to the device end time on the device end, and the device end time is the current time of the device.

[0058] After receiving the host computer time, the device synchronizes the current device time with the host computer time and counts the device based on the host computer time.

[0059] It should be understood that before the device time is updated to the host computer time, the device time is obtained based on the time information of the last operation process stored in the device. There is usually a certain time interval between the last operation of the device and the current operation. The device time for the current operation based on the time information of the last operation may not be accurate. Therefore, the timestamp corresponding to the log generated during the period from device startup to the current time of the device may be incorrect and needs to be corrected.

[0060] Step 203, timestamp correction is performed on the log to be corrected by using the host computer time and the current time of the device when the host computer feedbacks the host computer time received by the device.

[0061] After receiving the host computer time feedback from the host computer, the device synchronizes the current time of the device with the host computer time.

[0062] It should be understood that the moment when the device receives the host computer time and the moment when the device is currently at the same time are theoretically the same moment, and the corresponding time is the same time. If there is a difference between the device's current time and the host computer time, the difference is the time difference between the host computer and the device. Therefore, the timestamp of the log to be corrected can be corrected according to the difference between the device's current time and the host computer time.

[0063] In the above implementation process, by establishing a communication connection between the device and the host computer, after the device is started, the device time can be synchronized with the host computer time of the host computer, and the timestamp of the log to be corrected can be corrected based on the difference between the current time of the device and the host computer time. There is no need to set up an RTC module (Real TimeClock, Chinese name: real-time clock module) on the device side, which can reduce the hardware cost of the device and reduce the space occupied by the device. There is no need to set up NTP (Network Time Protocol, Chinese name: full name Network Time Protocol), because NTP requires the device to have stable access to the network and has a strong dependence on hardware and network, which can reduce the dependence on hardware and improve the stability of the connection with the host computer.

[0064] In a possible implementation, before step 201, the method further includes: when the device is started, determining whether the device stores time information saved during the last operation; if it is determined that the device stores time information saved during the last operation, obtaining the time information and using the time information as the device startup time; using the device startup time as the initial time, and performing real-time timing on the device after the device is started.

[0065] If the device stores time information saved during the last operation, the time information is stored in a specific location of the device, such as a memory, a non-volatile storage medium, etc. The storage location of the time information can be selected according to actual conditions.

[0066] In one embodiment, if the device stores multiple pieces of time information saved during the last operation, the last saved time information is obtained, and the last saved time information is used as the device startup time.

[0067] It should be understood that after the device is started, the device startup time is used as the initial time to time the device in real time to obtain the device time, and the device time when the device receives the host computer time is used as the current time of the device.

[0068] In the above implementation process, after the device is started, the time information of the last movement process stored is used as the initial time to perform real-time timing on the device. After the device synchronizes the host computer time, the log timestamp can be corrected according to the difference between the current time of the device and the host computer time, thereby improving the accuracy of the log timestamp and reflecting a more accurate event occurrence time.

[0069] In a possible implementation, step 202 includes: determining the time period from the device startup time to the device current time when the device receives the host computer time feedback from the host computer as the correction time range; determining the logs in the log list that are within the correction time range as logs to be corrected.

[0070] The log list is a list of logs recorded by the device in the order in which the logs are generated.

[0071] like Figure 4 As shown, the log list here is a list used to record the time and log content of the event, such as 13:00 to open the camera, 13:30 to close the camera, 14:00 to open the camera, 15:00 to synchronize the time, etc.

[0072] It should be understood that after the device executes each log, the time and content of the execution of the log are recorded in the log list. If the device executes multiple logs, the time and content of the multiple logs are recorded in the log list in the order in which the logs are actually executed.

[0073] The log to be corrected can be determined based on the relationship between the timestamp of the log and the correction time range.

[0074] Exemplarily, if the host computer time is greater than the current time of the device, it can be determined whether the timestamp corresponding to the log recorded in the log list is within the correction time range. The log whose timestamp is within the correction time range is determined to be the log to be corrected.

[0075] In the above implementation process, since the device time within the correction time range is obtained in real time based on the time information stored in the device, the device time within the correction time range may have errors, and therefore, the timestamps of the logs generated within the correction time range may also have errors. By correcting the timestamps of the logs within the correction time range as logs to be corrected, the accuracy of the log timestamps can be improved, thereby reflecting a more accurate time of event occurrence.

[0076] In a possible implementation, determining that a log in a log list that is within a correction time range is a log to be corrected includes: confirming the logs within the correction time range in order from the beginning to the end of the log list; and determining that a list row is located before a time synchronization log and that the log is within the correction time range is a log to be corrected.

[0077] The time synchronization log is a log generated when the current time of the device is synchronized with the time of the host computer fed back by the host computer received by the device.

[0078] In one embodiment, the logs in the log list are recorded in the log list rows in sequence according to the log generation order, that is, each row in the log list is used to record the time and content of a log.

[0079] It can be understood that since the logs in the log list are recorded in the order in which they actually occurred, it can be determined that the logs recorded in the log list before the synchronization time log are logs to be corrected. Since the timestamps corresponding to the logs after the synchronization time log are the time after synchronization, which is the actual time of the device, no correction is required.

[0080] For example, Figure 5 As shown in the figure, if the device startup time is 13:00, the device current time is 15:00, and the host computer time is 14:00, the log timestamps and time contents included in the log list are: 13:00 camera turned on, 13:30 camera turned off, 14:10 camera turned on, 15:00 synchronization time, 14:45 camera turned off. Then the correction time range is 13:00-15:00, and the corresponding logs are all logs in the log list; and the logs in the list line before the time synchronization log include: 13:00 camera turned on, 13:30 camera turned off, 14:10 camera turned on, 15:00 synchronization time. Then the logs to be corrected include: 13:00 camera turned on, 13:30 camera turned off, 14:10 camera turned on, and 15:00 synchronization time.

[0081] In the above implementation process, the logs in the log list are screened from two aspects: the relationship between the log timestamp and the correction time range, and the relationship between the log record position and the time synchronization log position, to determine the log to be corrected, thereby avoiding correcting the timestamp of the log after time synchronization, affecting the accuracy of the log timestamp after time synchronization, and improving the accuracy of the log timestamp correction.

[0082] In a possible implementation, step 203 includes: calculating the time difference between the device and the host computer based on the host computer time and the device current time when the host computer receives the host computer time feedback from the device; calculating the actual time when the log to be corrected was generated based on the time difference and the timestamp of the log to be corrected; and updating the timestamp of the log to be corrected by the actual time.

[0083] For example, Figure 5Take the example to further show the specific implementation process of log timestamp update: the time difference between the device and the host computer = 14:00-15:00 = -1h. Then, the logs to be corrected in the log list, 13:00 camera turned on, 13:30 camera turned off, 14:10 camera turned on, and 15:00 synchronization time, can be corrected to: 12:00 camera turned on, 12:30 camera turned off, 13:10 camera turned on, and 12:00 synchronization time. Since 14:45 camera turned off occurs after time synchronization, it does not need to be updated.

[0084] In the above implementation process, since the current time of the device and the host computer time are essentially the same time, the actual time when the log to be corrected occurred is deduced based on the time difference between the current time of the device and the host computer time, and the timestamp of the log to be corrected is corrected based on the actual time when the log to be corrected occurred. If the timing device loses time during shutdown, the time can also be restored based on the time difference, which can improve the time accuracy of the device and the accuracy of the log timestamp.

[0085] In a possible implementation, the actual time when the log to be corrected is generated is calculated based on the time difference and the timestamp of the log to be corrected, including: determining the synchronization interval to which each log to be corrected belongs respectively; for each log to be corrected, determining the time difference corresponding to the synchronization interval to which the log to be corrected belongs; and calculating the actual time when the log to be corrected is generated based on the time difference corresponding to the synchronization interval to which the log to be corrected belongs and the timestamp of the log to be corrected.

[0086] The synchronization interval is the time interval between the start of the device and the time when the device obtains the host computer feedback.

[0087] The time difference corresponding to each synchronization interval here is the difference between the host computer time when the device obtains the host computer feedback corresponding to the synchronization time interval and the current time of the device when the device obtains the host computer time when the device obtains the host computer feedback.

[0088] Since the device startup time of each device operation is the stored time information of the last device operation, the device time in the later operation is usually slower than the device time in the previous operation. In addition, the device operation process in which the log to be corrected occurs can be determined based on the synchronization interval to which the log timestamp of the log to be corrected belongs.

[0089] It should be understood that for each operation of the device, the corresponding time difference can be determined according to the current time of the device and the host computer time during the operation, and the log timestamp of the log to be corrected in the operation can be corrected based on the determined time difference.

[0090] In the above implementation process, when the device has multiple start, stop, start, and stop operation processes, the timestamp of the log to be corrected in the operation process can be corrected according to the time difference between the host computer time and the current time of the device in each operation process of the device. Even if the device suddenly shuts down or restarts during operation, the log timestamp of the log to be corrected in each operation process of the device can be corrected, thereby more accurately reflecting the time of event occurrence.

[0091] Based on the same application concept, the embodiment of the present application also provides a log timestamp correction device corresponding to the log timestamp correction method. Since the principle of solving the problem by the device in the embodiment of the present application is similar to that of the aforementioned log timestamp correction method embodiment, the implementation of the device in this embodiment can refer to the description in the embodiment of the above method, and the repeated parts will not be repeated.

[0092] See also Figure 6 , is a functional module diagram of the log timestamp correction device provided in the embodiment of the present application. Each module in the log timestamp correction device in this embodiment is used to execute each step in the above method embodiment. The log timestamp correction device includes a connection module 301, a determination module 302, and a correction module 303; wherein,

[0093] The connection module 301 is used to send a time synchronization request to the host computer when the device establishes a connection with the host computer.

[0094] The determination module 302 is used to determine the log to be corrected in the device that needs to be timestamp corrected based on the device startup time and the device current time when the device receives the host computer time feedback from the host computer; wherein the device startup time is the time information saved during the last operation of the device.

[0095] The correction module 303 is used to perform timestamp correction on the log to be corrected by using the host computer time and the current time of the device when the host computer receives the host computer time fed back by the device.

[0096] In one possible implementation, the log timestamp correction device also includes a timing module, which is used to determine whether the device stores time information saved during the last operation when the device is started; if it is determined that the device stores time information saved during the last operation, the time information is obtained and used as the startup time of the device; the startup time of the device is used as the initial time, and the device is timed in real time after the device is started.

[0097] In one possible implementation, the determination module 302 is also used to: determine the time period from the device startup time to the device current time when the device receives the host computer time feedback from the host computer as the correction time range; determine the logs in the log list that are within the correction time range as the logs to be corrected; wherein the log list is a list of logs recorded in sequence by the device in the order in which the logs are generated.

[0098] In one possible implementation, the determination module 302 is specifically used to: confirm the logs within the correction time range in order from the beginning to the end of the log list; determine that the list row is located before the time synchronization log, and the log within the correction time range is the log to be corrected; wherein the time synchronization log is a log generated when the current time of the device is synchronized to the host computer time fed back by the host computer received by the device.

[0099] In one possible implementation, the correction module 303 is further used to: calculate the time difference between the device and the host computer based on the host computer time and the current time of the device when the host computer receives the host computer time fed back by the device; calculate the actual time when the log to be corrected was generated based on the time difference and the timestamp of the log to be corrected; and update the timestamp of the log to be corrected by the actual time.

[0100] In a possible implementation, the correction module 303 is specifically used to: respectively determine the synchronization interval to which each log to be corrected belongs, the synchronization interval being the time interval between when the device is started and when the device obtains the host computer time fed back by the host computer; for each log to be corrected, determine the time difference corresponding to the synchronization interval to which the log to be corrected belongs; wherein the time difference corresponding to each synchronization interval is the difference between the host computer time when the device obtains the host computer time fed back by the host computer corresponding to the synchronization time interval and the current time of the device when the device obtains the host computer time fed back by the host computer; calculate the actual time when the log to be corrected is generated according to the time difference corresponding to the synchronization interval to which the log to be corrected belongs and the timestamp of the log to be corrected.

[0101] In addition, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the log timestamp correction method described in the above method embodiment are executed.

[0102] The computer program product of the log timestamp correction method provided in the embodiment of the present application includes a computer-readable storage medium storing program code, and the instructions included in the program code can be used to execute the steps of the log timestamp correction method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.

[0103] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0104] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0105] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a disk or an optical disk. It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variation thereof are intended to cover non-exclusive inclusion, so that a process, method, article or apparatus that includes a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or apparatus. In the absence of more restrictions, the elements defined by the sentence "includes..." do not exclude the presence of other identical elements in the process, method, article or apparatus that includes the elements.

[0106] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application. It should be noted that similar numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0107] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A log timestamp correction method, characterized in that: The method comprises: When the device is connected to the host computer, a time synchronization request is sent to the host computer; Determine the log to be corrected in the device that needs to be timestamped according to the device startup time and the device current time when the host computer receives the host computer time feedback from the host computer; wherein the device startup time is the time information saved during the last operation of the device; The timestamp of the log to be corrected is corrected by using the host computer time and the current time of the device when the host computer receives the host computer time fed back by the device.

2. The method according to claim 1, characterized in that When the device is connected to the host computer, before sending a time synchronization request to the host computer, the method further includes: When the device is started, determining whether the device stores time information saved during the last operation; If it is determined that the device stores time information saved during the last operation, the time information is obtained and used as the device startup time; The device startup time is taken as the initial time, and the device is timed in real time after the device is started.

3. The method according to claim 1, characterized in that Determining the log to be corrected in the device that needs to be timestamped according to the device startup time and the device current time when the host computer receives the device and feeds back the host computer time includes: Determine the time period from the start time of the device to the current time of the device when the device receives the time fed back by the host computer as the correction time range; Determine that the logs in the log list that are within the correction time range are the logs to be corrected; The log list is a list of logs recorded by the device in the order in which the logs are generated.

4. The method according to claim 3, characterized in that in, The logs in the log list are recorded in order in each list line of the log list according to the order in which the logs are generated; The step of determining that the logs in the log list that are within the correction time range are the logs to be corrected includes: According to the order of the log list from the beginning to the end, confirm the logs within the correction time range in sequence; Determine that the list row is located before the time synchronization log and the log within the correction time range is the log to be corrected; The time synchronization log is a log generated when the current time of the device is synchronized with the time of the host computer fed back by the host computer and received by the device.

5. The method according to any one of claims 1 to 4, characterized in that: The timestamp correction of the log to be corrected is performed using the host computer time received by the device and the current time of the device when the host computer feeds back the host computer time, including: Calculate the time difference between the device and the host computer according to the host computer time received by the device and the current time of the device when the host computer feeds back the host computer time; Calculate the actual time when the log to be corrected is generated according to the time difference and the timestamp of the log to be corrected; The timestamp of the log to be corrected is updated by the actual time.

6. The method according to claim 5, characterized in that The calculating the actual time when the log to be corrected is generated according to the time difference and the timestamp of the log to be corrected includes: Determine the synchronization interval of each log to be corrected respectively, where the synchronization interval is the time interval between the start of the device and the time when the device obtains the host computer time feedback from the host computer; For each log to be corrected, determine the time difference corresponding to the synchronization interval to which the log to be corrected belongs; wherein the time difference corresponding to each synchronization interval is the difference between the host computer time when the device obtains the host computer feedback corresponding to the synchronization time interval and the current time of the device when the device obtains the host computer time feedback from the host computer; The actual time when the log to be corrected is generated is calculated according to the time difference corresponding to the synchronization interval to which the log to be corrected belongs and the timestamp of the log to be corrected.

7. A device, characterized in that: include: Communications devices and processors; The communication device is used to send a time synchronization request to the host computer when the device is connected to the host computer; The processor is used to determine the log to be corrected in the device that needs to be timestamped according to the device startup time and the device current time when the host computer receives the host computer time feedback from the host computer; wherein the device startup time is the time information saved during the last operation of the device; The processor is further configured to perform timestamp correction on the log to be corrected by using the host computer time and the current time of the device when the host computer receives the host computer time fed back by the device.

8. The device according to claim 7, characterized in that The communication device establishes a connection with the host computer via a universal serial bus.

9. The device according to claim 7, characterized in that Also includes: Memory; The memory is used to store time information during the operation of the device.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are executed.

Citation Information

Cited By

  • Real-time log storage method, chip equipment and storage medium

    CN120215844A