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

By storing the initial log sequence when the chip device is started and automatically configuring the timing priority, the problem of low log storage efficiency in the prior art is solved, and more efficient and secure log storage is achieved.

CN120215844AActive Publication Date: 2025-06-27天津布尔科技有限公司
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510703613.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-29
Publication Date
2025-06-27
Estimated Expiration
2045-05-29

AI Technical Summary

Technical Problem

The existing technology of lieutenant-collaboration solutions cannot adapt to the changing complex environment, resulting in low log storage efficiency.

Method used

The timing module is started when the chip device is started, storing the initial log sequence and carrying time offset information. Automatically configure the priority of NTP server and GPS satellite calibration according to the size of the initial log sequence, and store the log information in the log file after successful calibration. When temporary cache files exceed capacity limit, log information will be automatically cleaned and sent synchronously.

Benefits of technology

It improves the timeliness and security of log storage, adapts to different environments and application scenarios, and selects the most suitable school time plan to improve school time efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120215844A_ABST
    Figure CN120215844A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and discloses a real-time log storage method, chip equipment and a storage medium, the method comprises the following steps: firstly, synchronously starting a timing module when the chip equipment is started, and then storing logs generated by starting in a temporary cache file to form an initial log sequence; automatically configuring the timing priorities of the NTP server and the GPS satellite according to the size of the temporary cache file (the GPS priority is higher than the NTP when the size value is greater than or equal to a first threshold value), storing the subsequent log in the log file to obtain a later log sequence after the timing succeeds, and automatically cleaning the earliest initial log sequence when the temporary cache file exceeds a preset capacity; and synchronizing to the log file and the later log sequence for time synchronization to obtain real-time log information. According to the technical scheme, the timing scheme can be pre-judged and selected according to the initial log data volume, and the logs in different time periods are differently stored, so that the timeliness and safety of log storage are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and particularly to a storage method for real-time logs, a chip device, and a storage medium. Background Art

[0002] With the wide application of embedded devices in fields such as the Internet of Things, vehicle-mounted systems, and industrial control, device log recording has become an important tool for monitoring the operating status of devices, detecting faults, and performing system maintenance. However, in embedded devices without a Real-Time Clock (RTC) chip, the device often cannot obtain accurate time information immediately after startup, resulting in log records generated during the startup phase without timestamps. In this case, the log information of the device lacks accurate time markings, increasing the difficulty of subsequent log analysis and fault troubleshooting.

[0003] In related technologies, for example, in the technical solution of Chinese application: CN202111130293.1, time calibration is performed using an NTP server or a cloud server, that is, the NTP server is preferentially used for time calibration. If the NTP server is abnormal or the connection is interrupted, the time is calibrated from the cloud server. This time calibration solution cannot adapt to the changing complex environment, resulting in low storage efficiency of logs. Summary of the Invention

[0004] The main objective of the present invention is to provide a storage method for real-time logs, a chip device, and a storage medium, aiming to solve the technical problem that the time calibration solution in the prior art cannot adapt to the changing complex environment, resulting in low storage efficiency of logs.

[0005] To achieve the above objective, in a first aspect, an embodiment of the present application provides a storage method for real-time logs, which is applied to a chip device. The method includes: Start a timing module simultaneously when the chip device starts, and store the log information generated when the chip device starts in a temporary cache file to obtain an initial log sequence, where the initial log sequence carries time offset information; Automatically configure the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to a first threshold, configure the priority of GPS satellite time calibration to be higher than the priority of NTP server time calibration; Perform real-time time calibration of the chip device through an NTP server or a GPS satellite, and when the real-time time calibration of the chip device is successful, store the log information generated by the chip device in a log file to obtain a later log sequence, where the later log sequence carries timestamp information; When the temporary cache file exceeds the preset capacity limit, the earliest initial log sequence stored is automatically cleared and synchronously sent to the log file and the corresponding later log sequence for time synchronization to obtain real-time log information.

[0006] In a possible implementation, when the size value of the initial log sequence is greater than or equal to the first threshold, configuring the priority of GPS satellite time calibration to be higher than the priority of NTP server time calibration includes: Obtain the environmental perception data of the environment where the chip device is located, and the environmental perception data at least includes the electromagnetic interference intensity and the environmental temperature; Correct the first threshold according to the electromagnetic interference intensity and the environmental temperature, and configure the priority of GPS satellite time calibration to be higher than the priority of NTP server time calibration according to the corrected first threshold; Wherein, when the electromagnetic interference intensity is greater than or equal to the intensity threshold, perform a positive correction on the first threshold; when the electromagnetic interference intensity is less than the intensity threshold, perform a negative correction on the first threshold.

