Data printing optimization method, electronic device and storage medium

By using a printing dictionary and template numbering mechanism, the problems of slow printing speed and long locking time in traditional logging methods are solved, efficient log output is achieved, and system performance is improved.

CN120162016BActive Publication Date: 2025-09-09沐曦科技(成都)有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510639926.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-19
Publication Date
2025-09-09
Estimated Expiration
2045-05-19

AI Technical Summary

Technical Problem

Traditional logging methods face problems such as slow printing speed, long locking time and complex data type conversion under high performance requirements, which can easily lead to system resource exhaustion and crash, especially in multi-process or multi-threaded environments.

Method used

A printing dictionary mechanism is adopted to obtain the mapping relationship in the printing dictionary and use the template number to transmit the printing template, which reduces the amount of data and reduces the locking time. Variables are directly transmitted to reduce data type conversion.

Benefits of technology

It improves printing speed, reduces the locking time of multi-process output data, and improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162016B_ABST
    Figure CN120162016B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of chip design, and more particularly to a data printing optimization method, electronic device, and storage medium. The method comprises obtaining a printing dictionary, wherein the printing dictionary includes N mapping relationships, each mapping relationship including a printing template and its template number; each printing template includes a preset fixed string and / or format specifier, where N is greater than 1; selecting a target printing template in the printing dictionary based on a desired printing result, and obtaining a target template number of the target printing template; configuring at least one type of printing interface based on the target template number, and when the printing interface is executed, performing the following steps: outputting the target template number to a host computer; the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and printing the fixed characters and / or variables matching the format specifier in the target printing template. The method achieves the goals of fast printing speed, short locking time, and reduced data type conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of chip design, and in particular to a data printing optimization method, electronic equipment and storage medium. Background Art

[0002] In software development, logs, as a key debugging tool, are widely used to record various runtime information, including but not limited to error tracking, status monitoring, and performance analysis. This log information is crucial for developers, providing valuable insights into software behavior, locating the root causes of problems, and optimizing system performance. However, in high-performance product development environments, traditional logging methods face numerous challenges.

[0003] First, traditional logging methods rely heavily on serial port printing technology, which is slow. As the amount of code increases, the number of log information points that need to be recorded also increases, which means that the amount of data that needs to be printed increases significantly, and printing speed becomes a bottleneck for system performance. Secondly, in a multi-process or multi-threaded environment, in order to avoid confusion and loss of log information, it is usually necessary to introduce a locking mechanism to synchronize access to log resources by different processes / threads. However, long-term locking may lead to system resource exhaustion, causing system crashes or instability. Secondly, since there are many types and data formats of log information, including but not limited to text, binary data, images, etc.; when the GPU firmware outputs logs, due to differences in hardware characteristics, complex data conversion of the log data is often required. This process is time-consuming, further exacerbating the logging problem under high-performance requirements.

[0004] Therefore, there is an urgent need for an optimization method for data output that has a fast printing speed, a short locking time, and reduces data type conversion. Summary of the Invention

[0005] In order to solve the above technical problems, the present invention adopts a technical solution: a data printing optimization method, characterized in that it is applied to a lower computer and comprises the following steps:

[0006] S100, obtaining a printing dictionary, wherein the printing dictionary includes N mapping relationships, each mapping relationship includes a printing template and its template number; each printing template includes a preset fixed character string and / or format specifier, wherein N is greater than 1.

[0007] S200 , selecting a target printing template in the printing dictionary according to a desired printing result, and obtaining a target template number of the target printing template.

[0008] S300, configure at least one type of printing interface according to the target template number, and when the printing interface is executed, implement the following steps: output the target template number to the host computer; the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and print the fixed characters and / or variables matching the format specifier in the target printing template.

[0009] In addition, the present invention also provides a non-transitory computer-readable storage medium, which stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the above method.

[0010] In addition, the present invention also provides an electronic device including a processor and the above-mentioned non-transitory computer-readable storage medium.

[0011] The present invention has at least the following beneficial effects:

[0012] The present invention provides a data printing optimization method. A lower computer obtains a print template and its template number from a print dictionary based on the desired print result, then transmits the template number to a higher computer via a print interface. The template number triggers the higher computer to query the print dictionary, obtain the print template, and then print according to the print template. During this process, the data transmitted by the print interface is the template number, not the print template. The template number is much smaller than the print template. This not only reduces the amount of data transmitted and increases printing speed, but also shortens the duration of multi-process output data locking, improving performance. Variables are also transmitted directly through the print interface, reducing data conversion and further increasing printing speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0014] Figure 1 A flow chart of a data printing optimization method provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0015] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 those skilled in the art without making any creative efforts shall fall within the scope of protection of the present invention.

