Original article link
GPROF is a common performance tool for performance tuning. But !! It has a fatal disadvantage that dynamic link libraries (loaded by dlopen () cannot be processed ). Sigh...
How can I tune the dynamic link library? Use callgrind.
It is also a set of valgrind tools, which is also convenient to use. GCC carries the-G parameter and runs it with callgrind!
Same as the previous oneProgram:
# Include <stdio. h> # Include <Stdlib. h> Void F1 (){ Int I; Int * P; For (I = 0 ; I < 10 ; I ++ ) {P = Malloc ( Sizeof ( Int )); * P = 10 ; Free (p );}} Void F2 (){ Int I; Int * P; For (I = 0 ; I < 20 ; I ++ ) {P = Malloc ( Sizeof ( Int )); * P = 10 ; Free (p );}} Void F3 (){ Int I; Int * P; For (I = 0 ; I < 30 ; I ++ ) {P = Malloc ( Sizeof ( Int )); * P = 10 ; Free (p );}} Int Main (){ Int I; For (I = 0 ; I < 1000000 ; I ++ ) {F1 (); F2 (); F3 ();} Return 0 ;}
Compile and run:
Gcc-O test-G test. cvalgrind-- Tool = callgrind./test
Be patient. The program running on callgrind will be very slow (Long live ).
After running, callgrind. Out. *** appears in the folder, which is the log file. Similar to massif, tools are required for conversion:
Callgrind_annotate callgrind. Out.438
The result is as follows:
-------------------------------------------------------------------------------- Profile data File ' Callgrind. out.438 ' (Creator: callgrind- 3.5 . 0 ) -------------------------------------------------------------------------------- I1 cache: d1 cache: L2 cache: timerange: Basic Block 0 - 977300000 Trigger: Program terminationprofiled target :. /Test (PID 438 , Part 1 ) Events recorded: irevents shown: irevent Sort Order: irthresholds: 99 Include dirs: User annotated: Auto - Annotation: Off -------------------------------------------------------------------------------- IR -------------------------------------------------------------------------------- 4 , 136 , 177 , 734 Program totals -------------------------------------------------------------------------------- IR File : Function -------------------------------------------------------------------------------- 1 , 353 , 303 , 232 ??? : _ Int_free [/lib64/libc- 2.12 . 90 . So] 1 , 162 , 995 , 238 ??? : _ Int_malloc [/lib64/libc- 2.12 . 90 . So] 972 , 686 , 762 ??? : Malloc [/lib64/libc- 2.12 . 90 . So] 401 , 761 , 897 ??? : Free [/Lib64/libc- 2.12 . 90 . So] 119 , 471 , 210 Test. C: F3 [/home/dccmx/projects/console/ Test] 80 , 704 ,867 Test. C: F2 [/home/dccmx/projects/console/ Test] 41 , 938 , 337 Test. C: F1 [/home/dccmx/projects/console/test]
Is there a more powerful graphic front-end? Yes. Open callgrind. Out. *** with kcachegrind:
Refreshing! I believe you know the same thing.