[0007] In a possible implementation, the correcting the first threshold according to the electromagnetic interference intensity and the environmental temperature includes: Input the current electromagnetic interference intensity and the current environmental temperature into a correction model to obtain the first threshold, where the correction model satisfies the following expression: P = P0 + K1 * (E d - E0) - K2 * (T d - T0); In the formula, P is the corrected first threshold, P0 is the first threshold before correction, E d is the current electromagnetic interference intensity, E0 is the electromagnetic interference intensity reference value, T d is the current environmental temperature, T0 is the reference environmental temperature, and K1 and K2 are the correction coefficients of the electromagnetic interference intensity and the environmental temperature to the first threshold respectively.

[0008] In a possible implementation, the automatically configuring the priorities of the NTP server and GPS satellite time calibration according to the size of the initial log sequence further includes: When the size value of the initial log sequence is less than or equal to the second threshold, configure the priority of GPS satellite time calibration to be lower than the priority of NTP server time calibration; When the size value of the initial log sequence is greater than the second threshold and less than the first threshold, configure the priority of GPS satellite time calibration to be equal to the priority of NTP server time calibration; wherein, the second threshold is less than the first threshold.

[0009] In a possible implementation, the real-time time calibration of the chip device via an NTP server or a GPS satellite includes: When the priority of GPS satellite time calibration is configured to be equal to the priority of NTP server time calibration, if the current time has been calibrated via the NTP server, then GPS satellite time calibration is not performed within a preset duration; Alternatively, when the priority of GPS satellite time calibration is configured to be equal to the priority of NTP server time calibration, if the current time has been calibrated via the GPS satellite, then NTP server time calibration is not performed within a preset duration.

[0010] In a possible implementation, the automatic cleaning of the earliest initial log sequence and the synchronous transmission to the log file for time synchronization with the corresponding later log sequence to obtain real-time log information includes: Performing time synchronization on the corresponding initial log sequence according to the later log sequence so that the initial log sequence obtains timestamp information; Performing associated splicing on the later log sequence and the initial log sequence that has obtained timestamp information to obtain real-time log information.

[0011] In a possible implementation, the storing of the log information generated when the chip device is started in a temporary cache file to obtain an initial log sequence includes: Pre-dividing the temporary cache file into multiple data storage blocks; Storing the log information generated when the chip device is started in the multiple data storage blocks in sequence according to a time interval, where the time interval corresponds to time offset information.

[0012] In a possible implementation, when the real-time time calibration of the chip device is successful, the method further includes: Automatically adjusting the log storage settings so that the temporary cache file obtains the transfer permission and / or the automatic cleaning permission.

[0013] In a second aspect, an embodiment of the present application further provides a chip device, including: a memory and a processor, where the memory is used to store program code; the processor is used to call the program code to execute the method as described in the first aspect.

[0014] In a third aspect, an embodiment of the present application further provides a readable storage medium, on which a computer program is stored, and characterized in that when the computer program is executed by a processor, the steps of the method as described in the first aspect are implemented.

[0015] Different from the prior art, an embodiment of the present application provides a method for storing real-time logs. First, a timing module is started simultaneously when the chip device is started, and the log information generated when the chip device is started is stored in a temporary cache file to obtain an initial log sequence. Then, the priorities of NTP server and GPS satellite time calibration are automatically configured according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to the first threshold, the priority of GPS satellite time calibration is configured to be higher than that of NTP server time calibration. When the chip device is successfully calibrated in real time, the subsequent log information generated by the chip device is stored in a log file to obtain a later log sequence. Finally, when the temporary cache file exceeds the preset capacity limit, the earliest stored initial log sequence is automatically cleared and synchronously sent to the log file to be time-synchronized with the corresponding later log sequence to obtain real-time log information. The technical solution of the present application can automatically configure the priorities of NTP server and GPS satellite time calibration according to the data volume size of the initial log sequence, that is, predict and select the most suitable time calibration scheme (NTP or GPS) according to the data volume size of the initial log sequence; at the same time, different storage processes can be performed on the logs generated in different time periods. In this way, the timeliness and security of log storage are greatly improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention, and those of ordinary skill in the art can obtain other drawings based on the structures shown in these drawings without creative efforts.

[0017] Figure 1 It is a schematic flowchart of a method for storing real-time logs in some embodiments of the present application; Figure 2 It is a schematic flowchart of step S400 of the method for storing real-time logs in some embodiments of the present application; Figure 3 It is a schematic hardware structure diagram of a chip device in some embodiments of the present application.

[0018] The implementation, functional features and advantages of the object of the present invention will be further described with reference to the embodiments and the drawings. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0019] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without making creative efforts belong to the scope of protection of the present invention.

