Use gprof to visualize code running time

来源:互联网 发布:jd抢购软件 编辑:程序博客网 时间:2024/06/05 22:43

Step 1

Install requirements:
- gprof
- graphviz
- grpof2dot

Step 2

Add -pg to gcc/g++ flag, both when compiling and linking, like below:

g++ -pg -I . -o fun.o fun.cppg++ -pg -I . -o main.o main.cppg++ -pg -o main main.o fun.o -L/usr/local/lib -lboost_system

Step 3

./main

Run the execute file. And then you may find gmon.out file in the folder containing exe.

Step 4

gprof main gmon.out | gprof2dot | dot -Tpng -o output.png && eog output.png

You can find a picture like this:

Step 5

Another endless journey of optimization begins.

0 0
原创粉丝点击