A storage method for real-time logs, a chip device, and a storage medium
By starting the timing module in an embedded device to generate initial log sequences and dynamically configure timing priority, the problem of logging lacks timestamps in the absence of RTC chips is solved, and efficient log storage and troubleshooting in complex environments is achieved.
Patent Information
- Application Number
- CN202510703613.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-05-29
AI Technical Summary
In embedded devices without real-time clock (RTC) chips, the device cannot obtain accurate time information immediately, resulting in a lack of time stamps on the log records generated in the startup phase, which increases the difficulty of log analysis and troubleshooting. The existing timing solutions cannot adapt to the changing complex environment, resulting in low log storage efficiency.
The timing module is started when the chip device is started, and an initial log sequence carrying time offset is generated. The priority of the NTP server and GPS satellite is dynamically configured according to the size of the initial log sequence. After the high priority timer is successful in real-time, the log information is stored in the post log sequence. When the temporary cache file exceeds the capacity, the earliest log is cleaned and sent to the post log sequence synchronously.
By dynamically configuring the timing priority and automatic cleaning mechanism, the timeliness and security of log storage is improved, adapting to log storage needs in different environments, and ensuring the accuracy and completeness of log information.
Smart Images

Figure CN120215844B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and particularly relates to a method for storing 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, network time protocol (NTP) servers or cloud servers are used for time calibration, that is, NTP servers are preferentially used for time calibration. If the NTP server is abnormal or the connection is interrupted, the time is calibrated from the cloud server. Such a time calibration solution cannot adapt to the changing complex environment, resulting in low storage efficiency of logs. Summary of the Invention
[0004] The main object of the present invention is to provide a method for storing 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 object, in a first aspect, an embodiment of the present application provides a method for storing real-time logs, which is applied to a chip device. The method includes:
[0006] 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;
[0007] 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;
[0008] 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;
[0009] 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.
[0010] 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:
[0011] 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;
[0012] 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;
[0013] Wherein, when the electromagnetic interference intensity is greater than or equal to the intensity threshold, the first threshold is positively corrected; when the electromagnetic interference intensity is less than the intensity threshold, the first threshold is negatively corrected.
[0014] In a possible implementation, the correcting the first threshold according to the electromagnetic interference intensity and the environmental temperature includes:
[0015] Input the current electromagnetic interference intensity and the current environmental temperature into the correction model to obtain the first threshold, where the correction model satisfies the following expression:
[0016] 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.
[0017] In a possible implementation, the automatically configuring the priorities of the NTP server and the GPS satellite time calibration according to the size of the initial log sequence further includes:
[0018] 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;
[0019] 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; where the second threshold is less than the first threshold.
[0020] In a possible implementation, the real-time time calibration of the chip device by the NTP server or GPS satellite includes:
[0021] In the case where the priority of GPS satellite time calibration is configured to be equal to the priority of NTP server time calibration, if the time calibration has been completed by the NTP server at the current moment, then do not perform GPS satellite time calibration within a preset duration;
[0022] Or, in the case where the priority of GPS satellite time calibration is configured to be equal to the priority of NTP server time calibration, if the time calibration has been completed by the GPS satellite at the current moment, then do not perform NTP server time calibration within a preset duration.
[0023] In a possible implementation, the automatic cleaning of the earliest initial log sequence stored and the synchronous sending to the log file and the corresponding later log sequence for time synchronization to obtain real-time log information includes:
[0024] Perform time synchronization on the corresponding initial log sequence according to the later log sequence so that the initial log sequence obtains timestamp information;
[0025] Perform associated splicing on the later log sequence and the initial log sequence that has obtained timestamp information to obtain real-time log information.
[0026] 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:
[0027] Pre-divide the temporary cache file into multiple data storage blocks;
[0028] 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 time offset information.
[0029] In a possible implementation, when the real-time time calibration of the chip device is successful, the method further includes:
[0030] Automatically adjust the log storage settings so that the temporary cache file obtains the permission for transfer and / or automatic cleaning.
[0031] 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 described in the first aspect.
[0032] 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 described in the first aspect are implemented.
[0033] Different from the prior art, 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 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; when the chip device is successfully calibrated in real time, then store the subsequent log information generated by the chip device 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 for 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 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, it can perform different storage processes 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
[0034] 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 use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on the structures shown in these drawings.
[0035] Figure 1 It is a schematic flowchart of the method for storing real-time logs in some embodiments of the present application;
[0036] 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;
[0037] Figure 3 It is a schematic hardware structure diagram of the chip device in some embodiments of the present application.
[0038] The realization, functional features, and advantages of the present invention will be further described in conjunction with embodiments and with reference to the accompanying drawings. Specific Embodiments
[0039] 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 of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present invention.
[0040] 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 the specific posture changes, the directional indications will also change accordingly.
[0041] 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 of such features. 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 fact that those of ordinary skill in the art can implement them. 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.
[0042] As Figure 1 - Figure 2 shown, the following takes a chip device executing the real-time log storage method as an example for description. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than here. Please refer to the attached Figure 1 figures. The method includes the following steps S100 - step S400:
[0043] Step S100: At the same time as the chip device is started, start the timing module, 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;
[0044] Specifically, after the chip device is powered on and started, the timing module is also started. 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.
[0045] After the chip device is started, relevant log information including the startup information of the chip device will be generated, such as relevant information about hardware self-check, driver loading, network status, etc.; these log information are recorded and stored by the log system.
[0046] 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, these log information generated during the startup of the device will not carry accurate timestamps. However, due to the startup of the timing module, these log information will carry the cumulative information of the duration.
[0047] To facilitate the storage and management of log information without timestamps, in the embodiments of the present 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 the cumulative information of the duration. And the temporary cache file can overwrite the earliest data by itself, which can improve the storage efficiency of log information.
[0048] 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:
[0049] Pre-divide the temporary cache file into multiple data storage blocks;
[0050] 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.
[0051] 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.
[0052] For example, the log information within 0.01S after the chip device is started is stored in the first data storage block, 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 log is retained first.
[0053] More specifically, from 0.00 to 0.01 seconds after startup: Log 1 (hardware self-check completed), Log 2 (kernel initialization) → stored in the first data block. From 0.01 to 0.02 seconds after startup: Log 3 (network module loaded) → stored in the second data block.
[0054] 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.
[0055] Based on this, after the chip device is powered on and started in the embodiment of the present application, the timing module starts synchronously with the device, and records the cumulative duration (time offset) from the start of the device 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.
[0056] 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;
[0057] NTP (Network Time Protocol) is a protocol for synchronizing computer clocks, which 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.
[0058] GPS satellite time calibration is a method of calibrating the local clock using the high-precision time signals provided by GPS (Global Positioning System) 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.
[0059] 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 has an abnormality or the connection is interrupted, it is necessary to switch to the cloud server to obtain time for time calibration, and this mechanism is likely to cause security problems such as a decrease in log storage efficiency and even data loss.
[0060] This application automatically configures the priorities of NTP server and GPS satellite time calibration according to the data volume 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 a relatively large amount of log data, further indicating that the startup of the chip device is slow. During this period, the chip device is likely to encounter network or system problems. At this time, the priority of GPS satellite time calibration is higher than that of NTP server time calibration, that is, GPS satellite time calibration is preferentially configured. For example, the time calibration function of the GPS satellite is enabled, and the time calibration function of the NTP server is disabled. Or, the time calibration function of the GPS satellite is preferentially enabled, and the time calibration function of the NTP server is enabled after a preset duration.
[0061] In other embodiments, the step of 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, 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 the first threshold, configuring 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.
[0062] 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 does not encounter obvious network or system problems during this period. At this time, the priority of GPS satellite time calibration is lower than that of NTP server time calibration, that is, NTP server time calibration is preferentially configured to reduce the overall power consumption of the chip device. For example, the time calibration function of the NTP server is enabled, and the time calibration function of the GPS satellite is disabled. Or, the time calibration function of the NTP server is preferentially enabled, and the time calibration function of the GPS satellite is enabled after a preset duration.
[0063] 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 judge whether there are network problems with the chip device. At this time, the priority of GPS satellite time calibration is 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 enabled. If the GPS satellite completes time calibration at a certain moment, the NTP server will no longer be used for time calibration.
[0064] Exemplarily, in the case where the priority of configuring GPS satellite time calibration is equal to the priority of NTP server time calibration, if the current time has been calibrated through the NTP server, then GPS satellite time calibration is not performed within a preset duration (such as 3S); or, in the case where the priority of configuring GPS satellite time calibration is equal to the priority of NTP server time calibration, if the current time has been calibrated through the GPS satellite, then NTP server time calibration is not performed within a preset duration (such as 3S).
[0065] In this way, when the GPS satellite and NTP server time calibration functions are both enabled in this application, if a certain time calibration source (such as the GPS satellite) completes time calibration first, then the mutual exclusion locking mechanism is triggered, and another time calibration source (such as the NTP server) is prohibited 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.
[0066] It should be noted that the first threshold represents 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 not good (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 the GPS satellite for time calibration needs to be dynamically determined in combination with the environmental perception data.
[0067] Specifically, if the electromagnetic interference intensity in the environment where the chip device is located is too high (such as in an industrial closed 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.
[0068] 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:
[0069] 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;
[0070] 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;
[0071] Wherein, when the electromagnetic interference intensity is greater than or equal to the intensity threshold, the first threshold is corrected positively; when the electromagnetic interference intensity is less than the intensity threshold, the first threshold is corrected negatively.
[0072] Specifically, the electromagnetic noise level in the environment (e.g., in dBm) can be quantified by a dedicated sensor, and the magnitude of electromagnetic interference intensity can be characterized by the electromagnetic noise level; and the ambient 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 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.
[0073] Exemplarily, when the electromagnetic interference intensity ≥ a preset intensity threshold (e.g., -80 dBm), it indicates that the GPS signal may be unstable. At this time, a positive correction is made to the first threshold (e.g., increasing the threshold to 120% of the original value) to reduce the sensitivity of triggering GPS priority time correction. 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 correction 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 made to the first threshold (e.g., reducing the threshold to 80% of the original value) to trigger GPS priority time correction more sensitively. The GPS time correction priority is directly configured to be higher than that of NTP, and the high-precision characteristics of GPS are utilized to quickly complete time correction.
[0074] In this way, by introducing the electromagnetic interference intensity and ambient 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.
[0075] For example, in the outdoor substation scenario of a smart grid, the device 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 correction when the electromagnetic interference is small, and configure to preferentially use NTP time correction when the interference is strong. In this way, according to different scenario environments, the automatic configuration of the time correction function is completed in advance, thereby improving the time correction efficiency and the storage efficiency of logs.
[0076] To further improve the accuracy of time correction control, in one embodiment, the correcting the first threshold according to the electromagnetic interference intensity and ambient temperature includes:
[0077] Inputting the current electromagnetic interference intensity and the current ambient temperature into a correction model to obtain the first threshold, where the correction model satisfies the following expression:
[0078] 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 dLet \(T\) be the current ambient temperature, \(T_0\) be the reference ambient temperature, and \(K_1\), \(K_2\) be the correction coefficients respectively characterizing the electromagnetic interference intensity and the ambient temperature on the first threshold. The correction coefficients \(K_1\), \(K_2\) can both be set to 0.5.
[0079] Specifically, when \(E\) d \(> E_0\), the electromagnetic interference increases, and \(K_1\times(E_d - E_0)\) is positive, resulting in an increase in \(P\), that is, increasing the difficulty of triggering GPS priority time synchronization, avoiding time synchronization failure due to large GPS signal interference. At this time, the system is more inclined to rely on NTP time synchronization. When \(E\) d \(\leq E_0\), the electromagnetic interference weakens or remains unchanged, and \(K_1\times(E_d - E_0)\) is negative or zero, resulting in a decrease in \(P\), that is, more sensitively triggering GPS priority time synchronization. At this time, the system is more inclined to rely on GPS time synchronization. When \(T\) d \(> T_0\), the increase in temperature may lead to a decrease in hardware performance (such as crystal oscillator frequency drift, reduced stability of the network module). At this time, \(-K_2\times(T\) d \(- T_0)\) is negative, resulting in a decrease in \(P\), lowering the threshold for triggering GPS priority time synchronization, and being more inclined to give priority to using GPS time synchronization. When \(T\) d \(\leq T_0\), the temperature is appropriate. At this time, \(-K_2\times(T\) d \(- T_0)\) is positive, \(P\) increases, increasing the difficulty of triggering GPS priority time synchronization, and reducing the triggering frequency of GPS time synchronization. That is, when the temperature is stable and appropriate, the system is more inclined to NTP time synchronization, reducing GPS power consumption and computational overhead.
[0080] Based on this, the system of the present application can implement an optimal time synchronization 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.
[0081] Step S300: Perform real-time time synchronization of the chip device through an NTP server or a GPS satellite, and when the real-time time synchronization 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;
[0082] 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 condition is satisfied (such as a large amount of initial log sequence data, weak electromagnetic interference, and high temperature), the real-time time calibration of the chip device is preferentially performed through the GPS satellite. If the NTP server priority time calibration condition is satisfied (such as a small amount of initial log sequence data), 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 appended with timestamp information, and the later log sequence is generated immediately after the previous log sequence.
[0083] In one embodiment, when the real-time time calibration of the chip device is successful, the method further includes:
[0084] Automatically adjust the log storage settings to enable the temporary cache file to obtain transfer permission and / or automatic cleaning permission.
[0085] 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 transfer permission and / or automatic cleaning permission.
[0086] For example, allow the temporary cache file to be transferred to a long-term storage medium (such as a hard disk, cloud storage), such as in a log file. In this way, after the time calibration is successful, the critical log data is safely transferred from the volatile cache to prevent data loss due to power failure, system crash, data overwrite, or other reasons.
[0087] Step S400, when the temporary cache file exceeds the preset capacity limit, automatically clean the earliest 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.
[0088] 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 log information for up to ten days at most, or the earliest initial log sequence is cleaned when the quantity or capacity is exceeded 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.
[0089] It should be noted that the initial log sequence and the corresponding later log sequence can be associated by a tag number to prevent time synchronization errors.
[0090] 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 a preset limit.
[0091] In one embodiment, the step S400: automatically cleaning the earliest initial log sequence stored and synchronously sending it to the log file and the corresponding later log sequence for time synchronization to obtain real-time log information, includes:
[0092] S410. Perform time synchronization on the corresponding initial log sequence according to the later log sequence so that the initial log sequence obtains timestamp information;
[0093] S420. Perform associated splicing on the later log sequence and the initial log sequence that has obtained timestamp information to obtain real-time log information.
[0094] Specifically, use the time information of the later log sequence and the time offset information in step S100 to add an accurate timestamp to the initial log sequence. After the initial log sequence obtains accurate timestamp information, integrate it with the later log sequence to form a complete and continuous log information flow, 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, the running state of the system and the occurrence process of events can be understood more comprehensively.
[0095] Exemplarily, for the above-mentioned: 0.00 - 0.01 seconds after startup: Log 1 (Hardware self-check completed), Log 2 (Kernel initialization) → stored in the first data block. 0.01 - 0.02 seconds after startup: Log 3 (Network module loading) → stored in the second 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.
[0096] 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 management personnel to conduct targeted analysis and fault troubleshooting.
[0097] It can be understood that cache files are usually located in high-speed storage media (such as memory), and their read and write speeds are much faster than those of traditional disk storage. When the chip device starts to generate log information, directly writing it into 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 number of log information, it is written into 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, the embodiments of the present application store the logs generated in the early stage in a temporary cache file and the logs generated in the later stage in a log file, which can improve the timeliness and security of log storage.
[0098] Based on this, a method for storing real-time logs provided by the embodiments of the present application first starts a timing module while the chip device starts, and stores the log information generated when the chip device starts 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 a first threshold, the priority of GPS satellite time calibration is configured to be higher than that of the NTP server time calibration; when the chip device successfully calibrates the time 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 for 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 in different time periods. In this way, the timeliness and security of log storage are greatly improved.
[0099] 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 embodiments 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.
[0100] 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 to synchronize the time with the corresponding later log sequence to obtain real-time log information.
[0101] 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.
[0102] 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.
[0103] 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.
[0104] 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.
[0105] 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 a read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CDROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0106] The embodiment of the present application also provides a computer program product, which includes one or more program codes, and the program codes are stored in a computer-readable storage medium. The processor of the warning system reads the program codes from the computer-readable storage medium, and the processor executes the program codes to complete the steps of the real-time log storage method provided in the above embodiment.
[0107] 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 can be a read-only memory, a magnetic disk, or an optical disc, etc.
[0108] 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.
[0109] 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 method embodiments 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.
[0110] 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 the NTP server or 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 electromagnetic interference intensity and environmental temperature; Correct the first threshold according to the electromagnetic interference intensity and 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 the real-time log according to claim 2, characterized in that, Correcting the first threshold according to the electromagnetic interference intensity and environmental temperature includes: Input the current electromagnetic interference intensity and 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); where P is the corrected first threshold, P0 is the first threshold before correction, 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 correction coefficients of the electromagnetic interference intensity and the ambient temperature to the first threshold 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 the NTP server or 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 real-time logs according to claim 1, characterized in that, Automatically clean the earliest 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, including: Synchronize the time of the corresponding initial log sequence according to 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 timestamp information obtained to obtain real-time log information.
7. The storage method of the real-time log according to claim 1, wherein 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 the time offset information.
8. The storage method of the real-time log 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 transfer permission and / or the automatic cleaning permission.
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, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
System, method and device for realizing time synchronization function, processor and computer readable storage medium thereof
CN113872718A
Emergency broadcast equipment log debugging method
CN112968744A
Log time correction method and device, electronic equipment and storage medium
CN116701338A