[0020] It should be noted that all directional indications (such as up, down, left, right, front, back...) in the embodiments of the present invention are only used to explain the relative positional relationship and movement conditions between components in a specific posture (as shown in the accompanying drawings). If this specific posture changes, the directional indication will also change accordingly.

[0021] In addition, the descriptions involving "first", "second", etc. in the present invention are only for descriptive purposes, and cannot be understood as indicating or implying their relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In addition, "and / or" throughout the text includes three scenarios. Taking A and / or B as an example, it includes the technical solution of A, the technical solution of B, and the technical solution that A and B are satisfied simultaneously. In addition, the technical solutions between the various embodiments can be combined with each other, but it must be based on the ability of those of ordinary skill in the art to implement. When the combination of technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0022] As Figure 1 - Figure 2 shown, the following takes the chip device executing the real-time log storage method as an example for illustration. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here. Please refer to the attached Figure 1 drawing. The method includes the following steps S100 - step S400: Step S100, start the timing module simultaneously when the chip device is started, and store the log information generated when the chip device is started in a temporary cache file to obtain an initial log sequence, and the initial log sequence carries time offset information; Specifically, after the chip device is powered on and started, the timing module is also started accordingly. The timing module specifically plays the role of time accumulation. For example, it accumulates the cumulative duration from the start of the chip device to the current moment.

[0023] After the chip device is started, relevant log information including the start information of the chip device will be generated, such as relevant information on hardware self-check, driver loading, network status, etc.; these log information are recorded and stored by the log system.

[0024] It can be understood that when the chip device is started, since the device does not have an RTC chip or the network time is not synchronized, the log information generated during device startup will not carry an accurate timestamp. However, due to the startup of the timing module, this log information will carry cumulative information on the duration.

[0025] To facilitate the storage and management of log information without timestamps, in the embodiments of this application, the log information generated when the chip device is started is stored in a temporary cache file to obtain an initial log sequence. In this way, the initial log sequence carries time offset information, that is, the initial log sequence carries cumulative information on the duration. Moreover, the temporary cache file can overwrite the earliest data by itself, which can improve the storage efficiency of log information.

[0026] In one embodiment, the step of storing the log information generated when the chip device is started in a temporary cache file to obtain an initial log sequence includes: Pre-divide the temporary cache file into multiple data storage blocks; Store the log information generated when the chip device is started in the multiple data storage blocks in sequence according to a time interval, where the time interval corresponds to the time offset information.

[0027] Specifically, the temporary cache file can be pre-divided into multiple data storage blocks. For example, the temporary cache file is divided into 1-10 data storage blocks, and the capacity of each block is 10KB. Then, the log information generated when the chip device is started is stored in the multiple data storage blocks in sequence according to a time interval (such as 0.01S), so as to realize the storage of the initial log sequence by the temporary cache file.

[0028] For example, the log information within 0.01S after the chip device is started is stored in the first data storage block, and the log information within 0.01 - 0.02S after the chip device is started is stored in the second data storage block, and so on until all the initial log sequences are stored. When the cache is full or reaches a certain proportion, the earliest data storage block is preferentially overwritten to ensure that the latest logs are retained first.

[0029] More specifically, 0.00 - 0.01 seconds after startup: Log 1 (Hardware self-check completed), Log 2 (Kernel initialization) → stored in the 1st data block. 0.01 - 0.02 seconds after startup: Log 3 (Network module loading) → stored in the 2nd data block.

[0030] It can be understood that the above time interval (such as 0.01S) can be used as the time offset information for subsequent time synchronization.

[0031] Based on this, after the chip device is powered on and started, the timing module starts synchronously with the device, and records the cumulative duration (time offset) from the device startup to the current moment through the timing module. Then, the logs generated when the chip device starts are stored in a temporary cache file, and the cumulative duration information of the timing module is used as the time offset to form an initial log sequence, providing accurate data support for subsequent time synchronization.

[0032] Step S200: Automatically configure the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to the first threshold, configure the priority of GPS satellite time calibration to be higher than that of NTP server time calibration. NTP (Network Time Protocol) is a protocol used to synchronize computer clocks. It provides high-precision time calibration services through a hierarchical time server architecture. NTP server time calibration depends on a stable network connection between the chip device and the server, and the network quality directly affects the time calibration accuracy.

[0033] GPS satellite time calibration is a method of calibrating the local clock using the high-precision time signals provided by Global Positioning System (GPS) satellites. GPS satellite time calibration requires the chip device to be in a low electromagnetic interference environment to reduce time signal errors. And GPS satellite time calibration requires the chip device to receive GPS satellite signals, which usually requires the use of a dedicated GPS receiver. Therefore, the power consumption of the GPS receiver is relatively high.

