Data printing optimization method, electronic equipment and storage medium

By obtaining the printing dictionary in the lower computer and transmitting the template number to achieve efficient logging, the problems of slow printing speed, long locking time and long data type conversion in traditional logging methods are solved, and the system performance and printing speed are improved.

CN120162016AActive Publication Date: 2025-06-17沐曦科技(成都)有限公司
View PDF 11 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Traditional logging methods face the problems of slow printing speed, long locking time and long data type conversion in product development environments with high performance requirements.

Method used

By obtaining the printing dictionary in the lower computer, selecting the target printing template and obtaining its template number, using the printing interface to transmit the template number to the upper computer, triggering the upper computer to query the printing dictionary and print it. This method reduces the amount of data transmitted and locking time, and directly transmits variables to reduce data conversion.

Benefits of technology

Improves printing speed, reduces the time for multi-process output data locking, improves system performance, and reduces data conversion time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162016A_ABST
    Figure CN120162016A_ABST
Patent Text Reader

Abstract

The invention relates to the field of chip design, in particular to a data printing optimization method, electronic equipment and a storage medium, a printing dictionary is obtained, the printing dictionary comprises N mapping relations, and each mapping relation comprises a printing template and a template number thereof; each printing template comprises a preset fixed character string and / or a format descriptor, and N is greater than 1; selecting a target printing template in the printing dictionary according to an expected printing result, and obtaining a target template number of the target printing template; at least one type of printing interface is configured according to the target template number, and when the printing interface is executed, the following steps are realized: outputting the target template number to an upper computer; the target template number is used for triggering the upper computer to query the printing dictionary to obtain the target printing template, and printing the fixed characters and / or variables matched with the format descriptor in the target printing template. The purposes of being high in printing speed, short in locking time and capable of reducing data type conversion are achieved.
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 particularly to an optimization method for data printing, an electronic device, and a storage medium. Background Art

[0002] In the field of software development, logs are widely used as a key debugging tool for recording various information during software operation, including but not limited to error tracking, status monitoring, and performance analysis. These log messages are crucial for developers as they provide valuable clues for deeply understanding software behavior, locating the root causes of problems, and optimizing system performance. However, in a product development environment with high-performance requirements, traditional logging methods face numerous challenges.

[0003] Firstly, traditional logging methods mostly rely on serial port printing technology, and the speed of serial port printing is slow. As the code volume increases, the number of log information points to be recorded also increases accordingly, that is, the amount of data to be printed increases significantly, and the printing speed becomes a bottleneck of system performance. Secondly, in a multi-process or multi-thread environment, in order to avoid confusion and loss of log information, a lock mechanism is usually introduced to synchronize the access of different processes / threads to log resources. However, long-term locking may lead to exhaustion of system resources, causing system crashes or instability. Secondly, due to the variety of 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 hardware characteristic differences, complex data conversion often needs to be performed on the log data, and this process takes a long time, further exacerbating the logging problem under high-performance requirements.

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

[0005] In view of the above technical problems, the technical solution adopted by the present invention is: an optimization method for data printing, characterized in that it is applied to a lower computer, and the method includes the following steps: S100, obtain a printing dictionary, where 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, where N is greater than 1.

[0006] S200, select a target printing template from the printing dictionary according to the expected printing result, and obtain the target template number of the target printing template.

[0007] S300 configures at least one type of printing interface according to the target template number. When the printing interface is executed, the following steps are implemented: 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.

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

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

[0010] The present invention has at least the following beneficial effects: An optimized method for data printing provided by the present invention. The lower computer obtains the printing template and its template number in the printing dictionary according to the expected printing result, and transmits the template number to the host computer through the printing interface. The template number triggers the host computer to query the printing dictionary to obtain the printing template and perform printing according to the printing template. In this process, the data transmitted by the printing interface is the template number rather than the printing template. The data volume of the template number is much smaller than that of the printing template, which not only reduces the transmitted data volume, improves the printing speed, but also reduces the locking duration of multi-process output data, improving the performance. It also directly transmits variables through the printing interface, reducing data conversion and further improving the printing speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0012] Figure 1 It is a flowchart of an optimized method for data printing provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0013] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

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

