Scalable data logging method

By defining data and cache structures, the problems of single log recording format and printf blocking are solved, realizing flexible log output and timing control, which is suitable for tasks with high timing requirements.

CN115248802BActive Publication Date: 2026-03-24TIANJIN JINHANG COMP TECH RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-19
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing technologies use a single logging format, which means that logs can only be output to a fixed port, and the printf function can cause data blocking in time-sensitive processing tasks.

Method used

Define a data structure and a cache structure. Record the display type and original data length of the process data through a basic recording function. Write the data structure into the cache structure in sequence, and determine the conversion function for output based on the enumeration type variable.

Benefits of technology

It enables flexibility and timing control in log output, avoids data blocking in tasks with high timing requirements, and allows log data to be processed uniformly when the CPU is idle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115248802B_ABST
    Figure CN115248802B_ABST
Patent Text Reader

Abstract

The application provides an extensible data logging method, comprising: defining a data structure body for recording process data, original data length and display type of final output display; defining a cache structure body, members of the cache structure body comprising a record array for caching a plurality of data structure bodies; recording the process data, the original data length and the display type into the data structure body based on a basic record function; sequentially writing all the data structure bodies into the record array of the cache structure body; sequentially reading out the data structure bodies in the cache structure body; determining a conversion function according to an enumeration type variable in the read data structure body; and converting and outputting the process data in the data structure body as data with the enumeration type variable through the conversion function and the original data length. Thus, the time sequence of the log record is improved, and the recording process does not affect other important process processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure generally relates to the field of computer control, and specifically to a scalable data logging method. Background Technology

[0002] In existing technologies, the logging format is relatively simple, usually using printf to redirect to a file or device. This method results in output only to a fixed port. At the same time, printf, as a blocking function in the standard output library, can cause data blocking for time-sensitive processing tasks. Summary of the Invention

[0003] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a scalable data logging method that can solve the above-mentioned technical problems.

[0004] This application provides a scalable data logging method, including:

[0005] Define a data structure, which includes a first union, a second union, and an enumeration type variable; the first union is used to record process data, and the record type of the process data includes 32-bit unsigned data, 32-bit signed data, character data, and character array; the second union is used to record the original data length of the process data; the enumeration type variable represents the display type of the process data to be finally output and displayed;

[0006] Define a cache structure, wherein the members of the cache structure include a record array, and the record array is used to cache multiple data structures;

[0007] Based on the basic recording function, the process data is recorded in the first union, the original data length of the process data is recorded in the second union, and the enumeration type variable is assigned the display type that the process data is to be finally output and displayed.

[0008] Write all the data structures into the record array of the cache structure in sequence;

[0009] The data structures in the cache structure are read out sequentially; a conversion function is determined based on the enumeration type variables in the read data structures; the process data in the data structures is converted and output as data with the enumeration type variables using the conversion function and the original data length.

[0010] According to the technical solution provided in the embodiments of this application, the original data length of the process data and the display type to be finally output are obtained by the basic recording function and generic operation mapping.

[0011] According to the technical solution provided in the embodiments of this application, the enumeration type variables include string data, unsigned integer decimal data, one-byte signed integer data, two-byte signed integer data, four-byte signed integer data, one-byte hexadecimal data, two-byte hexadecimal data, four-byte hexadecimal data, and character data;

[0012] The conversion functions include decimal processing functions, hexadecimal processing functions, and character processing functions;

[0013] The method for determining the conversion function based on the enumeration type variables in the read data structure includes the following steps:

[0014] When it is determined that the enumeration type variable is string data or character data, the character processing function is called;

[0015] When it is determined that the enumerated type variable is an unsigned decimal integer, a one-byte signed integer, a two-byte signed integer, or a four-byte signed integer, the decimal processing function is called.

[0016] When it is determined that the enumerated type variable is one byte of hexadecimal data, two bytes of hexadecimal data, or four bytes of hexadecimal data, the hexadecimal processing function is called.

[0017] According to the technical solution provided in the embodiments of this application, the character processing function is used to receive the read process data and the original data length; and output and display the process data.

[0018] According to the technical solution provided in the embodiments of this application, the decimal processing function is used for:

[0019] Receive the read process data and enumeration type variables;