[0034] It can be understood that due to the complex and changeable application scenario environment of the chip device, the prior art solutions usually give priority to using NTP servers for time calibration. However, when the NTP server fails or the connection is interrupted, it is necessary to switch to the cloud server to obtain time for time calibration. This mechanism is likely to cause security problems such as a decrease in log storage efficiency and even data loss.

[0035] And this application automatically configures the priorities of NTP server and GPS satellite time calibration according to the data volume size of the initial log sequence. For example, when the data volume of the initial log sequence is large (greater than or equal to the first threshold), it indicates that the chip device has generated relatively more log data, further indicating that the startup of the chip device is slow, and it is very likely that the chip device has encountered network or system problems during this period. At this time, configure the priority of GPS satellite time calibration to be higher than that of NTP server time calibration, that is, give priority to configuring GPS satellite for time calibration. For example, turn on the time calibration function of the GPS satellite and turn off the time calibration function of the NTP server. Or, give priority to turning on the time calibration function of the GPS satellite, and then turn on the time calibration function of the NTP server after a preset duration.

[0036] In other embodiments, the step of automatically configuring the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence further includes: when the size value of the initial log sequence is less than or equal to a second threshold, configuring the priority of GPS satellite time calibration to be lower than that of NTP server time calibration; when the size value of the initial log sequence is greater than the second threshold and less than a first threshold, configuring the priority of GPS satellite time calibration to be equal to that of NTP server time calibration; wherein, the second threshold is less than the first threshold.

[0037] Specifically, when the data volume of the initial log sequence is small (such as less than or equal to the second threshold), it indicates that the chip device starts up quickly and no obvious network or system problems are encountered during this period. At this time, configure the priority of GPS satellite time calibration to be lower than that of NTP server time calibration, that is, preferentially configure to use the NTP server for time calibration to reduce the overall power consumption of the chip device. For example, turn on the time calibration function of the NTP server and turn off the time calibration function of the GPS satellite. Or, preferentially turn on the time calibration function of the NTP server and then turn on the time calibration function of the GPS satellite after a preset duration.

[0038] When the data volume of the initial log sequence is greater than the second threshold and less than the first threshold, it indicates that there may be uncertain factors during the device startup process, but it is impossible to accurately determine whether there are network problems with the chip device. At this time, configure the priority of GPS satellite time calibration to be equal to that of NTP server time calibration, that is, the GPS satellite and the NTP server compete simultaneously to improve the time calibration success rate. For example, in a certain situation, the time calibration functions of both the GPS satellite and the NTP server are turned on. If the GPS satellite completes time calibration at a certain moment, then the NTP server will no longer be used for time calibration.

[0039] Exemplarily, in the case where the priority of GPS satellite time calibration is equal to that of NTP server time calibration, if the current time has been calibrated by the NTP server, then do not calibrate the time by the GPS satellite within a preset duration (such as 3S); or, in the case where the priority of GPS satellite time calibration is equal to that of NTP server time calibration, if the current time has been calibrated by the GPS satellite, then do not calibrate the time by the NTP server within a preset duration (such as 3S).

[0040] In this way, in the case where the time calibration functions of both the GPS satellite and the NTP server are turned on in this application, if a certain time calibration source (such as the GPS satellite) completes time calibration first, then trigger the mutual exclusion locking mechanism to prohibit another time calibration source (such as the NTP server) from continuing to attempt time calibration within a preset duration (such as 3 seconds), so as to avoid resource competition and frequent switching, reduce the power consumption and computing load of the chip device, and extend the device battery life.

[0041] It should be noted that the first threshold characterizes that the size of the initial log sequence reaches the limit value, and this limit value usually reflects that the network state of the chip device is poor (for example, due to frequent network connection failures or abnormal feedback, the log data surges). However, when the environment deviates from the normal situation (such as electromagnetic interference, extreme temperature, etc.), whether to preferentially use GPS satellites for time calibration needs to be dynamically decided in combination with the environmental perception data.

[0042] Specifically, if the electromagnetic interference intensity in the environment where the chip device is located is too high (such as in an industrial sealed site, a strong radiation area), the GPS signal may be severely distorted, and directly relying on GPS time calibration may instead lead to time synchronization failure.

[0043] Based on this, in one embodiment, the step: when the size value of the initial log sequence is greater than or equal to the first threshold, configuring the priority of GPS satellite time calibration to be higher than the priority of NTP server time calibration, includes: S210. Obtain the environmental perception data of the environment where the chip device is located, and the environmental perception data at least includes the electromagnetic interference intensity and the environmental temperature; S220. Correct the first threshold according to the electromagnetic interference intensity and the environmental temperature, and configure the priority of GPS satellite time calibration to be higher than the priority of NTP server time calibration according to the corrected first threshold; Wherein, when the electromagnetic interference intensity is greater than or equal to the intensity threshold, a positive correction is made to the first threshold; when the electromagnetic interference intensity is less than the intensity threshold, a negative correction is made to the first threshold.

