Log information printing method, device and server

By converting log information from data segments to code segments and compiling it into executable binary files, the problem of limited log information storage in smart network interface card (SOC) is solved, achieving efficient log information printing and optimized printing paths.

CN120950016BActive Publication Date: 2026-01-16YIHUA TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511103976.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-07
Publication Date
2026-01-16
Estimated Expiration
2045-08-07

AI Technical Summary

Technical Problem

In the MPU subsystem inside the smart network interface card (SOC), the limited size of the DTCM data storage area prevents log information from being stored properly, affecting software development and debugging.

Method used

The preprocessing script converts the log information from data segment format to code segment format, and then uses an automated compilation tool to compile it into an executable binary file, clearing the memory occupied by the data segment and enabling the printing of log information in the code segment.

Benefits of technology

It significantly increases the storage capacity of log information and optimizes the printing path of log information, supporting efficient software development and debugging under conditions of limited hardware storage resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120950016B_ABST
    Figure CN120950016B_ABST
Patent Text Reader

Abstract

The application provides a log information printing method, device and server, relates to the technical field of software processing, and comprises the following steps: copying a source code file from an original directory to a temporary construction directory; performing a preprocessing operation on the source code file in the temporary construction directory through a preprocessing script to obtain a first log file in a data segment format, and converting the first log file from the data segment format to a code segment format to obtain a second log file; compiling the second log file into an executable binary target log file through an automatic compilation tool to clear the memory occupied by the log information in the data segment, and performing log information printing in the code segment based on the target log file. The application can significantly improve the storage capacity of log information and optimize the log information printing path.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software processing, and in particular to a log information printing method, device and server. BACKGROUND

[0002] There are multiple MPU subsystems in an intelligent network card SOC, each of which limits the size of a DTCM data storage area, and the MPU cannot read and write memory with storage spaces outside the subsystem. At present, the related technology proposes that a target executable file generated by a general compiler usually puts string data appearing in source code into a data segment and reads data for processing through a read memory instruction. However, due to the limited storage space of the data segment, part of the microcode hardware architecture cannot store a large amount of log string information, so that the conventional log information printing function cannot be normally used. SUMMARY

[0003] Therefore, the present application aims to provide a log information printing method, device and server, which can significantly improve the storage capacity of log information and optimize the log information printing path.

[0004] In a first aspect, an embodiment of the present application provides a log information printing method, which comprises the following steps: copying a source code file from an original directory to a temporary build directory; performing a preprocessing operation on the source code file in the temporary build directory through a preprocessing script to obtain a first log file in a data segment format, and converting the first log file from the data segment format to a code segment format to obtain a second log file; compiling the second log file into an executable binary target log file through an automated compilation tool to clear the memory occupied by the log information in the data segment, and performing log information printing in the code segment based on the target log file.

[0005] In an embodiment, the step of performing a preprocessing operation on the source code file in the temporary build directory through a preprocessing script to obtain a first log file in a data segment format comprises: performing file scanning processing on the source code file in the temporary build directory through the preprocessing script to obtain the first log file in the data segment format.

[0006] In an embodiment, the step of performing file scanning processing on the source code file in the temporary build directory through the preprocessing script to obtain a first log file in a data segment format comprises: searching the source code file participating in the compiler compilation in the temporary build directory, and storing the searched target source code file into a source file list; performing file scanning processing on the target source code file in the source file list one by one to obtain a log printing keyword, and obtaining the first log file according to the log printing keyword.

[0007] In an implementation, the step of converting the first log file from the data segment format to the code segment format to obtain the second log file comprises: performing string transfer processing on the first log file by the pre-processing script to transfer the first log file from the data segment format to the code segment format to obtain the second log file.

[0008] In an implementation, the step of performing string transfer processing on the first log file by the pre-processing script to transfer the first log file from the data segment format to the code segment format to obtain the second log file comprises: splitting log information in the first log file into a character set constructed by single characters; and embedding the character set into a code instruction framework to generate the second log file in the code segment format.