[0020] Calculate the sign variable: When the enumeration type variable is a one-byte signed integer data, a two-byte signed integer data, or a four-byte signed integer data, set the sign variable to 1; when the display type is an unsigned decimal integer data, set the sign variable to 0.

[0021] Define a character array output1 with a length of 11;

[0022] Define a variable divider, with an initial value of 1000000000;

[0023] When the sign variable is 1, the negative sign is assigned to the i-th position of the character data output1; i = i + 1, where i represents the number of elements, and the initial value of i is 0; execute the loop step;

[0024] If the symbolic variable is 0, execute the loop step directly;

[0025] The cyclic steps specifically include:

[0026] Step a: If the process data is less than the variable divider, update the variable divider to the value divided by 10 and execute step a; otherwise, execute step b.

[0027] Step b:

[0028] When the variable divider is greater than or equal to 10: divide the process data by the variable divider and add 0x30; assign the calculation result to the i-th bit of output1; i = i + 1; update the process data to the remainder of the process data divided by the variable divider; update the variable divider to the variable divider divided by 10, and execute step c;

[0029] If the variable divider is less than 10, proceed directly to step c;

[0030] Step c: Add 0x30 to the process data and assign it to the i-th bit of the character array output; i = i + 1; Execute step d;

[0031] Step d: Output the character array output1 and the number of elements i.

[0032] According to the technical solution provided in the embodiments of this application, the hexadecimal processing function is used for:

[0033] Receive the read process data and the original data length; obtain the data bit length nDigits based on the original data length;

[0034] Define a constant character set hexVals with a length of 16. The elements of the constant character set hexVals are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

[0035] Define a character array output2 with a length of 9;

[0036] Define an integer variable j;

[0037] Set the initial value of j to the number of data bits nDigits minus 1;

[0038] When the integer variable j is greater than -1, the element in the constant character array hexVals that is the value of process data &0x0F is obtained and assigned to the j-th element of the character array output2. The value of the process data is shifted four bits to the right and then assigned to the process data, j = j-1. This step is repeated.

[0039] Output the character array output2 and the number of data bits nDigits.

[0040] According to the technical solution provided in the embodiments of this application, the members of the cache structure further include write pointer positions; writing the data structure of the data structure into the cache structure specifically includes the following steps:

[0041] s51: Receive write data pointer and write cache structure pointer; the write parameter data pointer points to the data structure; the write cache structure pointer points to the cache structure;

[0042] s52: Write the data of the data structure pointed to by the write parameter data pointer to the write position in the cache structure pointed to by the cache structure pointer, wherein the write position is the write pointer position plus one;

[0043] s53: If the write pointer position is not 0xFF, update the write pointer position to the write pointer position plus one; if the write pointer position is 0xFF, set the write pointer position to 0.

[0044] s54: Repeat steps s51-s53.

[0045] 11. According to the technical solution provided in the embodiments of this application, the member of the cache structure further includes a read pointer position, and reading the data structure in the record array specifically includes the following steps:

[0046] s71: Receives a pointer to the read parameter data and a pointer to the read cache structure; the pointer to the read cache structure points to the cache structure;

[0047] s72: Assign the data at the read position of the cache structure pointed to by the read cache structure pointer to the position pointed to by the read parameter data; the read position is the read pointer position of the cache structure plus one;

[0048] s73: If the read pointer position is not 0xFF, update the write read pointer position to the read pointer position plus one; if the read pointer position is 0xFF, set the read pointer position to 0.

[0049] s74: Repeat steps s71-s73.

[0050] According to the technical solution provided in the embodiments of this application, the members of the cache structure also include the number of elements of the data structure contained in the record array, and the number of elements has a maximum set value, which is used to characterize the capacity of the cache structure;

[0051] Specifically, step s51 involves determining that when the number of elements is less than the maximum set value: receiving a write data pointer and a write cache structure pointer; the write parameter data pointer points to the data structure; and the write cache structure pointer points to the cache structure.

[0052] Specifically, step s53 involves: when the write pointer position is not 0xFF, updating the write pointer position to the write pointer position plus one, and updating the number of elements to the number of elements plus one; when the write pointer position is 0xFF, setting the write pointer position to 0.