[0015] Please refer to Figure 1 , which shows a flowchart of an optimized method for data printing, applied to a lower computer. The method includes the following steps: S100, obtain a print dictionary, where the print dictionary includes N mapping relationships, and each mapping relationship includes a print template and its template number; each of the print templates includes a preset fixed string and / or format specifier, where N is greater than 1.

[0016] In one implementation, 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 protection scope of the present invention.

[0017] 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 fall within the protection scope of the present invention.

[0018] Among them, the print dictionary is used to store log strings and formats. The print dictionary needs to be queried both when the print interface is called in the lower computer and when the upper computer parses the data transmitted by the print interface.

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

[0020] Among them, the fixed string is the fixed character that needs to be output in the print template.

[0021] Among them, format specifiers are used to indicate how to format subsequent arguments. To correctly print the value of the actual variable corresponding to the format specifier, it is necessary to define a variable type that matches the format specifier and pass the variable type as an argument to the printing interface. In this printing template, the fixed string is invariant, and only the arguments formatted by the format specifier are variable outputs.

[0022] Among them, the template number is the unique identification number of the printing template, and can also be called the unique index number. Regardless of the amount of data contained in the printing template, the amount of data of its template number is fixed, and the amount of data of the template number is much smaller than that of the printing template.

[0023] In one implementation, the amount of data of the template number is two bytes. When there are few printing templates in the printing dictionary, the amount of data of the template number can also be preset to one byte. When there are many printing templates in the printing dictionary, the amount of data of the template number can also be preset to three bytes, etc. The size of the template number can be configured according to the actual situation. The template numbers with other preset byte sizes also fall within the protection scope of the present invention.

[0024] S200, select a target printing template from the printing dictionary according to the desired printing result, and obtain the target template number of the target printing template.

[0025] It should be noted that when a programmer is programming, it is necessary to configure the corresponding printing function and the desired printing result according to the requirements. For example, during debugging, print the values of key variables, or print the corresponding log information, or display operation results, error prompts and other information to the user.

[0026] S300, configure at least one type of printing interface according to the target template number. When the printing interface is executed, the following steps are implemented: 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.

[0027] Among them, the printing interface is also called a printing function, which is used to transfer the target template number, the number of variables and the variables to the host computer, and display the fixed string preset in the printing template and / or the variables corresponding to the format specifier on the screen.

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

[0029] Among them, different types of printing interfaces are used to print data of different data types. In one implementation, the type of the printing interface is a basic integer class printing interface for printing integer data, or a basic character class printing interface for printing character data. Printing interfaces for printing other data types also fall within the protection scope of the present invention.

[0030] In one implementation, the target template number is output to the host computer through a physical interface. In one implementation, the physical interface is a serial interface (Serial Interface) or other interfaces that can be accessed by the host computer. The serial interface is an interface for serial communication, and serial communication sends and receives bytes bit by bit, that is, data is transmitted sequentially one bit at a time.

[0031] In another implementation, the target template number is saved to a memory that can be accessed by the host computer.

[0032] It should be noted that by transmitting the template number through the printing interface, the host computer obtains the printing template corresponding to the template number by querying the printing dictionary. In this way, the amount of data transmitted can be reduced, and the printing speed can be greatly improved. On the other hand, since the template number is transmitted, when its thread or operation is locked, the template number is locked. This not only reduces the hardware resources consumed during locking, but also greatly reduces the locking duration due to the increased printing speed. In addition, variables can be directly transmitted in the printing interface, and there is no need to convert the type of the variable into a string for output like in the traditional printing method, reducing data type conversion and further improving the printing speed.

[0033] In one embodiment, the types of the printing interfaces in S300 further include: configuring a basic integer type printing interface: S310, configuring the input parameters of the basic integer type printing interface as a target template number, the number of variables m1, and integer variables matching the 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 through the serial port, and sequentially outputting all the integer variables to the host computer in order; wherein, the target template number is used to trigger the host computer to query the printing dictionary to obtain the target printing template, and fuse all the integer variables according to the format of the target printing template to restore the desired printing result, and print the restored printing result; wherein, m1 is greater than or equal to 0. In one embodiment, when there is a format specifier in the printing template indexed by the target template number of the printing interface, the value of m1 is greater than 0, and there are variable values in the finally obtained printing result. In another embodiment, when there is no format specifier 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 printing result is plain text. That is, this basic integer type printing interface can print both the desired plain text output and the mixed result of text and variables.