[0009] In an implementation, before the step of splitting log information in the first log file into a character set constructed by single characters, the method comprises: performing matching processing on a formatted output function of the first log file by using a regular expression to obtain a code instruction framework.

[0010] In an implementation, the step of splitting log information in the first log file into a character set constructed by single characters comprises: extracting log information in the first log file by using a regular expression and creating a string array; and assigning the log information to the string array character by character to obtain the character set.

[0011] In a second aspect, an embodiment of the present application further provides a log information printing device, which comprises: a file acquisition module configured to copy a source code file from an original directory to a temporary construction directory; a format conversion module configured to perform a pre-processing operation on the source code file in the temporary construction directory by a pre-processing script to obtain a first log file in a data segment format, and convert the first log file from the data segment format to a code segment format to obtain a second log file; and a file compilation module configured to compile the second log file into an executable binary target log file by an automatic compilation tool to clear memory occupied by log information in a data segment, and perform log information printing in a code segment based on the target log file.

[0012] In a third aspect, an embodiment of the present application further provides a server, comprising a processor and a memory, the memory storing computer executable instructions capable of being executed by the processor, and the processor executes the computer executable instructions to implement the method of any one of the first aspect.

[0013] In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, the computer readable storage medium storing computer executable instructions, and the computer executable instructions, when invoked and executed by a processor, cause the processor to implement the method of any one of the first aspect.

[0014] The embodiment of the present application brings the following beneficial effects:

[0015] The method, device and server for printing log information provided by the embodiment of the present application can significantly improve the storage capacity of log information and optimize the printing path of log information.

[0016] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent to those skilled in the art upon examination of the following or can be learned by practice of the present application. The objects and other advantages of the present application can be realized and attained by the structure particularly pointed out in the description, claims and drawings.

[0017] In order to make the above-mentioned objects, features and advantages of the present application more apparent, the following preferred embodiments are specifically described with reference to the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.

[0019] Figure 1 A schematic diagram of an intelligent network card storage structure provided by the embodiment of the present application;

[0020] Figure 2 A flowchart of a log information printing method provided by the embodiment of the present application;

[0021] Figure 3 A schematic diagram of MPU software memory usage before format conversion provided by the embodiment of the present application;

[0022] Figure 4 A schematic diagram of MPU software memory usage after format conversion provided by the embodiment of the present application;

[0023] Figure 5 A structural schematic diagram of a log information printing device provided by the embodiment of the present application;

[0024] Figure 6 This is a schematic diagram of the structure of a server provided in an embodiment of the present invention. Detailed Implementation

[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0026] Currently, see Figure 1 The diagram illustrates a smart network interface card (NIC) storage structure. Within a smart NIC SOC, there are dozens or even hundreds of MPU (microprocessor unit) subsystems. Due to chip size and power consumption considerations, each MPU subsystem limits the size of its DTCM (Data Transmission Center) data storage area and omits the hardware logic circuits for the MPU subsystem's dBus (data bus) and DCache (data cache). Therefore, the MPU processor can only retrieve values ​​from DDR and cannot load-store storage space outside the MPU subsystem. Furthermore, the DTCM storage space is typically only a few KB, supporting only essential business data storage and unable to store large amounts of log printing information during development and debugging. This prevents the software from properly using printf() to print log information, impacting software development and debugging. Therefore, the log printing method, apparatus, and server provided by this invention can significantly increase the amount of log information stored and optimize the log printing path. By being compatible with various formats of printf(fmt, …), it achieves efficient software development and debugging even with limited hardware storage resources.

[0027] See Figure 2 The diagram shows a method for printing log information, which mainly includes the following steps S202 to S206:

[0028] Step S202: Copy the source code file from the original directory to the temporary build directory. In one implementation, the source code file can be copied to a specific directory (such as build_tmp), where build_tmp is a temporary build directory used to store intermediate files (.o, .a, .so, executable files, etc.) generated during the compilation process.

