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

限于喜欢 提交于 2019-12-10 10:36:20

问题


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 optimizations on (and I tried again with -O0 to be sure), and I've also tried with and without -lunwind.

Why does the profiler think that f calls g (and itself somtimes)? How do I use the profiler correctly?

来源:https://stackoverflow.com/questions/24668450/why-do-i-see-edges-in-the-call-graph-that-dont-exist-using-gperftools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!