[0034] When the first data type of the variable in the desired printing result does not match the second data type of the variable in the basic integer type printing interface, it is necessary to assist in transmitting data through the extended interface, and other types of printing interfaces also fall within the protection scope of the present invention. The mismatch between the first data type and the second data type includes the mismatch of the data type itself and the mismatch of the length of the data type.

[0035] In one embodiment, for the case of the mismatch of the length of the data type, S300 further includes S320: respectively obtaining the first data type of the variable in the desired printing result and the second data type of the variable in the basic integer type 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 output the target template number to the host computer through the basic integer type printing interface, and cooperate with the length extension interface to output the variable of the second data type; wherein, the input parameters of the length extension interface are the number of variables m3 and integer variables matching 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.

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

[0037] In one implementation, for the case where the data types themselves do not match, S300 further 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 print interface. When the first data type is different from the second data type, only output the target template number to the host computer through the basic integer class print interface, and output the variable of the second data type in cooperation with the type extension interface; wherein, the input parameters of the type extension interface are the number of variables m3 and the variable matching the format specifier of the second data type, and the value of m3 is greater than 0.

[0038] 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.

[0039] The basic integer class print interface cooperates with the length extension interface or the type extension interface to be able to output more types of data.

[0040] In addition to the print interface for integer data types, the embodiments of the present invention also provide a print interface for characters.

[0041] In one implementation, the types of print interfaces in S300 further include: configuring a basic character class print interface: S301, configuring the input parameters of the basic character class print interface as the string length m2 and the string variable matching the format specifier. When the basic character class print interface is executed, the following steps are implemented: when there is a target print template for outputting m2 characters in the print dictionary, then call the basic integer class print interface, and its parameters are respectively configured as the template number of the target print template, m2, and the string variable; otherwise, loop through the basic integer class print interface to print the string character by character. The basic character class print interface enables the system to print character variables according to the print dictionary.

[0042] In one implementation, S100 further includes: adding a new print template and its template number to the print dictionary to obtain an updated print dictionary. Timely updating the print dictionary according to the actual situation can make the print dictionary more perfect and better utilized.

[0043] In another implementation, the mapping relationship in the print dictionary can also be deleted.

[0044] In summary, for an optimization method of data printing provided by the present invention, the lower computer obtains a printing template and its template number in a printing dictionary according to an expected printing result, and transmits the template number to the upper computer through a printing interface. The template number triggers the upper computer to query the printing dictionary to obtain the printing template and perform printing according to the printing template. In this process, the data transmitted by the printing interface is the template number rather than the printing template. The data volume of the template number is much smaller than that of the printing template, which not only reduces the transmitted data volume, improves the printing speed, but also reduces the duration of locking for multi-process output data, improving the performance. Variables are directly transmitted through the printing interface, reducing data conversion and further improving the printing speed.

[0045] An embodiment of the present invention further 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 segment of a program related to a method for implementing a method in a method embodiment. The at least one instruction or the at least one segment of the program is loaded and executed by the processor to implement the method provided in the above embodiment.

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

[0047] An embodiment of the present invention further provides a computer program product, which includes program code. When the program product runs on an electronic device, the program code is used to cause the electronic device to execute the steps in the methods according to various exemplary embodiments of the present invention described above in this specification.

[0048] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example. In practical applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.

[0049] Although some specific embodiments of the present invention have been described in detail by way of examples, those skilled in the art should understand that the above examples are only for illustration and not for limiting the scope of the present invention. Those skilled in the art should also understand that various modifications can be made to the embodiments without departing from the scope and spirit of the present invention. The scope disclosed by 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 comprises 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, wherein N is greater than 1; 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; S300, configuring at least one type of printing interface according to the target template number, and when the printing interface is executed, implementing 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 print the fixed characters in the target printing template and / or the variables matching the format specifier.

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 printing 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 an 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 printing result and the second data type of the variable in the basic integer class printing interface, and 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 1, 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 also 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 the processor to implement the method according to any one of claims 1 to 8.

10. An electronic device, characterized in that: The invention 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

  • Printing format setting method and system

    CN108062210A

  • General printing template metadata design method

    CN108733332A

  • Printing method and printing device based on editable template and storage medium

    CN111026338A

  • Cloud printing method, device and system and cloud printer

    CN111488130A