Gprof How to work
When you specify the-PG option when using GCC compilation, the compiler inserts the performance test code into the user code.
Gprof Simple Application Example
Main.c
#include <stdio.h> #include "lib.h" int main (void) {func1 (FUNC2); return 0;}
Lib.h
#ifndef lib_h#define lib_hvoid func1 (int i), void func2 (int i); #endif/* Lib_h */
Lib.c
#include <stdio.h> #include "lib.h" void func1 (int i) {while (i--) printf ("Func1 ():%d\n", i);} void Func2 (int i) {while (i--) printf ("Func2 ():%d\n", i);}
Makefile
CFLAGS + =-PGOBJS = $ (patsubst%.c,%.o,$ (wildcard *.c)) Prog: $ (OBJS) gcc-pg-o [email protected] $^clean:-rm-f prog $ (obj S
Run make compile code at the command line to generate the prog file. Enter the./prog to run the file, producing an output file gmon.out. After
Use the tool gprof to analyze the operation of the output File Analyzer and to derive the data optimizer based on these analyses.
Run the Gprof prog gmon.out > Gprofrslt.txt analysis output file to get the following results (excerpt). can be passed to
Gprof different parameters to derive the output of different aspects of performance considerations.
flat profile:each sample counts as 0.01 seconds. no time accumulated % cumulative self self total time seconds seconds calls Ts/call Ts/call name 0.00 0.00 0.00 1 0.00 0.00 func1 0.00 0.00 0.00 1 0.00 0.00 func2
The meaning of the specific output can be referenced in the GPROF help documentation.
3. Gprof Documentation
http://sourceware.org/binutils/docs/gprof/
This article is from the "Jimokuangxiangqu" blog, make sure to keep this source http://4594296.blog.51cto.com/4584296/1841733
Linux Performance Optimization Tool gprof précis-writers