[0044] Specifically, the electromagnetic noise level in the environment can be quantified by a dedicated sensor (such as in dBm) to characterize the magnitude of the electromagnetic interference intensity; and the environmental temperature around the device can be monitored by a temperature sensor. Optionally, the degree of enclosure of the environment can also be used to characterize the magnitude of the electromagnetic interference intensity. The greater the degree of enclosure of the environment, the greater the electromagnetic interference intensity, that is, the lower the ability of the chip device to receive electromagnetic signals.

[0045] Exemplarily, when the electromagnetic interference intensity ≥ the preset intensity threshold (such as -80 dBm), it indicates that the GPS signal may be unstable. At this time, a positive correction is performed on the first threshold (such as increasing the threshold to 120% of the original value) to reduce the sensitivity of triggering GPS priority time calibration. If the initial log sequence size still exceeds the threshold after correction, it is necessary to comprehensively judge whether to enable GPS in combination with other environmental data (such as temperature); if the environment is harsh, NTP time calibration can be preferentially retained. When the electromagnetic interference intensity < the preset intensity threshold, it indicates that the GPS signal is reliable. At this time, a negative correction is performed on the first threshold (such as reducing the threshold to 80% of the original value) to more sensitively trigger GPS priority time calibration. Directly configure the GPS time calibration priority to be higher than NTP, and use the high-precision characteristics of GPS to quickly complete time calibration.

[0046] In this way, by introducing the electromagnetic interference intensity and environmental temperature as correction factors in the embodiments of the present application, the evaluation threshold of the priority is dynamically adapted to the actual environment, avoiding the limitations of a single fixed threshold.

[0047] For example, in the outdoor substation scenario of a smart grid, the equipment may face strong electromagnetic interference and high temperature challenges simultaneously. By dynamically correcting the first threshold, the system can configure to preferentially use GPS time calibration when the electromagnetic interference is small, and configure to preferentially use NTP time calibration when the interference is strong. In this way, according to different scenario environments, the automatic configuration of the time calibration function is completed in advance, thereby improving the time calibration efficiency and the storage efficiency of the logs.

[0048] To further improve the accuracy of time calibration control, in one embodiment, the correcting the first threshold according to the electromagnetic interference intensity and environmental temperature includes: Inputting the current electromagnetic interference intensity and the current environmental temperature into a correction model to obtain the first threshold, where the correction model satisfies the following expression: P = P0 + K1 * (E d - E0) - K2 * (T d - T0); In the formula, P is the corrected first threshold (dynamically adjusted threshold), P0 is the first threshold before correction (initial fixed threshold), E d is the current electromagnetic interference intensity, E0 is the electromagnetic interference intensity reference value, T d is the current environmental temperature, T0 is the reference environmental temperature, and K1 and K2 are the correction coefficients respectively representing the correction of the first threshold by the electromagnetic interference intensity and environmental temperature. The correction coefficients K1 and K2 can both be set to 0.5.

[0049] Specifically, when E dWhen E > E0, the electromagnetic interference increases, and K1*(Ed - E0) is positive, resulting in an increase in P, that is, increasing the difficulty of triggering GPS priority time calibration, avoiding time calibration failure due to strong GPS signal interference. At this time, the system is more inclined to rely on NTP time calibration. When E d ≤ E0, the electromagnetic interference weakens or remains unchanged, K1*(Ed - E0) is negative or zero, resulting in a decrease in P, that is, triggering GPS priority time calibration more sensitively. At this time, the system is more inclined to rely on GPS time calibration. When T d > T0, the increase in temperature may lead to a decline in hardware performance (such as crystal oscillator frequency drift and reduced stability of the network module). At this time, -K2*(T d - T0) is negative, resulting in a decrease in P, reducing the threshold for triggering GPS priority time calibration, and being more inclined to give priority to using GPS time calibration. When T d ≤ T0, the temperature is suitable. At this time, -K2*(T d - T0) is positive, P increases, increasing the difficulty of triggering GPS priority time calibration, and reducing the triggering frequency of GPS time calibration. That is, when the temperature is stable and suitable, the system is more inclined to NTP time calibration, reducing GPS power consumption and computational overhead.

[0050] Based on this, the system of the present application can implement the optimal time calibration strategy in different environments, balance time synchronization accuracy, resource utilization rate, and reliability, and meet the high requirements of different scenarios such as industrial Internet of Things and smart grid.