[0029] Step S204, performing a preprocessing operation on the source code files in the temporary build directory through a preprocessing script to obtain a first log file in data segment format, and converting the first log file from data segment format to code segment format to obtain a second log file, in an embodiment, when the printf_proc preprocessing script is executed on the source files in the build_tmp directory, the preprocessing script has two functions, extracting the log file (i.e., obtaining the first log file), and format converting the log file (i.e., obtaining the second log file), wherein printf_proc is a custom preprocessing script used for formatting, extracting information, inserting debugging printing, replacing macros, generating reports, and other preprocessing operations on source files.

[0030] Step S206, compiling the second log file into an executable binary target log file through an automated compilation tool to clear the memory occupied by the log information in the data segment, and based on the target log file, printing the log information in the code segment, in an embodiment, make can be executed on the second log file to generate a target executable binary file, wherein make is an automated compilation tool that compiles source code according to the Makefile (compilation script) in the directory, and after processing, checks the compilation map file to determine whether the.rodata space has been occupied.

[0031] Therefore, the existing scheme cannot store log information in a large amount of software code under a hardware architecture in which the processor can only read from the code segment memory and cannot load-store read and write access, and the processor has a small readable and writable storage space, resulting in the inability to use common printf(), while the above-mentioned log information printing method provided by the embodiments of the present application can multiplex the.stack data segment by coding the log data to the.text code segment, without occupying additional DTCM hardware storage resources, to achieve the purpose of supporting printf log printing, thereby significantly improving the storage amount of log information and optimizing the log information printing path.

[0032] Referring to Figure 3 and Figure 4A format conversion after MPU software memory usage diagram is shown, before processing, the string in printf is placed in the.rodata data segment, the space occupied depends on the number of printf logs, due to the hardware cannot load data from DDR, thus causing unable to run normally, after processing, the.rodata data segment is 0, all printf contained strings are compiled into the.text program code segment, the processor can take value, decode and execute, increase a char pt_str[] array storage overhead, the array length depends on the length of the string contained in the single printf in the source code.

[0033] The embodiment of the application further provides an implementation of performing a preprocessing operation through a preprocessing script, and specific reference is made to (A) to (B) as follows:

[0034] (A) Through the preprocessing script, file scanning processing is performed on the source code files in the temporary construction directory to obtain a first log file in data segment format. In an implementation, all source code files participating in compiler compilation in the temporary construction directory can be searched, and the searched target source code files can be stored in a source file list. Then, the target source code files in the source file list are processed one by one to obtain log printing keywords, and the first log file is obtained according to the log printing keywords.

[0035] In actual application, all “.c” and “.cpp” files (i.e., source files written in C language) participating in compilation in the build_tmp directory are searched and saved in a source file list (for example, src_files[]), and the source files in src_files[] are processed one by one to find log printing keywords (such as printf(), printk(), pr_raw(), etc.).

[0036] (B) Through the preprocessing script, string transfer processing is performed on the first log file to transfer the first log file from data segment format to code segment format to obtain a second log file, and specific reference is made to (1) to (2) as follows:

[0037] (1) The formatting output function (i.e., printf) of the first log file is matched and processed by using a regular expression to obtain a code instruction framework. In an implementation, according to the specific printf(“any string”, arg1, arg2, …) of the printing function, the content in the printf() parentheses is matched and processed by using a regular expression, and then “any string” is matched and extracted.

[0038] (2) split the log information in the first log file into a character set constructed by single characters, and embed the character set into a code instruction framework to generate a second log file in a code segment format, in an implementation, the log information in the first log file is extracted by using a regular expression, a string array is created, and then the log information is assigned to the string array character by character to obtain the character set, in an implementation, a string array (such as char pr_str

[80] ;) is created, and "any string" is assigned to pr_str[] character by character (the purpose is to encode single character data as an immediate number into a machine instruction), finally, the printing mode based on pr_str is replaced by printf(pr_str, arg1, arg2,...), and the above steps are repeated to replace all printf("any string", arg1, arg2,...) into the form of assigning a string to pr_str[] and adding printf(pr_str, arg1, arg2,...), to generate the second log file in the code segment format.

[0039] In summary, the application can change the data compiled by default by the compiler into the.rodata into the.text segment, support the method and processing flow of printing the printf() log data without changing the original software code under the condition of limited hardware storage resources, thereby significantly improving the storage capacity of log information and optimizing the printing path of log information.

