First, the preface
Reference gprof User manual: Http://sourceware.org/binutils/docs-2.17/gprof/index.html
Reference Blog: http://blog.csdn.net/stanjiang2010/article/details/5655143
Gprof is GCC's own performance testing tool, which can count the number of calls, time, and function call graphs for each function.
Second, the tutorial
Using GRPOF is divided into three steps
(1) Compile time to open the compile switch,-PG
(2) Run the program (the program must run normally before the performance report will be generated)
(3) Run the Performance test tool to generate the report.
1. Code
Write a sample code here and then perform a performance test on it
TEST_GPROF.C
#include <stdio.h>
void new_func1 (void);
void func1 (void)
{
printf ("\ n Inside func1 \ n");
int i = 0;
for (; i<0xffffffff;i++);
New_func1 ();
return;
}
static void Func2 (void)
{
printf ("\ Inside func2 \ n");
int i = 0;
for (; i<0xffffffaa;i++);
return;
}
int main (void)
{
printf (\ Inside main () \ n);
int i = 0;
for (; i<0xffffff;i++);
Func1 ();
Func2 ();
return 0;
}
Test_gprof_new.c
#include <stdio.h>
void new_func1 (void)
{
printf (\ Inside new_func1 () \ n ");
int i = 0;
for (; i<0xffffffee;i++);
return;
}
2. Compile and Execute
g++ -pg test_gprof.cpp test_gprof_new.cpp-o test_gprof
You can see that the execution will be reborn into a gmon.out file
3. Run Performance test Tool
Gprof test_gprof Gmon.out
You can see a variety of parameters that are on the screen
(1) Flat profile, including the number of calls per function, and the processor time consumed by each function
(2) Call graph includes the invocation relationship of functions, and the time spent in each function call