[0051] Step S300: Perform real-time time calibration of the chip device through an NTP server or a GPS satellite, and when the real-time time calibration of the chip device is successful, store the log information generated by the chip device in a log file to obtain a later log sequence, and the later log sequence carries timestamp information; Specifically, according to the dynamically adjusted time calibration priority in step S200, an NTP server or a GPS satellite is selected as the time calibration source. If the GPS priority time calibration conditions are met (such as a large amount of data in the initial log sequence, and weak electromagnetic interference and high temperature), then the real-time time calibration of the chip device is preferentially performed through the GPS satellite. If the NTP server priority time calibration conditions are met (such as a small amount of data in the initial log sequence), then the real-time time calibration of the chip device is preferentially performed through the NTP server. After the real-time time calibration of the chip device is successful, the chip device continues to run and generates log information. At this time, the log information generated by the chip device is stored in a log file to obtain a later log sequence. Since the time calibration has been completed previously, the later log sequence is attached with timestamp information, and the later log sequence is generated immediately after the previous log sequence.

[0052] In one embodiment, when the real-time time calibration of the chip device is successful, the method further includes: Automatically adjust the log storage settings to enable the temporary cache file to obtain dump permission and / or automatic cleaning permission.

[0053] Specifically, when the chip device completes real-time time calibration through an NTP server or a GPS satellite, it triggers the automatic adjustment of the log storage settings to enable the temporary cache file to obtain dump permission and / or automatic cleaning permission.

[0054] For example, allow the temporary cache file to be dumped to a long-term storage medium (such as a hard disk, cloud storage), such as in a log file. In this way, after successful time calibration, the critical log data is safely transferred from the volatile cache to prevent data loss due to power failure, system crash, or data overwrite.

[0055] Step S400: When the temporary cache file exceeds the preset capacity limit, automatically clean the earliest initial log sequence stored, and synchronously send it to the log file to synchronize the time with the corresponding later log sequence to obtain real-time log information.

[0056] Specifically, in the embodiment of the present application, automatic cleaning is performed when the storage date or storage capacity exceeds the preset limit. For example, the temporary cache file is set to store up to ten days of log information at most, or when the number or capacity exceeds the limit, the earliest initial log sequence will be cleaned to ensure the efficient use of the storage space. And the log data to be cleaned is synchronously sent to the log file (long-term storage medium) to synchronize the time with the corresponding later log sequence to obtain real-time log information.

[0057] It should be noted that the initial log sequence and the corresponding later log sequence can be associated through a tag number to prevent time synchronization errors.

[0058] In other embodiments, automatic cleaning can also be performed when the storage date or storage capacity of the real-time log information in the log file exceeds the preset limit.

[0059] In one embodiment, the step S400: automatically clean the earliest initial log sequence stored, and synchronously send it to the log file to synchronize the time with the corresponding later log sequence to obtain real-time log information, includes: S410: Synchronize the time of the corresponding initial log sequence according to the later log sequence so that the initial log sequence obtains timestamp information; S420: Correlate and splice the later log sequence and the initial log sequence that has obtained timestamp information to obtain real-time log information.

[0060] Specifically, the accurate timestamps are added to the initial log sequence by using the time information of the later log sequence and the time offset information in step S100. After the initial log sequence obtains the accurate timestamp information, it is integrated with the later log sequence to form a complete and continuous log information stream, that is, real-time log information. This can facilitate subsequent analysis and processing of the logs, such as fault troubleshooting, performance monitoring, etc. By splicing the logs at different stages together, a more comprehensive understanding of the system operation status and the occurrence process of events can be achieved.

[0061] Exemplarily, for the previously mentioned: 0.00 - 0.01 seconds after startup: Log 1 (Hardware self-check completed), Log 2 (Kernel initialization) → stored in the 1st data block. 0.01 - 0.02 seconds after startup: Log 3 (Network module loading) → stored in the 2nd data block. Assume that the starting time point of the later log sequence is 8:01:25. Then the time points corresponding to Log 1 and Log 2 are 8:01:24.980 seconds, and the time point corresponding to Log 3 is 8:01:24.990 seconds.

[0062] After completing the splicing of the logs at different stages, the system can store the real-time log information file according to the management mechanism named by device IMEI + date, which is convenient for managers to conduct targeted analysis and fault troubleshooting.

[0063] It can be understood that the cache file is usually located in a high-speed storage medium (such as memory), and its read and write speeds are much faster than those of traditional disk storage. When the chip device starts to generate log information, directly writing to the cache file can quickly complete the operation, reduce the impact of log writing on the main business of the device, and improve the security of the initial log sequence. In addition, after the cache file accumulates a certain amount of log information, it is written to the disk log file in batches. This method reduces the frequent seek and rotational latency of the disk and improves the disk write efficiency. Therefore, in the embodiment of the present application, storing the logs generated in the early stage in the temporary cache file and storing the logs generated in the later stage in the log file can improve the timeliness and security of log storage.