[0053] According to the technical solution provided in the embodiments of this application, step s71 specifically involves, when determining that the number of elements is less than the maximum set value: receiving a read parameter data pointer and a read cache structure pointer; the read cache structure pointer points to the cache structure;

[0054] Specifically, step s73 involves: when the read pointer position is not 0xFF, updating the write-read pointer position to the read pointer position plus one, and updating the number of elements to the number of elements minus one; when the read pointer position is 0xFF, setting the read pointer position to 0.

[0055] The beneficial effects of this application are as follows: By defining a data structure, different process data, corresponding to the display type to be displayed for different process data, and the original data length can be recorded in the data structure based on the basic recording function. By defining a cache structure, numerous data structures can be cached sequentially in the cache structure. Therefore, the log can be processed only after the high-priority transactions are completed, which facilitates timing control. Finally, according to the display type in different data structures, a conversion function is determined to convert the process data read from the data structure into data with the specified display type for output display. In this way, the final output interface can be set arbitrarily, such as using CAN bus, network port, etc. Secondly, in processes with high timing requirements, this application only temporarily stores the data in the cache, which will not affect the processing of the current important process. When the important tasks are completed and the CPU is idle, the data in the cache can be retrieved and processed at the same time. Attached Figure Description

[0056] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:

[0057] Figure 1 A flowchart illustrating a scalable data logging method provided in this application. Detailed Implementation

[0058] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.

[0059] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0060] Example 1

[0061] Please refer to Figure 1 A flowchart of a scalable data logging method provided in this application includes:

[0062] S1: Define a data structure, which includes a first union, a second union, and an enumeration type variable; the first union is used to record process data, and the record type of the process data includes 32-bit unsigned data, 32-bit signed data, character data, and character array; the second union is used to record the original data length of the process data; the enumeration type variable represents the display type of the process data to be finally output and displayed;

[0063] S2: Define a cache structure, the members of which include a record array, the record array being used to cache multiple data structures;

[0064] S3: Based on the basic recording function, record the process data into the first union, record the original data length of the process data into the second union, and assign the enumeration type variable the display type that the process data is to be finally output and displayed;

[0065] S4: Write all the data structures into the record array of the cache structure in sequence;

[0066] S5: Read out the data structures in the cache structure in sequence; determine the conversion function according to the enumeration type variables in the read data structures; convert the process data in the data structures and output it as data with the enumeration type variables through the conversion function and the original data length.

[0067] Specifically, the original data length includes the string length and the number of bytes;

[0068] Specifically, the original data length of the process data and the display type (i.e., enumerated type variable) to be finally output are obtained by the basic recording function and generic operation mapping.

[0069] Specifically, the basic recording function is used to record the process data; the basic recording function includes:

[0070] 1. log_char, used to record character data;

[0071] 2. log_str, used to record string data;

[0072] 3. log_var, used to record various types of data;

[0073] 4. log_dec, used to record decimal data;

[0074] 5. log_hex, used to record hexadecimal data;

[0075] 6. log_array, used to record arrays;

[0076] 7. log_array_dec: Records a decimal array;

[0077] 8. log_array_hex, records a hexadecimal array.

[0078] Specifically, the basic recording function can be called by the user according to their needs, and the display type and original data length of the process data to be finally output are obtained by the basic recording function and generic operation mapping.

[0079] To facilitate understanding by those skilled in the art, the above-mentioned log_dec, log_hex, log_char, log_array, log_array_dec, and logarray_hex will be used as examples for explanation:

[0080] 1) The steps of the log_dec algorithm include:

[0081] Receive input parameters, which include process data to be recorded;

[0082] Taking C language as an example, the generic operation of the computer language is called to determine the enumeration type variable (i.e. the display type to be finally output): the enumeration type variable is mapped according to the type of the process data, as shown in Table-1;

[0083] The original data length (number of bytes) is recorded in the second union, and the process data is recorded in the first union.

[0084]

[0085]

[0086] Table 1

[0087] 2) The algorithm steps of log_hex include:

[0088] Receive input parameters, which include process data to be recorded;

[0089] Taking C language as an example, the generic operation of the computer language is called to determine the enumeration type variable (i.e., the display type to be finally output): the enumeration type variable is mapped according to the type of the process data, as shown in Table-2:

