Text log management method and device based on embedded system, equipment and medium

By dividing continuous log storage areas in an embedded system and dividing them into subpartitions of equal sizes, rapid retrieval and loop coverage are achieved, and the hardware resource scarcity problem of embedded systems when storing and managing massive text log data is solved, and the problem of simplification of the hardware resource scarcity of embedded systems is solved. Log data management reduces resource usage.

CN119493780AActive Publication Date: 2025-02-21SHENZHEN QIHUI ELECTRIC CO LTD

Patent Information

Application Number
CN202311033509.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-16
Publication Date
2025-02-21
Estimated Expiration
2043-08-16

AI Technical Summary

Technical Problem

When embedded systems store and manage massive text log data, the scarcity of hardware resources makes it difficult to meet the needs of large-capacity storage, and the existing log systems are complex and difficult to quickly analyze and maintain.

Method used

A text log management method based on an embedded system is adopted to realize rapid retrieval, data writing and reading by dividing continuous log storage areas in the storage area and dividing them into multiple subpartitions of equal size. The method includes skipping to read the last N bytes of the subpartition, determining the current operation partition and write offset, and loop overlaying the historical data to manage the log data.

Benefits of technology

This method simplifies log data management, reduces the use of hardware resources, realizes rapid retrieval and sequential writing, is suitable for various storage media, and has the advantages of rapid deployment and low resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119493780A_ABST
    Figure CN119493780A_ABST
Patent Text Reader

Abstract

The invention discloses a text log management method and device based on an embedded system, equipment and a medium. According to the text log management method based on the embedded system, a storage medium is provided, the storage medium is divided into storage areas, and the storage areas are divided according to partitions; the management method comprises a writing method, a quick retrieval method and a data reading method. The method can be conveniently applied to an embedded system with relatively few hardware resources, the contradiction between embedded system development and large-capacity log data storage requirements is solved, meanwhile, the requirement that field maintenance is simple and easy to use can be met, and the method can be suitable for various storage media, occupies few system hardware resources, can be rapidly deployed, and has high practicability. And the method also has the advantages of quick retrieval, sequential writing, data reading, automatic coverage, few occupied resources and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of embedded system development, and in particular to a text log management method, device, electrical equipment and computer-readable storage medium based on an embedded system. Background Art

[0002] During the operation of electrical equipment, various working conditions may occur, causing abnormal or deviation in the operation of the equipment. Therefore, a well-designed operation log system is needed to record the abnormalities. In particular, a manual read-only log system is necessary for on-site maintenance personnel to quickly analyze problems and troubleshoot. Since most electrical equipment is an embedded system, hardware resources are relatively scarce, which is in conflict with the demand for large-capacity log data storage. Therefore, it is necessary to develop a method and device for managing massive text log data suitable for embedded systems to meet actual needs. Summary of the invention

[0003] In order to solve the above problems, the present invention provides a simple, easy-to-use, reliable and low-cost method for managing massive text log data, an electrical device and a computer-readable storage medium.

[0004] A text log management method based on an embedded system, in which a log storage area is divided in a storage area of ​​the embedded system, the log storage area is a continuous space, and the log storage area is divided into a plurality of sub-partitions of equal size; a method for managing massive text log data, including: a fast retrieval method, a data writing method and a data reading method, wherein,

[0005] The fast retrieval method is applied when the embedded system is started and includes:

[0006] S01, taking sub-partitions as units, jump-read the last N bytes of each sub-partition, and if the values ​​of the N bytes are all first preset values, stop reading and determine the sub-partition as the current operation partition;

[0007] S02, starting from the starting position of the current operation partition, sequentially reading the data of the current operation partition until the read data is equal to a first preset value, and the address where the first preset value is located is the current write offset;

[0008] S03, reading out the starting N bytes of the next partition of the current operation partition, and if the read data are all the first preset values, determining that the original storage offset is located in the first sub-partition, otherwise the original storage offset is located in the next partition of the current operation partition; wherein N is greater than or equal to 1;

[0009] S04, storing the current write offset and the original storage offset;

[0010] Data writing methods include:

[0011] S05, when saving the log data, sequentially write it in plain text format starting from the position of the current write offset;

[0012] S06, if the position of the current write offset crosses the boundary of the sub-partition, the content of the next sub-partition is set to the first preset value;

