Goal is to show callgraphs of any process

perf record -g ./foo
perf script | ./gprof2dot.py -f perf | dot -Tpng -o foo.png

This utility comes from jrfonseca's Gprof2Dot page, direct download link is: gprof2dot.py (local mirror).

Produces:

And test program

#include <stdio.h>

int sum = 0;
#define LOOP()                    \
  {                               \
    int j;                        \
    for (j = 0; j < 10000; j++) { \
      sum += j;                   \
    }                             \
  }

int f() { LOOP(); }
int d() { LOOP(); f(); }
int e() { LOOP(); f(); }
int c() { LOOP(); d(); LOOP(); e(); }
int b() { LOOP(); c(); }
int a() { LOOP(); c(); }

int main() {
  int i;
  for (i = 0; i < 10000; i++) {
    a();
    b();
  }
}

Tags

Related Posts