[0090] The original data length (number of bytes) is recorded in the second union, and the process data is recorded in the first union.

[0091] Serial Number Procedure data types Enumeration type variables 1 unsignedchar _LOG_HEX_1 (one byte of hexadecimal data) 2 unsignedshort _LOG_HEX_2 (two-byte hexadecimal data) 3 unsignedlong _LOG_HEX_4 (four-byte hexadecimal data) 4 unsignedint _LOG_HEX_4 (four-byte hexadecimal data) 5 char _LOG_HEX_1 (one byte of hexadecimal data) 6 signedchar _LOG_HEX_1 (one byte of hexadecimal data) 7 signedshort _LOG_HEX_2 (two-byte hexadecimal data) 8 signedlong _LOG_HEX_4 (four-byte hexadecimal data) 9 signedint _LOG_HEX_4 (four-byte hexadecimal data)

[0092] Table 2

[0093] 3) The algorithm steps for log_char include:

[0094] Receive input parameters, which include process data to be recorded;

[0095] Set the enumeration type variable to the character data LOG_CHAR;

[0096] The process data is recorded in the first union, and the original data length (number of bytes) "1" is recorded in the second union.

[0097] 4) The algorithm steps for log_array include:

[0098] The input parameters include: an array pointer pArray, of type untyped pointer; the number of elements nItems, of type unsigned integer; the number of bytes per element nBytesPerItem, of type unsigned short integer; and the record data type Arraytype, of type the enumeration type.

[0099] Define an unsigned character pointer pData, initialize it with pArray (cast pArray to an unsigned character pointer), and set the initial value of offset to 0;

[0100] s4_1: Decrement nItems by one, looping to check if nItems is 0. If it is not 0, go to s4_2; if it is 0, end.

[0101] s4_2: Check if the value of nBytesPerItem is 4. If the check is successful, take the address of pData with the index offset, take 4 bytes of data at this address, and assign it to value, then go to s4_5; if the check fails, go to s4_3.

[0102] s4_3: Check if the value of nBytesPerItem is 2. If the check is successful, take the address of pData with the index offset, take 2 bytes of data at this address, and assign it to value, then go to S4_5; if the check fails, go to s4_4.

[0103] s4_4: Retrieve the address of pData at index offset, take 1 byte of data from this address, and assign it to value. Go to s4_5;

[0104] s4_5: Record the value of value into the first union, set the type of the enumeration variable to Arraytype, and update the value of offset to offset+nBytesPerItem. Go to s4_6.

[0105] s4_6: Check if nItems is not 0, and use log_char to record spaces.

[0106] 5) The algorithm steps of log_array_dec include:

[0107] Receive input parameters, including: array pointer to be recorded, and number of elements nItems;

[0108] Call log_array and pass the array pointer array, the number of elements nItems, sizeof((array)[0]), and the data type (i.e. the display type to be output) to the log_array function for processing; sizeof((array)[0]) is the number of bytes of each element of the array pointer;

[0109] The data type of the record is determined by the C language keyword: _Generic (generic), and the data type is mapped according to the type of the process data, as shown in Table-1;

[0110] 6) The algorithm steps of log_array_dec include:

[0111] Receive input parameters, including: array pointer to be recorded, and number of elements nItems;

[0112] Call log_array and pass the array pointer array, the number of elements nItems, sizeof((array)[0]), and the data type (i.e. the display type to be output) to the log_array function for processing;

[0113] The data type of the record is determined by the C language keyword: _Generic (generic), and the data type is mapped according to the type of the process data, as shown in Table-2;

[0114] It needs further explanation that the logging format in the existing technology is relatively simple, usually using printf to redirect to a certain file or device. This means that the output can only be sent to a fixed port. At the same time, printf, as a blocking function in the standard output library, will cause data blocking for processing tasks with high time sequence requirements.