[0016] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present invention have the same meanings as commonly understood by those skilled in the art.

[0017] See also Figure 1 , which shows a flow chart of a data printing optimization method, applied to a lower computer, the method includes the following steps:

[0018] S100, obtaining a printing dictionary, wherein the printing dictionary includes N mapping relationships, each mapping relationship includes a printing template and its template number; each printing template includes a preset fixed character string and / or format specifier, wherein N is greater than 1.

[0019] In one embodiment, the lower computer is a graphics processing unit (GPU), a tensor processing unit (TPU), or a neural processing unit (NPU). Other types of processors for executing instructions issued by the upper computer and printing results fall within the scope of protection of the present invention.

[0020] Among them, the upper computer is a central processing unit (CPU), and other types of processors for issuing instructions to the lower computer and outputting printing results all fall within the protection scope of the present invention.

[0021] The print dictionary is used to store log character strings and formats, and needs to be queried when calling the print interface in the lower computer and parsing the data transmitted by the print interface in the upper computer.

[0022] Among them, the print template is a preset template of the expected printing result. As an example, the print template with template number "517" in the print dictionary is "msg_id:%u,msg:0x%x,arg:0x%x". Among them, "%u" and "%x" are different types of format specifiers, respectively, and the print template is a mixture of fixed strings and format specifiers. The print template with template number "512" in the print dictionary is "read!=write, bad flash or not exist, switch tobackup", and the print template is a fixed string. The print template with template number "257" in the print dictionary is "%c %c", and the print template is a format specifier. It should be noted that a print template may include multiple fixed strings and / or format specifiers.

[0023] The fixed character string is the fixed character that needs to be output in the print template.

[0024] The format specifier indicates how to format subsequent parameters. To correctly print the value of the actual variable corresponding to the format specifier, you need to define a variable type that matches the format specifier and pass the variable type as a parameter to the printing interface. In this printing template, the fixed string remains unchanged; only the parameter formatted by the format specifier is variable.

[0025] The template number is the unique identification number of the print template, which can also be called the unique index number. No matter how much data the print template contains, the data volume of the template number is fixed, and the data volume of the template number is much smaller than that of the print template.

[0026] In one embodiment, the template number has a data size of two bytes. When there are relatively few print templates in the print dictionary, the template number may be preset to have a data size of one byte. When there are relatively many print templates in the print dictionary, the template number may be preset to have a data size of three bytes, etc. The size of the template number may be configured based on actual circumstances. Template numbers with preset byte sizes of other sizes also fall within the scope of protection of the present invention.

[0027] S200 , selecting a target printing template in the printing dictionary according to a desired printing result, and obtaining a target template number of the target printing template.

[0028] It should be noted that when programming, programmers need to configure the corresponding printing function and the expected printing results according to their needs. For example, during debugging, they can print the values ​​of key variables, print corresponding log information, or display operation results, error prompts, and other information to the user.

[0029] S300, configure at least one type of printing interface according to the target template number, and when the printing interface is executed, implement the following steps: output the target template number to the host computer; the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and print the fixed characters and / or variables matching the format specifier in the target printing template.

[0030] The print interface is also called a print function, which is used to transmit the target template number, variable quantity and variables to the host computer, and display the variables corresponding to the fixed string and / or format specifier preset in the print template on the screen.

[0031] Among them, the printing interface is configured by the programmer during the programming process.

[0032] Different types of print interfaces are used to print data of different data types. In one embodiment, the type of the print interface is a basic integer-type print interface for printing integer data, or a basic character-type print interface for printing character data. Print interfaces for printing other data types also fall within the scope of protection of the present invention.

[0033] In one embodiment, the target template number is output to a host computer via a physical interface. In one embodiment, the physical interface is a serial interface or other interface accessible to the host computer. A serial interface is an interface for serial communication. Serial communication sends and receives bytes bit by bit, i.e., data is transmitted sequentially, one bit at a time.

[0034] In another embodiment, the target template number is saved in a memory accessible to a host computer.