[0040] For the printing method of log information provided in the foregoing embodiments, an embodiment of the application provides a printing device of log information, referring to Figure 5 As shown in the structural schematic diagram of the printing device of log information, the device comprises the following parts:

[0041] The file acquisition module 502 copies the source code file from the original directory to the temporary build directory;

[0042] The format conversion module 504 performs a preprocessing operation on the source code file in the temporary build directory by using a preprocessing script to obtain a first log file in a data segment format, and converts the first log file from the data segment format to a code segment format to obtain a second log file;

[0043] The file compilation module 506 compiles the second log file into an executable binary target log file by using an automatic compilation tool, to clear the memory occupied by the log information in the data segment, and perform log information printing in the code segment based on the target log file.

[0044] The printing device of log information provided in the embodiment of the application can significantly improve the storage capacity of log information and optimize the printing path of log information.

[0045] In an embodiment, when performing the step of performing a preprocessing operation on the source code files in the temporary build directory through the preprocessing script to obtain the first log file in the data segment format, the format conversion module 504 is further configured to: perform file scanning processing on the source code files in the temporary build directory through the preprocessing script to obtain the first log file in the data segment format.

[0046] In an embodiment, when performing the step of performing file scanning processing on the source code files in the temporary build directory through the preprocessing script to obtain the first log file in the data segment format, the format conversion module 504 is further configured to: search for the source code files participating in the compiler compilation in the temporary build directory, and store the searched target source code files into a source file list; perform file scanning processing on the target source code files in the source file list one by one to obtain log printing keywords, and obtain the first log file according to the log printing keywords.

[0047] In an embodiment, when performing the step of converting the first log file from the data segment format to the code segment format to obtain the second log file, the format conversion module 504 is further configured to: perform string transfer processing on the first log file through the preprocessing script to transfer the first log file from the data segment format to the code segment format to obtain the second log file.

[0048] In an embodiment, when performing the step of performing string transfer processing on the first log file through the preprocessing script to transfer the first log file from the data segment format to the code segment format to obtain the second log file, the format conversion module 504 is further configured to: split the log information in the first log file into a character set constructed by single characters; and embed the character set into a code instruction framework to generate the second log file in the code segment format.

[0049] In an embodiment, before performing the step of splitting the log information in the first log file into a character set constructed by single characters, the format conversion module 504 is further configured to: perform matching processing on the formatted output function of the first log file by using a regular expression to obtain a code instruction framework.

[0050] In an embodiment, when performing the step of splitting the log information in the first log file into a character set constructed by single characters, the format conversion module 504 is further configured to: extract the log information in the first log file by using a regular expression, and create a string array; and assign the log information to the string array character by character to obtain the character set.

[0051] The device provided by the embodiments of the present application has the same implementation principle and technical effects as the foregoing method embodiments. For brevity, the part of the device embodiments not mentioned in the foregoing method embodiments can be referred to the corresponding content in the foregoing method embodiments.

[0052] The embodiments of the present application provide a server, specifically, the server includes a processor and a storage device; the storage device stores a computer program, and the computer program performs the method of any one of the above embodiments when executed by the processor.

[0053] Figure 6 The structure diagram of the server provided by the embodiments of the present application is shown. The server 100 includes a processor 60, a memory 61, a bus 62 and a communication interface 63, the processor 60, the communication interface 63 and the memory 61 are connected through the bus 62; the processor 60 is used to execute the executable modules stored in the memory 61, such as a computer program.

[0054] The memory 61 can include a high-speed random access memory (RAM) and can also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 63 (which can be wired or wireless), and the Internet, a wide area network, a local area network, a metropolitan area network, etc. can be used.

[0055] The bus 62 can be an ISA bus, a PCI bus or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For brevity, Figure 6 Only one bidirectional arrow is used in the figure, but it does not mean that there is only one bus or only one type of bus.

[0056] The memory 61 is used to store a program, and the processor 60 executes the program after receiving an execution instruction. The method executed by the device defined by the flow process disclosed in any one of the foregoing embodiments of the present application can be applied to the processor 60 or realized by the processor 60.

