Source: http://morningspace.51.net/,moyingzz@etang.com |
It helps you analyze and find the bottleneck of the program running, find the time consumed, and also help you find the code that will not be executed. So as to optimize the program. |
Profile Composition |
Profile includes three command line tools: Prep, profile, and plist. You can run profile in the command line mode. The process is: Prep reads the executable file of the application and generates. PBI file and. PBT file; Profile according. the PBI file is generated by running and analyzing the program. pbO output file; Prep then according. pbO files and. PBT file to generate a new. PBT file; plist according. the PBT file generates readable output. |
Profile Functions |
-Function timing: evaluates the time spent by the Program on executing a specific function. You can activate this feature in the profile dialog box. In the analysis results, the func time Column records the function running time in seconds. The next column shows the percentage of the function time to the total running time; the func + child time Column records the total time spent on running the Function and Its called sub-functions. The next column shows the percentage of the preceding time to the total running time; the hit count Column records the number of times a function is called. The function column displays the function name. |
|
-Function coverage: records whether a specific function is called and can be used to determine the unexecuted part of the code. You can activate this feature in the profile dialog box. The analysis result lists all the functions analyzed and marks the executed functions with the asterisk. |
|
-Function counting: records the number of times a program calls a specific function. Select custom in the profile dialog box, and specify fcount. BAT (located in the vc98/bin directory) in custome settings ). Note that the fcount. when the directory where BAT is located, it is best not to use the long file name method, which may cause errors. For example, to write C:/program files into C:/progra ~ 1. |
|
-Line counting: record the number of specific rows in the Code executed by the program. Select custom in the profile dialog box, and specify lcount. BAT (located in the vc98/bin directory) in custome settings ). This function uses the debug information in. EXE to start the profile, so the. map file is not required. In the analysis results, the line column shows the source code line number, and the hit count Column records the number of executions of the line. The next column shows the percentage of executions of the line to all code lines, source line displays the corresponding source code. |
|
-Line coverage: records whether a specific line in the code is executed. It can be used to determine the unexecuted part of the code. You can activate this feature in the profile dialog box. The analysis result lists all the analyzed code lines and marks the executed lines with the asterisk. Because line coverage only records whether the code line has been executed, its execution overhead is smaller than line counting. |
|
In addition, the profile dialog box provides the Merge function to combine the statistical results after running the profile multiple times. If you are using the function coverage function, you will see whether all functions have been tested. If you are using the function timing function, you will see the cumulative time of all the previous analysis and the current analysis. |
Use of profile in IDE environment |
-Functions related to function analysis
- Select project> Settings> link and select enable profiling check box
- Reconstruction Project
- Select build> profile. The profile dialog box is displayed.
- After necessary settings, select OK to start running the program
|
|
-Functions related to row Analysis
- Select project-> Settings-> link, and select the Enable profiling check box and Generate debug info check box.
- Select project-> Settings-> C/C ++, and select line numbers only
- Reconstruction Project
- Select build> profile. The profile dialog box is displayed.
- After necessary settings, select OK to start running the program
|
Configure profile in three ways |
-Modify the profiler. ini file |
|
Profiler. INI is located in the vc98/bin directory. In its [profiler] segment, you can specify the Lib file or OBJ file not involved in analysis. For example: |
|
[profiler]exclude:user32.libexclude:gdi32.lib |
|
|
-Specify options in the profile dialog box. |
|
If you select the funciton timing, function coverage, or line coverage options, you can specify a further range in advanced settings. For example, you want the profile to analyze only sampleapp. the code within a specific range in the CPP file can be entered in advanced settings,/excall/INC sampleapp. CPP (30-67 ). Another example: If you want file1.obj and file2.obj to not participate in the analysis, you can enter/EXC file1.obj/EXC file2.obj in advanced settings. Another example: If you want to describe only the specified function, you can enter/SF in advanced settings? Samplefunc @ yaxpb @. The modifier name of a specific function is followed by the SF parameter. The simplest way to obtain the name is to search for it in the map file generated during project creation. |
|
SF, excall, exc, INC are the command line parameters of prep. For details about other parameters, you can enter PREP/h at the command line prompt. |
|
-Compile a batch command file |
|
See fcount. bat, fcover. bat, ftime. bat, lcount. bat, and lcover. bat. |
Output data from Profile |
The plist/T command allows plist to output the. PBT file content to a text file in tabulation format. This format is suitable for inputting it into a workbook or database. For example: plist/T myprog> myprog. txt, the generated myprog. txt can be imported to the Microsoft Excel Workbook using profiler. XLM (in the vc98/bin directory. |
Note: |
-Generally, analyzing the entire program is of little significance, because most Windows applications spend the most time waiting for messages. Therefore, precisely locating the code to be analyzed can speed up profile execution, improve the analysis accuracy. Close other unrelated applications whenever possible during profile execution. |
|
-If remote debugging is enabled, the profile function cannot be called from the build menu. |
|
-For inline functions, the compiler replaces the function call with the actual code, so the inline function is not generated. the map file or call command, so when such a function is executed, the profile will not be able to know that the time spent, the number of runs, and other data are attributed to the function that calls the function. Profile provides row-level running times and overwrites for inline functions. |
|
-For multi-threaded applications, the profile behavior depends on the analysis method you selected. For line counting and line coverage, the profile does not distinguish between threads, it will contain all the threads currently running. For function timing, function coverage, and function counting, the analysis result depends on the thread. You can analyze an independent thread in the following way:
- Declare the main function of the thread as the initial function (use the prep/SF option)
- Contains all functions in the Program (do not use the prep/EXC option)
|
|
Otherwise, the analysis results are difficult to explain. |