A Code-Oriented Application Performance Analysis Method and System
By adding tags to the front and back ends of the compiler and generating an execution process information output file, the accuracy of code performance analysis on platforms with limited computing capabilities is solved, and the precise analysis of recursive calls and inline functions is realized, which improves the accuracy and compatibility of performance analysis.
Patent Information
- Application Number
- CN202210569917.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-24
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-05-24
AI Technical Summary
The existing technology is difficult to improve the accuracy of code performance analysis on computer platforms with limited computing capabilities, especially on domestic Linux operating systems, which cannot effectively analyze the performance problems of recursive calls and inline functions.
The source code of the target application is compiled into performance test-specific object code through preset compilation options, and tags are added to the compiler front-end and back-end to generate execution process information output files, statistical variables, functions and assembly instructions information, and generate performance analysis results.
It realizes precise performance analysis of recursive calls and inline functions, improves the accuracy and compatibility of performance analysis, and is suitable for any target application.
Smart Images

Figure CN114968779B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of code performance analysis of programs, and particularly relates to a method and system for analyzing the performance of application programs oriented to code. Background Art
[0002] Currently, for computer platforms with limited computing power, it is difficult to improve the accuracy of code performance analysis. For example, on domestic Linux operating systems, based on an integrated development environment, through performance analysis, code performance analysis at different levels and multi-granularity is achieved, performance bottlenecks are found, the reasons for performance problems are identified, and the integrity of performance analysis is improved. However, due to limited computing power, there are difficulties. The existing performance analysis tool gprof for application programs can only analyze the number of calls to each function in the code, the processor time consumed by each function, etc. For a recursively called function, its execution time does not include the actual execution time of its sub-functions. Therefore, it is not suitable for analyzing programs with a large number of recursive calls and cannot handle inline functions either. Summary of the Invention
[0003] The technical problem to be solved by the present invention: In view of the above problems of the prior art, a method and system for analyzing the performance of application programs oriented to code are provided. The present invention can accurately analyze the code performance based on the source code of the application program, improve the accuracy of performance analysis, be applicable to various recursively called or inline functions, have good compatibility, and can perform application program performance analysis for any target application program.
[0004] To solve the above technical problems, the technical solution adopted by the present invention is as follows:
[0005] A method for analyzing the performance of application programs oriented to code, comprising:
[0006] 1) For the target application program to be tested, compile the source code of the target application program into corresponding target code dedicated for performance testing through preset compilation options, and the target code dedicated for performance testing has the function of outputting execution process information to a specified output file;
[0007] 2) Run the target code dedicated for performance testing, and for the specified output file obtained by running the target code dedicated for performance testing, count the execution process information in the output file, so as to obtain the performance analysis result of the target application program.
[0008] Optionally, outputting the execution process information to a specified output file specifically means outputting the information of variables, functions, and assembly instructions executed during the execution process to the specified output file, and the information of variables includes the names of global variables and local variables, and the information of functions includes the name of the function, the position of the function entry, and the position of the function end.
[0009] Optionally, when compiling the source code of the target application into the corresponding target code dedicated for performance testing through preset compilation options in step 1), it includes, at the front end of the compiler, identifying variables and functions in the source code, determining the types of variables as global variables or local variables, determining the function entry and the position of the end of the function, and adding marks to each variable, function, its function entry, and the end of the function according to set rules, where the marks are used to output the information of the corresponding variable, function, function entry, or the end of the function as execution process information to a specified output file when the target code dedicated for performance testing is executed.
[0010] Optionally, when adding marks to each variable, function, its function entry, and the end of the function according to set rules, it includes using local variable marks to label local variables, using global variable marks to label global variables, using function marks to label functions, using function entry marks to label the function entries of functions, and using function end marks to label the ends of functions.
[0011] Optionally, after adding marks to each variable, function, its function entry, and the end of the function according to set rules, it further includes a step of performing syntax and lexical checks on the added marks. If the added marks conform to the syntax rules, continue to execute downward; otherwise, correct the keywords that do not conform to the rules and then execute downward.
[0012] Optionally, when compiling the source code of the target application into the corresponding target code dedicated for performance testing through preset compilation options in step 1), it further includes, at the back end of the compiler, adding marks to all or specified partial assembly instructions, and adding a mark garbage collection function module to the target code dedicated for performance testing. The mark garbage collection function module is used to count the marks of each variable, function, function entry, the end of the function, and the assembly instructions respectively, so as to count the memory usage size of variables, the usage times of variables, the start and end running times of functions, and the usage times of assembly instructions, and after the counting is completed, regard the marks as garbage for recycling to reduce the memory usage.
[0013] Optionally, the output file obtained by running the target code dedicated for performance testing in step 2) records the memory usage size of each variable, the usage times of variables, the start and end running times of functions, and the usage times of assembly instructions.
[0014] Optionally, when counting the execution process information in the output file in step 2), it also includes calculating the running time of each function respectively, and the proportion of the running time occupying the total running time of the performance test dedicated target code. Generate a function index file for all functions, function entrances, and function endings, and generate the function call relationship between different functions according to the function index file to add to the performance analysis result of the target application. The running time of the function is the difference between the start and end running times of the function.
[0015] In addition, the present invention also provides an application program performance analysis system for code, including a microprocessor and a memory connected to each other. The microprocessor is programmed or configured to execute the steps of the foregoing application program performance analysis method for code.
[0016] In addition, the present invention also provides a computer-readable storage medium. A computer program is stored in the computer-readable storage medium, and the computer program is used to be programmed or configured by a microprocessor to execute the steps of the foregoing application program performance analysis method for code.
[0017] Compared with the prior art, the present invention has the following advantages:
[0018] 1. The present invention compiles the source code of the target application program into the corresponding performance test dedicated target code through preset compilation options. The performance test dedicated target code has the function of outputting the execution process information to a specified output file. The performance analysis result of the target application program can be obtained by counting the execution process information in the output file, which can solve the problem of accurately analyzing the code performance based on the application program source code, improve the performance analysis accuracy, and can be applied to various recursively called or inlined functions.
[0019] 2. The present invention realizes the performance analysis of the target application program based on the performance test dedicated target code having the execution process information. The execution process information can include code analysis from multiple horizontal levels such as variables, functions, assembly instructions, and code lines, providing support for software code tuning and improving the performance analysis accuracy.
[0020] 3. The present invention is compiled into the corresponding performance test dedicated target code through preset compilation options, without involving the modification of the target application program, and has good compatibility, and can realize the application program performance analysis for any target application program. Brief Description of the Drawings
[0021] Figure 1 It is a schematic diagram of the basic process of the method in the embodiment of the present invention.
[0022] Figure 2 It is a schematic diagram of the function improvement of the compiler in the embodiment of the present invention. Detailed Embodiment
[0023] As Figure 1 shown, the method for analyzing the performance of a code-oriented application in this embodiment includes:
[0024] 1) For the target application to be tested, compile the source code of the target application into corresponding target code dedicated for performance testing through preset compilation options, and the target code dedicated for performance testing has the function of outputting execution process information to a specified output file;
[0025] 2) Run the target code dedicated for performance testing, and for the specified output file obtained by running the target code dedicated for performance testing, count the execution process information in the output file, so as to obtain the performance analysis result of the target application.
[0026] The present invention realizes the performance analysis of the target application based on the fact that the target code dedicated for performance testing has the execution process information. The execution process information can include code analysis at multiple horizontal levels such as variables, functions, assembly instructions, and code lines, providing support for software code tuning and improving the accuracy of performance analysis. As an alternative implementation, in this embodiment, outputting the execution process information to a specified output file specifically means outputting the information of variables, functions, and assembly instructions executed during the execution process to the specified output file, and the information of variables includes the names of global variables and local variables, and the information of functions includes the name of the function, the function entry, and the position of the function end, that is, mainly performing performance analysis at multiple horizontal levels of variables, functions, and assembly instructions, providing support for software code tuning and improving the accuracy of performance analysis.
[0027] In this embodiment, when compiling the source code of the target application into corresponding target code dedicated for performance testing through preset compilation options in step 1), it includes identifying variables and functions in the source code at the front end of the compiler, determining the type of variables as global variables or local variables, and determining the function entry and the position of the function end of the function, and adding marks to each variable, function, its function entry, and function end respectively according to set rules, and the marks are used to output the information of the corresponding variable, function, function entry, or function end as execution process information to a specified output file when the target code dedicated for performance testing is executed. As Figure 2 shown, at the front end of the compiler, the marks added to each variable, function, its function entry, and function end are variable marks, function marks, function entry marks, and function end marks respectively.
[0028] It should be noted that the preset compilation options can be specified manually according to needs. Only when the compilation with the above preset compilation options is enabled will the marking operations of variables and functions, the marking of assembly instructions mentioned below, and the operation of adding a marking garbage collection function module be executed. If the compilation with the above preset compilation options is not enabled, the compiler will perform normal compilation operations to compile the target application to be tested into target code that can be executed normally.
[0029] It should be noted that the rules for adding marks can be formulated manually according to needs. For example, as an optional implementation method, in this embodiment, when adding marks to each variable, function, its function entry, and function end according to the set rules, it includes using the local variable mark lx to mark local variables, using the global variable mark gx to mark global variables, using the function mark fx to mark functions, using the function entry mark sx to mark the function entry of the function, and using the function end mark tx to mark the function end of the function. Undoubtedly, other marks can also be used as long as they can achieve differentiation and do not affect compilation.
[0030] In this embodiment, after adding marks to each variable, function, its function entry, and function end according to the set rules, it further includes the step of performing syntax and lexical checks on the added marks. If the added marks conform to the syntax rules, continue to execute downward; otherwise, correct the keywords that do not conform to the rules and then execute downward, so as to ensure that the conversion can be completed normally and ensure the smooth progress of the marked compilation. Among them, the syntax and lexical checks are related to the specific language used in the source code. The syntax and lexical check rules for different languages are different, and the syntax and lexical checks are also routine operations of the compiler. This embodiment only involves the application of existing syntax and lexical checks and the simple processing of correcting keywords that do not conform to the rules. The detailed implementation details are not elaborated here.
[0031] In this embodiment, when compiling into the corresponding target code dedicated for performance testing through preset compilation options in step 1), it further includes adding marks to all or specified partial assembly instructions at the backend of the compiler, and adding a mark garbage collection function module to the target code dedicated for performance testing. The mark garbage collection function module is used to respectively count the marks of each variable, function, function entry, function end, and assembly instruction, so as to count the memory usage size of the variable, the usage times of the variable, the start and end running times of the function, and the usage times of the assembly instruction, and regard the marks as garbage for recycling after the counting is completed to reduce the memory usage. The mark garbage collection function module runs as an independent thread in the target code dedicated for performance testing, respectively counts the marks of each variable, function, function entry, function end, and assembly instruction, so as to count the memory usage size of the variable, the usage times of the variable, the start and end running times of the function, and the usage times of the assembly instruction, and outputs the statistical information to a specified output file, and regards the marks as garbage for recycling after the counting is completed to reduce the memory usage. Since the marks are additional content added to the application program itself during compilation, a part of memory usage will be consumed during execution. Therefore, this embodiment adopts the method of embedding the mark garbage collection function module into the application program (the target code dedicated for performance testing), so that the memory usage situation can be obtained more accurately, and the memory usage can be reduced by regarding the marks as garbage for recycling after the counting is completed, thus making the statistics more accurate, especially suitable for the performance testing of large application programs. As Figure 2 shown, at the backend of the compiler, the marks added to the assembly instructions are assembly instruction marks, and the added mark garbage collection function module is also included.
[0032] It should be noted that the method of this embodiment does not depend on the source code programming language of a specific application program and the type of compiler used. As a specific implementation manner, in this embodiment, the source code programming language of the application program is C / C++, and the compiler is an improvement based on the open-source GCC / LLVM to implement the relevant mark functions and the mark garbage collection function module.
[0033] In this embodiment, in the output file obtained by running the dedicated object code for performance testing in step 2), the memory usage size of each variable, the usage times of variables, the start and end running times of functions, and the usage times of assembly instructions are recorded. As an alternative implementation, when counting the execution process information in the output file in step 2) of this embodiment, it further includes calculating the running time of each function respectively, and the proportion of the running time occupied by the total running time of the dedicated object code for performance testing. Generate a function index file for all functions, function entrances, and function endings, and generate the function call relationship between different functions according to the function index file to add to the performance analysis result of the target application. The running time of the function is the difference between the start and end running times of the function. After generating a function index file for all functions, function entrances, and function endings, the function index file contains the function call relationship. For example, the function itself is necessarily adjacent to the function entrance, and the remaining positions other than the function ending are external calls to the function, and the positions between the function entrance and the function ending are recursive calls to the function itself. Therefore, when generating the function call relationship between different functions according to the function index file, it can be found and determined according to the function name combined with the above position relationship, and the keyword matching or regular expression matching method can be used during the search, so as to determine the situation of any function being called.
[0034] In addition, this embodiment also provides an application program performance analysis system oriented to code, including a microprocessor and a memory connected to each other. The microprocessor is programmed or configured to execute the steps of the aforementioned application program performance analysis method oriented to code.
[0035] In addition, this embodiment also provides a computer-readable storage medium. A computer program is stored in the computer-readable storage medium, and the computer program is used to be programmed or configured by a microprocessor to execute the steps of the aforementioned application program performance analysis method oriented to code.
[0036] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, as well as the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in the process Figure 1 one process or multiple processes and / or blocks Figure 1 These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device that implements the functions specified in the process Figure 1 one process or multiple processes and / or blocks Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in the process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0037] The above is only the preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the idea of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A code-oriented application performance analysis method, characterized in that Including: 1) For the target application to be tested, compile the source code of the target application into corresponding performance test dedicated target code through preset compilation options, and the performance test dedicated target code has the function of outputting execution process information to a specified output file; 2) Run the performance test dedicated target code, and for the specified output file obtained by running the performance test dedicated target code, count the execution process information in the output file, so as to obtain the performance analysis result of the target application; The outputting the execution process information to a specified output file specifically refers to outputting the information of variables, functions, and assembly instructions executed during the execution process to the specified output file, and the information of variables includes the names of global variables and local variables, and the information of functions includes the name of the function, the function entry, and the position of the function end; When compiling the source code of the target application into corresponding performance test dedicated target code through preset compilation options in step 1), it includes, at the front end of the compiler, identifying variables and functions in the source code, determining the type of variables as global variables or local variables, and determining the function entry and the position of the function end of the function, and adding marks to each variable, function, its function entry, and function end respectively according to the set rules, and the marks are used to output the information of the corresponding variable, function, function entry, or function end as execution process information to the specified output file when the performance test dedicated target code is executed; The output file obtained by running the performance test dedicated target code in step 2) records the memory usage size of each variable, the usage times of variables, the start and end running times of functions, and the usage times of assembly instructions; When counting the execution process information in the output file in step 2), it also includes calculating the running time of each function respectively, and the proportion of the running time occupied by the total running time of the performance test dedicated target code, generating a function index file for all functions, function entries, and function ends, and generating the function call relationship between different functions according to the function index file to add to the performance analysis result of the target application, and the running time of the function is the difference between the start and end running times of the function; when generating the function call relationship between different functions according to the function index file, the function itself and the function entry are adjacent, the positions other than the function end are external calls to the function, and the positions between the function entry and the function end are recursive calls to the function itself.
2. The method for analyzing the performance of a code-oriented application according to claim 1, wherein When adding marks to each variable, function, its function entry, and function end respectively according to the set rules, it includes using the local variable mark lx to mark local variables, using the global variable mark gx to mark global variables, using the function mark fx to mark functions, using the function entry mark sx to mark the function entry of the function, and using the function end mark tx to mark the function end of the function.
3. The method for analyzing the performance of a code-oriented application according to claim 1, wherein After adding marks to each variable, function, its function entry, and function ending according to the set rules, it further includes the step of performing syntax and lexical checks on the added marks. If the added marks conform to the syntax rules, continue to execute downward; otherwise, correct the keywords that do not conform to the rules and then execute downward.
4. The method for analyzing the performance of a code-oriented application according to claim 1, wherein When compiling into the corresponding performance test-specific target code through the preset compilation options in step 1), it further includes adding marks to all or specified partial assembly instructions at the backend of the compiler, and adding a mark garbage collection function module to the performance test-specific target code. The mark garbage collection function module is used to respectively count the marks of each variable, function, function entry, function ending, and assembly instruction, so as to count the memory usage size of variables, the usage times of variables, the start and end running times of functions, and the usage times of assembly instructions, and after the counting is completed, regard the marks as garbage for recycling to reduce the memory usage.
5. A code-oriented application performance analysis system, comprising a microprocessor and a memory connected to each other, characterized in that, The microprocessor is programmed or configured to execute the steps of the code-oriented application performance analysis method described in any one of claims 1 to 4.
6. A computer-readable storage medium storing a computer program therein, characterized in that, The computer program is used to be programmed or configured by the microprocessor to execute the steps of the code-oriented application performance analysis method described in any one of claims 1 to 4.
Citation Information
Patent Citations
Application test method and device and programmable device
CN107590066A