davepacheco/node-stackvis — pull request #2 by ackalker (2012-11-08 19:11:06+00:00)
Title: Add support for Linux `perf record` output

Add a command-line tool and reader to work with the output of `perf record` and `perf script`.

Tested with the following:
commands:

```
# gcc -g -o foo foo.c
# perf record -F 997 -g ./foo
# perf script | cmd/stackcollapse-perf > collapsed.out
# cmd/flamegraph < collapsed.out > perf.svg
```

foo.c:
```
#include
#include
#include

#define BIGLOOP(C,E,I) { int C; for(C=0; C<(E); ++C) {I;} }

int foo(int qux) {
int quux;
printf("foo\n");
BIGLOOP(p,16384,BIGLOOP(q,16384,continue));
quux = bar(qux * 7);
BIGLOOP(p,16384,BIGLOOP(q,16384,continue));
return baz(quux);
}

int bar(int xyzzy) {
printf("bar\n");
BIGLOOP(p,16384,BIGLOOP(q,16384,continue));
return xyzzy * 3;
}

int baz(int frob) {
printf("baz\n");
BIGLOOP(p,16384,BIGLOOP(q,16384,continue));
return frob * 2;
}

int main(void) {
int answer;
printf("main\n");
BIGLOOP(p,16384,BIGLOOP(q,16384,continue));
answer = foo(1);
printf("The answer is: %d\n", answer);
exit(0);
}
```