[0115] Based on this background, this application defines a data structure to record different process data, their corresponding display types, and original data lengths using basic recording functions. It also defines a cache structure to sequentially cache numerous data structures, allowing log processing to be performed only after high-priority transactions are completed, facilitating timing control. Finally, based on the display type in each data structure, a conversion function is determined to convert the process data read from that data structure into data with the specified display type. This approach allows for flexible configuration of the final output interface, such as using a CAN bus or Ethernet port. Furthermore, in processes with high timing requirements, data is only temporarily stored in the cache, without affecting the processing of currently important processes. Once important tasks are completed and the CPU is idle, the data in the cache can be retrieved and processed uniformly.

[0116] In some implementations, the enumeration type variables include string data, unsigned decimal integer data, one-byte signed integer data, two-byte signed integer data, four-byte signed integer data, one-byte hexadecimal data, two-byte hexadecimal data, four-byte hexadecimal data, and character data.

[0117] The conversion functions include decimal processing functions, hexadecimal processing functions, and character processing functions;

[0118] The method for determining the conversion function based on the enumeration type variables in the read data structure includes the following steps:

[0119] When it is determined that the enumeration type variable is string data or character data, the character processing function is called;

[0120] When it is determined that the enumerated type variable is an unsigned decimal integer, a one-byte signed integer, a two-byte signed integer, or a four-byte signed integer, the decimal processing function is called.

[0121] When it is determined that the enumerated type variable is one byte of hexadecimal data, two bytes of hexadecimal data, or four bytes of hexadecimal data, the hexadecimal processing function is called.

[0122] Specifically, the enumerated type variables include the above nine types, namely:

[0123] ① String data _LOG_STRING;

[0124] ② Unsigned integer decimal data: _LOG_UINT_DEC;

[0125] ③ One byte of signed integer data: _LOG_INT_DEC_1;

[0126] ④ Occupies two bytes of signed integer data: _LOG_INT_DEC_2;

[0127] ⑤ A four-byte signed integer data type: _LOG_INT_DEC_4;

[0128] ⑥ Occupies one byte of hexadecimal data: _LOG_HEX_1;

[0129] ⑦ Occupies two bytes of hexadecimal data: _LOG_HEX_2;

[0130] ⑧ Occupies 4 bytes of hexadecimal data _LOG_HEX_4;

[0131] ⑨ Character data type LOG_CHAR;

[0132] Example 2

[0133] Based on Embodiment 1, in some embodiments, the character processing function is used to receive the read process data and the original data length; and output and display the process data.

[0134] In some embodiments, the decimal processing function is used for:

[0135] Receive the read process data and enumeration type variables;

[0136] Calculate the sign variable: When the enumeration type variable is a one-byte signed integer data, a two-byte signed integer data, or a four-byte signed integer data, set the sign variable to 1; when the display type is an unsigned decimal integer data, set the sign variable to 0.

[0137] Define a character array output1 with a length of 11;

[0138] Define a variable divider, with an initial value of 1000000000;

[0139] When the sign variable is 1, the negative sign is assigned to the i-th position of the character data output1; i = i + 1, where i represents the number of elements, and the initial value of i is 0; execute the loop step;

[0140] If the symbolic variable is 0, execute the loop step directly;

[0141] The cyclic steps specifically include:

[0142] Step a: If the process data is less than the variable divider, update the variable divider to the value divided by 10 and execute step a; otherwise, execute step b.

[0143] Step b:

[0144] When the variable divider is greater than or equal to 10: divide the process data by the variable divider and add 0x30; assign the calculation result to the i-th bit of output1; i = i + 1; update the process data to the remainder of the process data divided by the variable divider; update the variable divider to the variable divider divided by 10, and execute step c;

[0145] If the variable divider is less than 10, proceed directly to step c;

[0146] Step c: Add 0x30 to the process data and assign it to the i-th bit of the character array output; i = i + 1; Execute step d;

[0147] Step d: Output the character array output1 and the number of elements i.

[0148] To facilitate understanding by those skilled in the art, a specific implementation process is taken as an example. For instance, the process data is 15, the enumeration variable type is a one-byte signed integer, and the algorithm process is as follows:

[0149] The enumeration type variable is determined to be a one-byte signed integer data. Therefore, the sign variable is set to 1, the negative sign character "-" is assigned to the 0th bit of the character data output1, and then the i = i + 1 operation is performed to change the value of i to 1.