[0035] It should be noted that the template number is transmitted through the printing interface, and the host computer obtains the printing template corresponding to the template number by querying the printing dictionary. This method can reduce the amount of data transmitted and greatly improve the printing speed. On the other hand, since the template number is transmitted, the thread or the template number is locked when locking. This not only reduces the hardware data consumed during locking, but also greatly reduces the locking time due to the faster printing speed. In addition, variables can be directly transmitted in the printing interface, and there is no need to convert the variable type into a string for output as in traditional printing methods, which reduces data type conversion and further improves printing speed.

[0036] In one embodiment, the type of the printing interface in S300 further includes: configuring a basic integer type printing interface: S310, configuring the entry parameters of the basic integer type printing interface to be a target template number, a variable number m1, and an integer variable that matches a format specifier. When the basic integer type printing interface is executed, the following steps are implemented: outputting the target template number to the host computer via the serial port, and outputting all integer variables to the host computer in sequence; wherein the target template number is used to trigger the host computer to query the printing dictionary to obtain a target printing template, and merge all integer variables according to the format of the target printing template, restore the desired printing result, and print the restored printing result; wherein m1 is greater than or equal to 0. In one embodiment, when a format specifier exists in the printing template indexed by the target template number of the printing interface, the value of m1 is greater than 0, and the final printed result contains the value of the variable. In another embodiment, when a format specifier does not exist in the printing template indexed by the target template number of the printing interface, that is, when the printing template is plain text, m1 is equal to 0, and the obtained printed result is plain text. That is, the basic integer class printing interface can print the desired output as pure text or a mixed result of text and variables.

[0037] When the first data type of a variable in the desired print result does not match the second data type of the variable in the basic integer printing interface, an extended interface is required to assist in data transmission. Other types of printing interfaces also fall within the scope of protection of this invention. The mismatch between the first and second data types includes a mismatch between the data types themselves and a mismatch between the lengths of the data types.

[0038] In one embodiment, for a data type length mismatch, S300 further includes, S320: obtaining a first data type of a variable in the desired print result and a second data type of a variable in a basic integer printing interface. When the first data type is the same as the second data type but the length of the first data type is greater than the length of the second data type, outputting only the target template number to a host computer via the basic integer printing interface and outputting the variable of the second data type in conjunction with the length extension interface. The input parameters of the length extension interface are the number of variables m3 and an integer variable that matches the format specifier of the second data type, and the value of m3 is greater than 0. The length extension interface is used to print the variable of the second data type.

[0039] As an example, the first integer data is 64-bit unsigned integer data, and the second integer data is 32-bit unsigned integer data.

[0040] In one embodiment, for the case where the data type itself does not match, S300 also includes, S330: respectively obtaining the first data type of the variable in the expected print result and the second data type of the variable in the basic integer class printing interface, when the first data type is different from the second data type, only outputting the target template number to the host computer through the basic integer class printing interface, and cooperating with the type extension interface to output the variable of the second data type; wherein, the input parameters of the type extension interface are the number of variables m3 and the variables matching the format specifier of the second data type, and the value of m3 is greater than 0.

[0041] As an example, the first integer data is 32-bit single-precision floating-point data or double-precision floating-point data, and the second integer data is 32-bit unsigned integer data.

[0042] The basic integer printing interface, combined with the length extension interface or type extension interface, can output more types of data.

[0043] In addition to the printing interface for integer data, the embodiment of the present invention also provides a printing interface for characters.

[0044] In one embodiment, the type of printing interface in S300 further includes: configuring a basic character class printing interface: S301, configuring the entry parameters of the basic character class printing interface to be a string length m2 and a string variable matching the format specifier. When the basic character class printing interface is executed, the following steps are implemented: when a target printing template that outputs m2 characters exists in the printing dictionary, calling the basic integer class printing interface, whose parameters are respectively configured as the template number of the target printing template, m2, and the string variable; otherwise, cyclically calling the basic integer class printing interface to print the string word by word. The basic character class printing interface enables the system to print character variables according to the printing dictionary.

[0045] In one embodiment, S100 further includes: adding a new printing template and its template number to the printing dictionary to obtain an updated printing dictionary. Updating the printing dictionary in a timely manner according to actual conditions can make the printing dictionary more complete and better utilized.

[0046] In another embodiment, the mapping relationship in the print dictionary may also be deleted.