[0013] S07, if the current write offset position exceeds the boundary of the last sub-partition, overwrite the historical data starting from the first sub-partition;

[0014] Data reading methods include:

[0015] S08, starting from the original storage offset, and continuously reading data according to the length and position parameters of the read data.

[0016] A text log management device based on an embedded system includes a quick retrieval module, a data writing module and a data reading module; wherein:

[0017] The quick search module includes:

[0018] The current operation partition determination submodule is used to read the last N bytes of each subpartition in a jump manner based on the subpartition as a unit. If the values ​​of the N bytes are all the first preset value, the reading is stopped and the subpartition is determined as the current operation partition;

[0019] The current write offset determination submodule is used to read the data of the current operation partition in sequence starting from the starting position of the current operation partition until the read data is equal to a first preset value, and the address where the first preset value is located is the current write offset;

[0020] The original storage offset determination submodule is used to read out the starting N bytes of the next partition of the current operation partition, and if the read data are all the first preset values, the original storage offset is determined to be located in the first sub-partition, otherwise the original storage offset is located in the next partition of the current operation partition; wherein N is greater than or equal to 1;

[0021] The cache submodule is used to store the current write offset and the original storage offset;

[0022] The data writing module includes:

[0023] The sequential writing submodule is used to write sequentially from the current writing offset position in plain text format when saving log data;

[0024] The data reset submodule is used to set the content of the next subpartition to the first preset value if the position of the current write offset crosses the boundary of the subpartition;

[0025] The loop overwriting submodule is used to overwrite historical data from the first subpartition if the current write offset exceeds the boundary of the last subpartition;

[0026] The data reading module includes:

[0027] The free read submodule is used to continuously read data based on the length and position parameters of the read data, starting from the original storage offset.

[0028] An electrical device comprises an embedded system, and the embedded system adopts the above-mentioned text log management method based on embedded system.

[0029] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the above-mentioned text log management method based on an embedded system.

[0030] The above-mentioned text log management method, device, equipment and medium based on embedded system can be conveniently applied to embedded systems with relatively scarce hardware resources, solving the contradiction between embedded system development and large-capacity log data storage needs, and at the same time can meet the requirements of simple and easy on-site maintenance. It can be applied to various storage media, occupies less system hardware resources, can be quickly deployed, and also has the advantages of fast retrieval, sequential writing, data reading, automatic overwriting, and occupying very few resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 This is a schematic diagram of the minimum partition in an embodiment of the present invention;

[0032] Figure 2 A schematic diagram of determining a current write offset in an embodiment of the present invention;

[0033] Figure 3 This is a schematic diagram of writing data in an embodiment of the present invention;

[0034] Figure 4 Schematic diagram of automatic overwriting in an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0036] A text log management method based on an embedded system is applied in electrical equipment. A space with continuous addresses is divided in the storage area of ​​the embedded system as a log storage area. The log storage area is specifically used to store log data. In order to facilitate the rapid search, positioning, reading and writing of data, the allocated continuous storage area needs to be divided according to the minimum partitioning rule, that is, the log storage area is divided into multiple sub-partitions of equal size.

[0037] The text log management method is applicable to massive text log data, and specifically includes three parts: a quick retrieval method, a data writing method, and a data reading method.

[0038] The fast retrieval method is applied when the embedded system is started, and includes:

[0039] S01, taking sub-partitions as units, jump-read the last N bytes of each sub-partition, if the values ​​of the N bytes are all first preset values, stop reading and determine the sub-partition as the current operation partition.

[0040] like Figure 1 As shown in the figure, each sub-partition is also called the minimum partition, and the size of the sub-partition is any one of 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, and 4096 bytes; or, it can be divided according to the disposable memory overhead of the embedded system, or it can be determined according to the size of the minimum partition of the storage medium (such as the Sector, Block, etc. of the FLASH memory). N is a natural number greater than 1.

[0041] The first preset value is also called reset data, which is used to fill the partition. The first preset value is preferably 0xFF. Before crossing from the previous operation partition to the next operation partition, the next operation partition needs to be filled with reset data 0xFF. Therefore, if continuous reset data 0xFF greater than or equal to 4 bytes is found in the partition data, it can be determined that this partition is the current operation partition. Specifically, taking N as 4 as an example, taking the minimum partition as a unit, jump reading the last 4 bytes of each minimum partition, such as the minimum partition The last 4 bytes are all 0xFF and stop, and the minimum partition is determined as the current operation partition.