[0057] The processor 60 can be an integrated circuit chip with signal processing capability. In implementation, each step of the above method can be completed by integrated logic circuit of hardware in the processor 60 or by instructions in the form of software. The processor 60 described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component. Each method, step and logic block diagram disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium in the art. The storage medium is located in the memory 61, and the processor 60 reads the information in the memory 61, and combines the hardware to complete the steps of the above method.

[0058] The computer program product of the readable storage medium provided by the embodiments of the present application includes a computer readable storage medium storing program codes, and the program codes include instructions for executing the method described in the foregoing method embodiments. For specific implementation, reference can be made to the foregoing method embodiments, which will not be described here.

[0059] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the present application that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes instructions for making a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0060] Finally, it should be noted that: the above-described embodiments are only specific embodiments of the present application, which are used to illustrate the technical solutions of the present application, but not to limit them. The protection scope of the present application is not limited to this. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily think of changes to the technical solutions recorded in the foregoing embodiments within the technical range disclosed by the present application, or make equivalent replacements to some technical features. The modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A log information printing method characterized by comprising: The method comprises: copying source code files from an original directory to a temporary build directory; performing a preprocessing operation on the source code files in the temporary build directory through a preprocessing script to obtain a first log file in data segment format, and converting the first log file from data segment format to code segment format to obtain a second log file; compiling the second log file into an executable binary target log file through an automated compilation tool to clear the memory occupied by log information in the data segment, and printing log information based on the target log file in the code segment.

2. The method of claim 1, wherein, The step of performing a preprocessing operation on the source code files in the temporary build directory through a preprocessing script to obtain a first log file in data segment format comprises: performing file scanning processing on the source code files in the temporary build directory through a preprocessing script to obtain the first log file in data segment format.

3. The method of claim 2, wherein, The step of performing file scanning processing on the source code files in the temporary build directory through a preprocessing script to obtain the first log file in data segment format comprises: searching for source code files participating in compiler compilation in the temporary build directory, and storing the searched target source code files into a source file list; performing file scanning processing on the target source code files in the source file list one by one to obtain log printing keywords, and obtaining the first log file according to the log printing keywords.

4. The method of claim 1, wherein, The step of converting the first log file from data segment format to code segment format to obtain a second log file comprises: performing string transfer processing on the first log file through a preprocessing script to transfer the first log file from data segment format to code segment format to obtain the second log file.

5. The method of claim 4, wherein, The step of performing string transfer processing on the first log file through a preprocessing script to transfer the first log file from data segment format to code segment format to obtain the second log file comprises: splitting log information in the first log file into a character set constructed by single characters; embedding the character set into a code instruction framework to generate the second log file in code segment format.

6. The method of claim 5, wherein, Before the step of splitting log information in the first log file into a character set constructed by single characters, the method comprises: performing matching processing on a formatted output function of the first log file using a regular expression to obtain the code instruction framework.

7. The method of claim 5, wherein, The step of splitting log information in the first log file into a character set constructed by single characters comprises: extracting the log information in the first log file using a regular expression, and creating a string array; assigning the log information to the string array character by character to obtain the character set.

8. A log information printing apparatus characterized by comprising: The device comprises: a file acquisition module that copies source code files from an original directory to a temporary build directory; The format conversion module performs a preprocessing operation on the source code files in the temporary build directory through a preprocessing script to obtain a first log file in a data segment format, and converts the first log file from the data segment format to a code segment format to obtain a second log file; The file compiling module compiles the second log file into an executable binary target log file through an automatic compiling tool to clear the memory occupied by the log information in the data segment, and prints the log information based on the target log file.

9. A server, characterized by The computer readable storage medium stores computer executable instructions, and the computer executable instructions, when invoked and executed by a processor, cause the processor to implement the method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer executable instructions, and the computer executable instructions, when invoked and executed by a processor, cause the processor to implement the method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Log processing method, log storage method and embedded device

    CN116910000A

  • Log file generation method and device, equipment and medium

    CN118820196A