[0064] Based on this, a method for storing real-time logs provided by an embodiment of the present application first starts a timing module simultaneously when the chip device is started, and stores the log information generated when the chip device is started in a temporary cache file to obtain an initial log sequence; then automatically configures the priorities of the NTP server and GPS satellite time calibration according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to the first threshold, the priority of GPS satellite time calibration is configured to be higher than the priority of NTP server time calibration; when the chip device is successfully calibrated in real time, then store the log information generated by the chip device subsequently in a log file to obtain a later log sequence; finally, when the temporary cache file exceeds the preset capacity limit, automatically clear the earliest stored initial log sequence and synchronously send it to the log file to perform time synchronization with the corresponding later log sequence to obtain real-time log information. The technical solution of the present application can automatically configure the priorities of the NTP server and GPS satellite time calibration according to the data volume size of the initial log sequence, that is, predict and select the most suitable time calibration scheme (NTP or GPS) according to the data volume size of the initial log sequence to adapt to different application scenarios or environments; at the same time, it can perform different storage processing on the logs generated at different time periods. In this way, the timeliness and security of log storage are greatly improved.

[0065] As Figure 3 shown, Figure 3 is a schematic diagram of the hardware structure of the chip device in some embodiments of the present application. The chip device provided by the embodiment of the present application further includes a memory 1000 and a processor 2000. Among them, the memory 1000 is used to store computer-readable instructions, and the processor 2000 is used to call the computer-readable instructions to execute the method for storing real-time logs as described above.

[0066] Among them, the processor 2000 is used to provide computing and control capabilities to control the chip device to execute corresponding tasks. For example, it controls the chip device to execute the real-time log storage method in any of the above method embodiments. The method includes: starting a timing module simultaneously when the chip device starts, and storing the log information generated when the chip device starts in a temporary cache file to obtain an initial log sequence, where the initial log sequence carries time offset information; automatically configuring the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to a first threshold, the priority of GPS satellite time calibration is configured to be higher than that of NTP server time calibration; performing real-time time calibration of the chip device through the NTP server or GPS satellite, and when the real-time time calibration of the chip device is successful, storing the log information generated by the chip device in a log file to obtain a later log sequence, where the later log sequence carries timestamp information; when the temporary cache file exceeds the preset capacity limit, automatically clearing the earliest stored initial log sequence and synchronously sending it to the log file for time synchronization with the corresponding later log sequence to obtain real-time log information.

[0067] The processor 2000 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0068] The memory 1000, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the program instructions / modules corresponding to the real-time log storage method in the embodiments of the present application. By running the non-transitory software programs, instructions, and modules stored in the memory 1000, the processor 2000 can implement the real-time log storage method in any of the above method embodiments.

[0069] Specifically, the memory 1000 may include volatile memory (VM), such as random access memory (RAM); the memory 1000 may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), or other non-transitory solid-state storage devices; the memory 1000 may further include a combination of the above types of memories.

[0070] In summary, the chip device of the present application adopts the technical solution of any one of the above embodiments of the real-time log storage method. Therefore, it has at least the beneficial effects brought by the technical solutions of the above embodiments, which will not be elaborated here one by one.

[0071] The embodiment of the present application also provides a computer-readable storage medium, such as a memory including program code, and the above program code can be executed by a processor to complete the real-time log storage method in the above embodiment. For example, the computer-readable storage medium may be read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CDROM), magnetic tape, floppy disk, and optical data storage device, etc.

[0072] The embodiment of the present application also provides a computer program product, which includes one or more pieces of program code, and the program code is stored in a computer-readable storage medium. The processor of the early warning system reads the program code from the computer-readable storage medium, and the processor executes the program code to complete the steps of the real-time log storage method provided in the above embodiment.

[0073] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above embodiments can be completed by hardware, or can be completed by hardware related to program code. The program can be stored in a computer-readable storage medium, and the above-mentioned storage medium may be read-only memory, magnetic disk, or optical disc, etc.

[0074] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0075] Through the description of the above embodiments, those of ordinary skill in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Those of ordinary skill in the art can understand that all or part of the processes of implementing the above embodiment methods can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0076] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structural transformation made by using the description of the present invention and the content of the drawings under the inventive concept of the present invention, or direct / indirect application in other related technical fields, is included in the patent protection scope of the present invention.

Claims