[0150] Execute step a: Determine that the process data is less than the variable divider(1000000000), so update the variable divider to the variable divider divided by 10, and repeat step a until divider = 10. At this time, the process data 15 is greater than the variable divider(10), and execute step b.

[0151] Step b: At this point, the process data 15 is greater than 10. Divide 15 by 10 to get 1 in the computer. Add 0x30 to 1 (to make it a character number 1) and assign it to the first bit of output1. i = i + 1, so the value of i is 2. Take the remainder of the process data divided by 10 to get the process data 5. Divide divider by 10 to get 1. The value of divider is 1, which is less than 10. Proceed to step c.

[0152] Step c: Add 0x30 to the process data 5 (converting it into the character number 5) and assign it to the second bit of output1;

[0153] Step d: Output1 will output the 0th position of the array "-", the first position "1", and the second position "5" in sequence, which will be displayed as the character "-15".

[0154] In some embodiments, the hexadecimal processing function is used for:

[0155] Receive the read process data and the original data length; obtain the data bit length nDigits based on the original data length;

[0156] Define a constant character set hexVals with a length of 16. The elements of the constant character set hexVals are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

[0157] Define a character array output2 with a length of 9;

[0158] Define an integer variable j;

[0159] Set the initial value of j to the number of data bits nDigits minus 1;

[0160] When the integer variable j is greater than -1, the element in the constant character array hexVals that is the value of process data &0x0F is obtained and assigned to the j-th element of the character array output2. The value of the process data is shifted four bits to the right and then assigned to the process data, j = j-1. This step is repeated.

[0161] Output the character array output2 and the number of data bits nDigits.

[0162] Through the above steps, the recorded content in the first data can be converted and output as data with the specified display type, with fast conversion speed and low resource consumption.

[0163] To facilitate understanding by those skilled in the art, let's take a specific implementation process as an example. For instance, if the process data is 1E and the number of data bits (nDigits) is 2, then:

[0164] Set the initial value of j to the number of data bits nDigits minus 1, that is, j = 1;

[0165] At this point, the value of j is 1, which is greater than -1. The process data is 1E. A bitwise AND operation is performed with 0x0F to obtain the value E (decimal data is 14). The data at index E is retrieved, which is the character "E". "E" is stored in the first position of the output array. The process data is then shifted four bits to the right, and the process data becomes 01. The value of j is then decremented by 1, so j = 0.

[0166] The loop checks if the value of j is greater than -1 (0). The current process data is 01. A bitwise AND operation with 0x0F is performed, resulting in 1. The data at index 1 is retrieved, which is the character "1". This "1" is stored in the 0th position of the output2 array. The process data 01 is then shifted right by 4 bits to become 0. The value of j is decremented by 1, now set to -1, and the loop ends.

[0167] Output2 will output the 0th element of the array "1" and the 1st element "E" in sequence, which will be displayed as the character "1E".

[0168] Example 3

[0169] Based on Embodiment 2, in some embodiments, the members of the cache structure further include write pointer positions; writing the first data of the data structure into the cache structure specifically includes the following steps:

[0170] s51: Receive write data pointer and write cache structure pointer; the write parameter data pointer points to the data structure; the write cache structure pointer points to the cache structure;

[0171] s52: Write the data of the data structure pointed to by the write parameter data pointer to the write position in the cache structure pointed to by the cache structure pointer, wherein the write position is the write pointer position plus one;

[0172] s53: If the write pointer position is not 0xFF, update the write pointer position to the write pointer position plus one; if the write pointer position is 0xFF, set the write pointer position to 0.

[0173] s54: Repeat steps s51-s53.

[0174] In some embodiments, the cache structure members also include a read pointer position, and reading the first data from the record array specifically includes the following steps:

[0175] s71: Receives a pointer to the read parameter data and a pointer to the read cache structure; the pointer to the read cache structure points to the cache structure;

[0176] s72: Assign the data at the read position of the cache structure pointed to by the read cache structure pointer to the position pointed to by the read parameter data; the read position is the read pointer position of the cache structure plus one;

[0177] s73: If the read pointer position is not 0xFF, update the write read pointer position to the read pointer position plus one; if the read pointer position is 0xFF, set the read pointer position to 0.

[0178] s74: Repeat steps s71-s73.

