所需工具:
过程:
- 编译/安装 pvtrace(make,make install 即可)
- 将 pvtrace 中instrument.c 拷贝到要进行编译的路径
- 按如下代码编译测试程序(注意第三行-finstrument-functions 是连起来的):
1: $ ls
2: instrument.c test.c
3: $ $ gcc -g -finstrument-functions test.c instrument.c -o test
4: $ ./test
5: $ ls
6: instrument.c test.c
7: test trace.txt
8: $ pvtrace test
9: $ ls
10: graph.dot test trace.txt
11: instrument.c test.c
12: $ dot -Tjpg graph.dot -o graph.jpg
13: $ ls
14: graph.dot instrument.c test.c
15: graph.jpg test trace.txt
16: $
我的源码:
1: #include <stdlib.h>
2:
3: void step1(){
4: printf(“I am step1 !\n”);
5: }
6:
7: void step(){
8: printf(“I am last step !\n”);
9: }
10:
11: void step2(){
12: printf(“I am step2 !\n”);
13: step();
14: }
15:
16: int main(void){
17: step1();
18: step2();
19: return 1;
20: }
21:
编译生成的图片:
PS:在makefile 中添加中间件编译参考[2]。
参考:
[1].http://www.ibm.com/developerworks/cn/linux/l-graphvis/
[2].http://blog.csdn.net/seasonpplp/article/details/7399053
[3].http://blog.csdn.net/fisher_jiang/article/details/6828427