1. A method for storing real-time logs, characterized in that, Applied to a chip device, the method includes: Start a timing module simultaneously when the chip device starts, and store the log information generated when the chip device starts in a temporary cache file to obtain an initial log sequence, where the initial log sequence carries time offset information; Automatically configure the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence. Among them, when the size value of the initial log sequence is greater than or equal to a first threshold, configure the priority of GPS satellite time calibration to be higher than that of NTP server time calibration; Perform real-time time calibration of the chip device through an NTP server or a GPS satellite, and when the real-time time calibration of the chip device is successful, store the log information generated by the chip device in a log file to obtain a later log sequence, where the later log sequence carries timestamp information; When the temporary cache file exceeds the preset capacity limit, automatically clean the earliest stored initial log sequence and synchronously send it to the log file to synchronize the time with the corresponding later log sequence to obtain real-time log information.

2. The storage method of the real-time log according to claim 1, characterized in that, When the size value of the initial log sequence is greater than or equal to the first threshold, configuring the priority of GPS satellite time calibration to be higher than that of NTP server time calibration includes: Obtain environmental perception data of the environment where the chip device is located, and the environmental perception data at least includes the electromagnetic interference intensity and the environmental temperature; Correct the first threshold according to the electromagnetic interference intensity and the environmental temperature, and configure the priority of GPS satellite time calibration to be higher than that of NTP server time calibration according to the corrected first threshold; Among them, when the electromagnetic interference intensity is greater than or equal to the intensity threshold, perform a positive correction on the first threshold; when the electromagnetic interference intensity is less than the intensity threshold, perform a negative correction on the first threshold.

3. The storage method of real-time logs according to claim 2, wherein, Correcting the first threshold according to the electromagnetic interference intensity and the environmental temperature includes: Input the current electromagnetic interference intensity and the current environmental temperature into a correction model to obtain the first threshold, where the correction model satisfies the following expression: P = P0 + K1 * (E d - E0) - K2 * (T d - T0); Wherein, P is the first threshold value after calibration, P0 is the first threshold value before calibration, E d is the current electromagnetic interference intensity, E0 is the reference value of electromagnetic interference intensity, T d is the current ambient temperature, T0 is the reference ambient temperature, and K1 and K2 are the calibration coefficients of the electromagnetic interference intensity and the ambient temperature on the first threshold value respectively.

4. The storage method of real-time logs according to claim 1, characterized in that, Automatically configuring the priorities of NTP server and GPS satellite time calibration according to the size of the initial log sequence further includes: When the size value of the initial log sequence is less than or equal to a second threshold, configure the priority of GPS satellite time calibration to be lower than that of NTP server time calibration; When the size value of the initial log sequence is greater than the second threshold and less than the first threshold, configure the priority of GPS satellite time calibration to be equal to that of NTP server time calibration; where the second threshold is less than the first threshold.

5. The storage method of the real-time log according to claim 4, characterized in that, Performing real-time time calibration of the chip device through an NTP server or a GPS satellite includes: When the priority of GPS satellite time calibration is equal to that of NTP server time calibration, if the current time has been calibrated through the NTP server, then do not calibrate through the GPS satellite within a preset duration; Or, when the priority of GPS satellite time calibration is equal to that of NTP server time calibration, if the current time has been calibrated through the GPS satellite, then do not calibrate through the NTP server within a preset duration.

6. The storage method of the real-time log according to claim 1, wherein Automatically clean the earliest initial log sequence and synchronously send it to the log file to synchronize with the corresponding later log sequence to obtain real-time log information, including: Synchronize the corresponding initial log sequence with the later log sequence so that the initial log sequence obtains timestamp information; Associate and splice the later log sequence and the initial log sequence with obtained timestamp information to obtain real-time log information.

7. The storage method of the real-time log according to claim 1, characterized in that Store the log information generated when the chip device is started in a temporary cache file to obtain an initial log sequence, including: Pre-divide the temporary cache file into multiple data storage blocks; Store the log information generated when the chip device is started in multiple data storage blocks in sequence according to a time interval, where the time interval corresponds to time offset information.

8. The storage method of real-time logs according to claim 1, characterized in that, When the chip device successfully performs real-time time calibration, the method further includes: Automatically adjust the log storage settings so that the temporary cache file obtains the permission to transfer and / or automatically clean.

9. A chip device, characterized in that, Including: A memory and a processor, the memory is used to store program code; The processor is used to call the program code to execute the method according to any one of claims 1 to 8.

10. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Log intelligent analysis method, tool, equipment and medium for complex system

    CN111106965A

  • Emergency broadcast equipment log debugging method

    CN112968744A

  • Log time correction method and device, electronic equipment and storage medium

    CN116701338A

  • Log timestamp correction method and device and computer readable storage medium

    CN118748576A

  • Trustworthy timestamps and certifiable clocks using logs linked by cryptographic hashes

    US20080201580A1