參考資訊:
https://github.com/jrfonseca/gprof2dot
main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void test1(void)
{
for (int x = 0; x < 5000; x++);
}
void test2(void)
{
usleep(1);
}
void test3(void)
{
usleep(100);
}
int main(int argc, char** argv)
{
int cnt = 10000;
while (cnt--) {
test1();
test2();
test3();
}
}
編譯並且執行
$ gcc -pg -g -no-pie main.c -o test $ git clone https://github.com/jrfonseca/gprof2dot $ cd gprof2dot $ ../test $ gprof ../test | ./gprof2dot.py -n0 -e0 | dot -Tpng -o output.png
完成