View static calls in gprof output
I have a gprof "flat profile" output which lists all my functions, including static functions. But, the "calls", "self ms/call", and "total ms/call" columns are all empty for the functions declared as "static". I want to see the data for these functions as well; they are actually far more interesting to me than the public functions in the module. For example:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
55.32 3.38 3.38 Static_Func1
16.61 4.39 1.01 Static_Func2
12.44 5.16 0.76 2 380.00 380.00 Public_Func1
9.90 5.76 0.60 Static_Func3
2.78 5.93 0.17 Static_Func4
0.98 5.99 0.06 12463589 0.00 0.00 main
0.65 6.03 0.04 1200000 0.00 0.00 Public_Func2
0.33 6.05 0.02 2 10.00 10.00 Public_Func3
0.33 6.07 0.02 Static_Func5
0.33 6.09 0.02 free
0.33 6.11 0.02 malloc
0.00 6.11 0.00 1 0.00 0.00 Public_Func4
I found Why does gprof occasionally not print number of calls for particular functions? which explains why I don't see the output for these functions, but is there a way to see it anyway aside from stripping out the static declarations? I know I can suppress printing static functions with -a
but I want to do the opposite and don't see an option for it.
When I edit the code to strip out the "static" keyword from the static functions in the above profile, the "calls" for main becomes empty (I'd expect 1, so it's wrong either way). More usefully, not only are the fields populated, but any functions called by those static functions also get listed. I'd like to be able to do that without any code changes.
I also found Is GNU gprof buggy? which seems to suffer from the same problems, but the solution there was to edit the code to force the compiler not to inline some of the functions. I don't want to edit my code just for the sake of profiling, I want to be able to see all my functions as they exist now.
Version info, running in MinGW shell under Windows 7 64-bit:
$ which gprof
/mingw/bin/gprof.exe
$ gprof --version
GNU gprof (GNU Binutils) 2.22
Based on BSD gprof, copyright 1983 Regents of the University of California.
This program is free software. This program has absolutely no warranty.
I'm not attempting an answer here but rather a further continuation of the same problem I'm also experiencing in cygwin
, GNU gprof (GNU Binutils) 2.24.51.20140528
(I have run this code on Ubuntu (both 32/64 bits) and I got no problems whatsoever):
#include<stdio.h>
#include<stdlib.h>
#define N1 100
#define N2 100
#define N3 100
#define N4 100
#define USE_STATIC
#ifdef USE_STATIC
static
#endif
void f5() {
int i;
for (i = 0; i < 10; i++) {
}
}
#ifdef USE_STATIC
static
#endif
void f4() {
int i;
for (i = 0; i < N4; i++) {
f5();
}
}
#ifdef USE_STATIC
static
#endif
void f3() {
int i;
for (i = 0; i < N3; i++) {
f4();
}
}
void f2() {
int i;
for (i = 0; i < N2; i++) {
f3();
}
}
void f1() {
int i;
for (i = 0; i < N1; i++) {
f2();
}
}
int main() {
f1();
return 0;
}
With the USE_STATIC
macro disabled I get this flat data reported by gprof (which seems reasonable):
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
85.90 1.98 1.98 100000000 0.00 0.00 f5
9.98 2.21 0.23 _mcount_private
3.47 2.29 0.08 1000000 0.00 0.00 f4
0.65 2.31 0.01 _fentry__
0.00 2.31 0.00 10000 0.00 0.00 f3
0.00 2.31 0.00 100 0.00 0.02 f2
0.00 2.31 0.00 1 0.00 2.06 f1
Now if I enable it it's all going down:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
79.48 1.82 1.82 f5
17.47 2.22 0.40 _mcount_private
2.18 2.27 0.05 f4
0.44 2.28 0.01 _fentry__
0.44 2.29 0.01 f3
0.00 2.29 0.00 101010000 0.00 0.00 __gcc_deregister_frame
0.00 2.29 0.00 100 0.00 0.00 f2
0.00 2.29 0.00 1 0.00 0.00 f1
As far as I'm able to determine mcount()
gets properly called in each of these functions so I have no idea what makes gprof mess the calls count so bad. After all this should be the only precise piece of data it is able to output. Timing information is completely unreliable anyway (especially for programs which get finished fast).
There's a historical stackoverflow topic here listing some better alternatives to gprof
: http://archive.today/9r927
You may probably want to take a look there. I know I will ...
链接地址: http://www.djcxy.com/p/43866.html上一篇: 无法查看gprof分析器的完整输出
下一篇: 在gprof输出中查看静态调用