[0179] Through the above steps, the data structure can be written to the cache structure in sequence, and the data in the cache structure can be read out in sequence, further improving the timing of the writing and reading processes.

[0180] In some embodiments, the members of the cache structure further include the number of elements of the data structure contained in the record array, wherein the number of elements has a maximum set value to characterize the capacity of the cache structure;

[0181] Specifically, step s51 involves determining that when the number of elements is less than the maximum set value: receiving a write data pointer and a write cache structure pointer; the write parameter data pointer points to the data structure; and the write cache structure pointer points to the cache structure.

[0182] Specifically, step s53 involves: when the write pointer position is not 0xFF, updating the write pointer position to the write pointer position plus one, and updating the number of elements to the number of elements plus one; when the write pointer position is 0xFF, setting the write pointer position to 0.

[0183] In some embodiments, step s71 specifically involves, when determining that the number of elements is less than a maximum set value: receiving a read parameter data pointer and a read cache structure pointer; the read cache structure pointer points to the cache structure;

[0184] Specifically, step s73 involves: when the read pointer position is not 0xFF, updating the write-read pointer position to the read pointer position plus one, and updating the number of elements to the number of elements minus one; when the read pointer position is 0xFF, setting the read pointer position to 0.

[0185] By comparing the number of elements with the maximum set value, the storage capacity is not exceeded. At the same time, by setting the read pointer position to 0 when it is determined to be 0xFF and setting the write pointer position to 0 when it is determined to be 0xFF, errors are avoided during the writing or reading process.

[0186] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the inventive concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.

Claims

1. A scalable data logging method, characterized by, The application relates to a data structure and a method for recording process data. The data structure comprises a first common body, a second common body and an enumeration type variable; the first common body is used for recording process data, the recording types of the process data include 32-bit unsigned data, 32-bit signed data, character data and character array; the second common body is used for recording the original data length of the process data; and the enumeration type variable represents the display type of the process data to be finally output and displayed. The cache structure body comprises a record array used for caching a plurality of data structure bodies. A basic recording function is used to record process data into the first common body, record the original data length of the process data into the second common body and assign the enumeration type variable to the display type of the process data to be finally output and displayed. All the data structure bodies are sequentially written into the record array of the cache structure body. The data structure bodies in the cache structure body are sequentially read out; an enumeration type variable in the read data structure body is used to determine a conversion function; and the process data in the data structure body is converted and output and displayed as data with the enumeration type variable through the original data length and the conversion function. The basic recording function is used to record the process data; and the basic recording function comprises: log_char, used for recording character data; log_str, used for recording string data; log_var, used for recording various data; log_dec, used for recording decimal data; log_hex, used for recording hexadecimal data; log_array, used for recording array; log_array_dec, used for recording decimal array; log_array_hex, used for recording hexadecimal array.

2. The scalable data logging method of claim 1, wherein, The original data length of the process data and the display type to be finally output and displayed are obtained through the basic recording function and generic operation mapping.

3. The scalable data logging method of claim 1, wherein, The enumeration type variable comprises string data, unsigned integer decimal data, one-byte signed integer data, two-byte signed integer data, four-byte signed integer data, one-byte hexadecimal data, two-byte hexadecimal data, four-byte hexadecimal data and character data. The conversion function comprises a decimal processing function, a hexadecimal processing function and a character processing function. The method for determining the conversion function according to the enumeration type variable in the read data structure body comprises the following steps: when the enumeration type variable is string data or character data, the character processing function is called; when the enumeration type variable is unsigned integer decimal data, one-byte signed integer data, two-byte signed integer data or four-byte signed integer data, the decimal processing function is called; when the enumeration type variable is one-byte hexadecimal data, two-byte hexadecimal data or four-byte hexadecimal data, the hexadecimal processing function is called.

4. The scalable data logging method of claim 3, wherein, The character processing function is used to receive the read process data, the original data length; output and display the process data.