[0042] S02, starting from the starting position of the current operation partition, sequentially read the data of the current operation partition until the read data is equal to a first preset value, and the address where the first preset value is located is the current write offset.

[0043] The current write offset is used to point to the location where the log data is written. Figure 2 As shown, taking the first preset value of 0xFF as an example, starting from the starting position of the current operation partition, the data of the current operation partition is read in sequence until the reset data 0xFF is found ( Figure 2At this time, the value of A is 0xFF, and the address of A is the current write offset. It can be understood that after the log content is written sequentially in the current operation partition, the offset filled with reset data 0xFF will move backward in the partition.

[0044] S03, reading out the starting N bytes of the next partition of the current operation partition, and if the read data are all the first preset values, determining that the original storage offset is located in the first sub-partition, otherwise the original storage offset is located in the next partition of the current operation partition; wherein N is greater than or equal to 1;

[0045] Since the log data is stored in a circular overwrite manner in the storage space, the original storage offset of the log data is not necessarily the starting position of the first sub-partition, but may be on other sub-partitions. The original storage offset is used to point to the starting position of the log data. For example, read out the starting 4 bytes of the next partition of the current operation partition. If the read data is the reset data 0xFF, the original storage offset is determined to be the first minimum partition, otherwise it is the next partition of the previous operation partition.

[0046] S04, storing the current write offset and the original storage offset.

[0047] The current write offset and original storage offset traversed above are cached. Both offsets are used for subsequent log data writing and reading actions.

[0048] For data writing method, refer to Figure 3 , Figure 4 ,include:

[0049] S05, when saving the log data, write it sequentially from the current write offset in plain text format. That is, based on the current write offset, write the log data to be saved in the order of the current write offset, and the log data should be in plain text format.

[0050] S06, if the current write offset position crosses the boundary of the sub-partition, the content of the next sub-partition is set to the first preset value. That is, during the data saving process, if the write offset crosses the minimum partition boundary, the next minimum partition should be reset so that the content of the next minimum partition becomes 0xFF.

[0051] S07, if the current write offset exceeds the boundary of the last sub-partition, the historical data will be overwritten starting from the first sub-partition. That is, when the write offset exceeds the boundary of the defined storage medium range, the next minimum partition written will return to the previous minimum partition. At this time, the write offset is reset to zero, the starting save offset is reset, the historical data is overwritten sequentially, and the write-back overwrite flag is set for log reading and retrieval.

[0052] Furthermore, during the data writing process, when the saved data length is not aligned, for example, not 4-byte aligned, a space character is padded at the end of the write to ensure that the overall length of the data is 4-byte aligned, so as to save fragmented space and improve the utilization of storage space.

[0053] Data reading methods include:

[0054] S08, starting from the original storage offset, and continuously reading data according to the length and position parameters of the read data.

[0055] Specifically, suppose the currently known parameters are: total storage space capacity Sz, original storage offset Ma of log data, relative offset RO of data to be read, length RL of data to be read. If the text to be read is a continuous area in the storage space, the starting position offset of the area = Ma+RO, and the data of the specified length RL can be read continuously from this position offset.

[0056] Because the storage log is always adding new overwrites, the original offset Ma is always changing. Ma may be the starting position of any partition in the storage space, so Ma+RO has the problem of exceeding the storage space range. When Ma+RO exceeds the storage space size (Sz), a wrap-around operation should be performed. The wrap-around operation includes but is not limited to taking the remainder of the calculation result by the storage space size (Sz), and so on. That is, if this problem occurs when the address is incremented in the subsequent continuous read, it should be handled in the same way.

[0057] Provided is a text log management device based on an embedded system, comprising a quick retrieval module, a data writing module and a data reading module; wherein the quick retrieval module comprises: a current operation partition determination submodule, a current write offset determination submodule, an original storage offset determination submodule and a cache submodule; the data writing module comprises a sequential write submodule, a reset data submodule and a loop overwrite submodule; the data reading module comprises a free read submodule. The functions of the above submodules correspond to the above text log management method, and will not be repeated here.

[0058] An electrical device is provided. The electrical device comprises an embedded system. The embedded system adopts the above-mentioned text log management method based on the embedded system.

[0059] A computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text log management method based on an embedded system as described above is implemented.

[0060] The above is an explanation of the present invention to help understand the present invention, but the implementation mode of the present invention is not limited to the above-mentioned embodiments. Any changes, modifications, substitutions, combinations, and simplifications made without departing from the principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A text log management method based on an embedded system, characterized in that: A log storage area is divided in the storage area of ​​the embedded system, wherein the log storage area is a continuous space and is divided into a plurality of sub-partitions of equal size; The method for managing massive text log data includes: a fast retrieval method, a data writing method and a data reading method, wherein: The fast retrieval method is applied when the embedded system is started, and includes: S01, taking the sub-partition as a unit, jump-read the last N bytes of each sub-partition, and if the values ​​of the N bytes are all first preset values, stop reading and determine the sub-partition as the current operation partition; S02, starting from the starting position of the current operation partition, sequentially reading the data of the current operation partition until the read data is equal to the first preset value, and the address where the first preset value is located is the current write offset; S03, reading out the starting N bytes of the next partition of the current operation partition, and if the read data are all the first preset values, determining that the original storage offset is located in the first sub-partition, otherwise the original storage offset is located in the next partition of the current operation partition; wherein N is greater than or equal to 1; S04, storing the current write offset and the original storage offset; The data writing method comprises: S05, when saving the log data, sequentially writing in plain text format starting from the position of the current write offset; S06, if the position of the current write offset crosses the boundary of a sub-partition, setting the content of the next sub-partition to the first preset value; S07, if the position of the current write offset exceeds the boundary of the last sub-partition, overwriting the historical data from the first sub-partition; The data reading method comprises: S08, taking the original storage offset as a starting point, and continuously reading data according to the length and position parameters of the read data.

2. The text log management method based on embedded system as claimed in claim 1, characterized in that: In the data writing method, when the length of the stored data is not aligned to 4 bytes, a space character is padded at the end of the writing.

3. The text log management method based on embedded system as claimed in claim 1 or 2, characterized in that: The first preset value is 0xFF.

4. The text log management method based on the embedded system as claimed in claim 1 or 2, characterized in that: The N is 4.

5. The text log management method based on embedded system as claimed in claim 1 or 2, characterized in that: The size of the sub-partition is any one of 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, and 4096 bytes.

6. A text log management device based on an embedded system, characterized in that: It includes a quick retrieval module, a data writing module and a data reading module; wherein, The quick retrieval module comprises: The current operation partition determination submodule is used to read the last N bytes of each subpartition in a jump manner based on the subpartition as a unit, and if the values ​​of the N bytes are all the first preset values, stop reading and determine the subpartition as the current operation partition; A current write offset determination submodule is used to read the data of the current operation partition in sequence starting from the starting position of the current operation partition until the read data is equal to the first preset value, and the address where the first preset value is located is the current write offset; The original storage offset determination submodule is used to read out the starting N bytes of the next partition of the current operation partition, and if the read data are all the first preset values, determine that the original storage offset is located in the first sub-partition, otherwise the original storage offset is located in the next partition of the current operation partition; wherein N is greater than or equal to 1; A cache submodule, used for storing the current write offset and the original storage offset; The data writing module comprises: A sequential writing submodule, used for sequentially writing in plain text format starting from the position of the current writing offset when saving log data; A data resetting submodule, configured to set the content of the next subpartition to the first preset value if the position of the current write offset crosses the boundary of the subpartition; A loop overwriting submodule, used for overwriting historical data starting from the first subpartition if the position of the current write offset exceeds the boundary of the last subpartition; The data reading module comprises: The free reading submodule is used to continuously read data based on the length and position parameters of the read data, starting from the original storage offset.

7. An electrical device, characterized in that: The electrical device includes an embedded system, and the embedded system adopts the text log management method based on the embedded system as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the text log management method based on an embedded system as claimed in any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Resource log read-write method and device for reducing data redundancy

    CN109802990A

  • Vehicle-mounted MCU configurable log storage and analysis method and system

    CN112732522A

  • Log processing method of embedded system, equipment, and readable storage medium

    CN114077594A

  • High-reliability log storage method based on memory

    CN115292266A

  • Cross-region access method for embedded file system

    US20120102012A1

Cited By

  • Miniature log management method, semiconductor device and computer readable storage medium

    CN122309219A

  • Micro-log management method, semiconductor device, and computer-readable storage medium

    CN122309219B