[0047] In summary, the present invention provides a method for optimizing data printing. A lower computer obtains a print template and its template number from a print dictionary based on the desired print result, and transmits the template number to a higher computer via a print interface. The template number triggers the higher computer to query the print dictionary to obtain the print template, and then print according to the print template. During this process, the data transmitted by the print interface is the template number rather than the print template. The data size of the template number is much smaller than that of the print template. This not only reduces the amount of data transmitted and increases printing speed, but also reduces the duration of multi-process output data locking, thereby improving performance. Variables are also directly transmitted through the print interface, reducing data conversion and further increasing printing speed.

[0048] An embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.

[0049] An embodiment of the present invention further provides an electronic device including a processor and the aforementioned non-transitory computer-readable storage medium.

[0050] An embodiment of the present invention further provides a computer program product comprising program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.

[0051] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0052] Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It should also be understood by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.

Claims

1. A data printing optimization method, characterized in that: Applied to the lower computer, the method includes the following steps: S100, obtaining a printing dictionary, wherein the printing dictionary includes N mapping relationships, each mapping relationship includes a printing template and its template number; each printing template includes a preset fixed string and / or format specifier of a log, wherein N is greater than 1; S200, selecting a target printing template in the printing dictionary according to a desired log printing result, and obtaining a target template number of the target printing template; S300, configure at least one type of printing interface according to the target template number, and when the printing interface is executed, implement the following steps: output the target template number, the number of variables and the variables to the host computer, wherein the variables are output to the host computer in sequence; the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and print the variables that match the fixed characters and / or format specifiers of the log in the target printing template, so that the fixed characters and / or format specifiers of the log in the target printing template are displayed on the screen.

2. The method according to claim 1, characterized in that The types of printing interfaces in S300 also include: configuring basic integer printing interfaces: S310, configure the entry parameters of the basic integer class printing interface as the target template number, the number of variables m1 and the integer variables matching the format specifier. When the basic integer printing interface is executed, implement the following steps: output the target template number to the host computer through the serial port, and output all integer variables to the host computer in sequence; wherein, the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and merge all integer variables according to the format of the target printing template, restore the expected printing result, and print the restored printing result; wherein, m1 is greater than or equal to 0.

3. The method according to claim 2, characterized in that S300 also includes, S320: respectively obtaining the first data type of the variable in the expected print result and the second data type of the variable in the basic integer class printing interface; when the first data type is the same as the second data type, but the length of the first data type is greater than the length of the second data type, only outputting the target template number to the host computer through the basic integer class printing interface, and outputting the variable of the second data type in conjunction with the length extension interface; wherein, the input parameters of the length extension interface are the number of variables m3 and the integer variable matching the format specifier of the second data type, and the value of m3 is greater than 0.

4. The method according to claim 2, characterized in that S300 also includes, S330: respectively obtaining the first data type of the variable in the expected print result and the second data type of the variable in the basic integer class printing interface; when the first data type is different from the second data type, only outputting the target template number to the host computer through the basic integer class printing interface, and cooperating with the type extension interface to output the variable of the second data type; wherein, the input parameters of the type extension interface are the number of variables m3 and the variables matching the format specifier of the second data type, and the value of m3 is greater than 0.

5. The method according to claim 2, characterized in that The types of printing interfaces in S300 also include: configuring basic character printing interfaces: S301, configure the entry parameters of the basic character class printing interface as the string length m2 and the string variable matching the format specifier. When the basic character class printing interface is executed, implement the following steps: when there is a target printing template that outputs m2 characters in the printing dictionary, call the basic integer class printing interface, and its parameters are respectively configured as the template number of the target printing template, m2 and the string variable; otherwise, call the basic integer class printing interface in a loop to print the string word by word.

6. The method according to claim 1, characterized in that S100 further includes: adding a new printing template and its template number to the printing dictionary to obtain an updated printing dictionary.

7. The method according to claim 1, characterized in that The data size of the template number is two bytes.

8. The method according to claim 1, characterized in that The target template number is output to the host computer via the serial interface.

9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by a processor to implement the method according to any one of claims 1 to 8.

10. An electronic device, characterized in that: The device comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.

Citation Information

Patent Citations

  • Data printing method and system

    CN103955345A

  • Cloud printing method, device and system and cloud printer

    CN111488130A

  • Log printing method and device, electronic equipment and computer readable storage medium

    CN115220668A