gperftools

Problems with using gperftools on Mac OS X

喜你入骨 提交于 2019-12-06 13:56:44
问题 I have found several conflicting answers over this topic. This blog post requires libuwind, but that doesn't work on Mac OS X. I included #include <google/profiler.h> in my code, however my compiler (g++) could not find the library. I installed gperftools via homebrew. In addition, I found this stackoverflow question showing this: Then I ran pprof to generate the output: [hidden ~]$ pprof --text ./a.out cpu.profile Using local file ./a.out. Using local file cpu.profile. Removing __sigtramp

Why do I see edges in the call graph that don't exist using gperftools?

£可爱£侵袭症+ 提交于 2019-12-06 11:15:15
Given the following code that either calls f or g #include <stdlib.h> #include <stdio.h> int f() { return 0; } int g() { return 1; } int main() { long sum = 0; for(int i = 0; i < 1000*1000*1000; i++) { int result; if(rand() % 2 == 0) { result = f(); } else { result = g(); } sum += result; } printf("%ld\n", sum); } I compile with g++ test.c -o doom -lprofiler -lunwind And run with CPUPROFILE=./test.txt ./test And then generate a gif with pprof --gif ./test ./test.txt > output.gif I get the following However, I have edges going from f to g, and f to itself, and g to itself. There are no

How exactly does gperftools CPU profiler start?

╄→гoц情女王★ 提交于 2019-12-05 02:00:59
gperftools documentation says that libprofiler should be linked into a target program: $ gcc myprogram.c -lprofiler (without changing a code of the program). And then program should be run with a specific environment variable: CPUPROFILE=/tmp/profiler_output ./a.out The question is: how does libprofile have a chance to start and finish a profiler when it is merely loaded, but its functions are not called? There is no constructor function in that library ( proof ). All occasions of "CPUPROFILE" in library code do not refer to any place where profiler is started. I am out of ideas, where to look