5. The scalable data logging method of claim 3, wherein, The decimal processing function is used to: receive the read process data and the enumeration type variable; calculate the sign variable: if the enumeration type variable is a one-byte signed integer data or a two-byte signed integer data or a four-byte signed integer data, set the sign variable to 1; if the display type is an unsigned integer decimal data, set the sign variable to 0; define a character array output1 with a length of 11; define a variable divider, and the initial value of the variable divider is 1000000000; if the sign variable is 1, assign a minus sign to the i-th bit of the character data output1; i = i + 1, i represents the number of elements, and the initial value of i is 0; execute the loop step; if the sign variable is 0, directly execute the loop step; the loop step specifically includes: step a: if the process data is less than the variable divider, update the variable divider to the variable divider divided by 10, and execute step a; otherwise, execute step b; step b: if the variable divider is greater than or equal to 10: divide the process data by the variable divider, and add 0x30; assign the calculation result to the i-th bit of the output1; i = i + 1; update the process data to the remainder of the process data divided by the variable divider; update the variable divider to the variable divider divided by 10, and execute step c; if the variable divider is less than 10, directly execute step c; step c: add 0x30 to the process data and assign it to the i-th bit of the character array output; i = i + 1; execute step d; step d: output the character array output1 and the number of elements i.

6. The scalable data logging method of claim 3, wherein, The hexadecimal processing function is used to: receive the read process data and the original data length; obtain the data bit number nDigits according to the original data length; define a constant character group hexVals with a length of 16, and the elements of the constant character group hexVals are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F; define a character array output2 with a length of 9; define an integer variable j; set the initial value of j to the data bit number nDigits minus 1; if the integer variable j is greater than -1, obtain the element of the constant character group hexVals that is the value &0x0F of the process data, and assign it to the j-th bit element of the character array output2; assign the value of the process data right shifted by four bits to the process data, j = j - 1, and repeat this step; output the character array output2 and the data bit number nDigits.

7. The scalable data logging method of claim 1, wherein, The member of the cache structure further comprises a write pointer position; the step of writing the data structure of the data structure into the cache structure specifically comprises the following steps: s51: receiving a write data pointer and a write cache structure pointer; the write parameter data pointer points to the data structure; the write cache structure pointer points to the cache structure; s52: writing the data of the data structure pointed to by the write parameter data pointer into the to-be-written position in the cache structure pointed to by the write cache structure pointer, the to-be-written position being the write pointer position plus one; s53: when the write pointer position is not 0xFF, updating the write pointer position to the write pointer position plus one; when the write pointer position is 0xFF, setting the write pointer position to 0; s54: repeating steps s51-s53.

8. The scalable data logging method of claim 7, wherein, The member of the cache structure further comprises a read pointer position, and the step of reading out the data structure in the record array specifically comprises the following steps: s71: receiving a read parameter data pointer and a read cache structure pointer; the read cache structure pointer points to the cache structure; s72: assigning the data of the read position of the cache structure pointed to by the read cache structure pointer to the position pointed to by the read parameter data; the read position being the read pointer position of the cache structure plus one; s73: when the read pointer position is not 0xFF, updating the read pointer position to the read pointer position plus one; when the read pointer position is 0xFF, setting the read pointer position to 0; s74: repeating steps s71-s73.

9. The scalable data logging method of claim 8, wherein, The member of the cache structure further comprises an element number of the data structure contained in the record array, the element number having a maximum set value, used to represent the capacity of the cache structure; The step s51 specifically comprises: when the element number is less than the maximum set value, receiving a write data pointer and a write cache structure pointer; the write parameter data pointer points to the data structure; the write cache structure pointer points to the cache structure; The step s53 specifically comprises: when the write pointer position is not 0xFF, updating the write pointer position to the write pointer position plus one, and updating the element number to the element number plus one; when the write pointer position is 0xFF, setting the write pointer position to 0.

10. The scalable data logging method of claim 9, wherein, The step s71 specifically comprises: when the element number is less than the maximum set value, receiving a read parameter data pointer and a read cache structure pointer; the read cache structure pointer points to the cache structure; The step s73 specifically comprises: when the read pointer position is not 0xFF, updating the read pointer position to the read pointer position plus one, and updating the element number to the element number minus one; when the read pointer position is 0xFF, setting the read pointer position to 0.

Citation Information

Patent Citations

  • Method for analyzing and managing log file with hexadecimal data

    CN102447575A

  • Method and system for building big data distributed log

    CN105138615A