用 Graphviz 可视化函数调用
2012-03-27 15:15
218 查看
为了捕获并显示调用图,您需要4个元素:
①GNU编译器工具链
②pvtrace
③instrument.c
④Graphviz
$ Sudo apt-get install graphviz
$wget http://public.dhe.ibm.com/software/dw/library/l-graphvis/pvtrace.zip
$unzip pvtrace.zip –d pvtrace
$cd pvtrace
$make
$make install
2.将instrument.C文件拷贝至工程目录
Instrument.c文件的源码如下:
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 /* Function prototypes with attributes */
15 void main_constructor( void )
16 __attribute__ ((no_instrument_function, constructor));
17
18 void main_destructor( void )
19 __attribute__ ((no_instrument_function, destructor));
20
21 void __cyg_profile_func_enter( void *, void* )
22 __attribute__ ((no_instrument_function));
23
24 void __cyg_profile_func_exit( void *, void* )
25 __attribute__ ((no_instrument_function));
26
27
28 static FILE *fp;
29
30
31 void main_constructor( void )
32 {
33 fp= fopen( "trace.txt", "w" );
34 if(fp == NULL) exit(-1);
35 }
36
37
38 void main_deconstructor( void )
39 {
40 fclose( fp );
41 }
42
43
44 void __cyg_profile_func_enter( void *this,void *callsite )
45 {
46 fprintf(fp, "E%p\n", (int *)this);
47 }
48
49
50 void __cyg_profile_func_exit( void *this,void *callsite )
51 {
52 fprintf(fp, "X%p\n", (int *)this);
53 }
54
3.修改工程的Makefile文件
在Makefile中的编译选项中添加如下命令:
-g –fininstrument-functions instrument.c
4.运行程序生成trace.txt文件
5.pvtrace 目标程序 生成graph.dot文件
6. 运行dot –Tjpg graph.dot –o graph.jpg命令生成.jpg调用图
①GNU编译器工具链
②pvtrace
③instrument.c
④Graphviz
使用方法:
1.安装pvtrace和graphviz工具:$ Sudo apt-get install graphviz
$wget http://public.dhe.ibm.com/software/dw/library/l-graphvis/pvtrace.zip
$unzip pvtrace.zip –d pvtrace
$cd pvtrace
$make
$make install
2.将instrument.C文件拷贝至工程目录
Instrument.c文件的源码如下:
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 /* Function prototypes with attributes */
15 void main_constructor( void )
16 __attribute__ ((no_instrument_function, constructor));
17
18 void main_destructor( void )
19 __attribute__ ((no_instrument_function, destructor));
20
21 void __cyg_profile_func_enter( void *, void* )
22 __attribute__ ((no_instrument_function));
23
24 void __cyg_profile_func_exit( void *, void* )
25 __attribute__ ((no_instrument_function));
26
27
28 static FILE *fp;
29
30
31 void main_constructor( void )
32 {
33 fp= fopen( "trace.txt", "w" );
34 if(fp == NULL) exit(-1);
35 }
36
37
38 void main_deconstructor( void )
39 {
40 fclose( fp );
41 }
42
43
44 void __cyg_profile_func_enter( void *this,void *callsite )
45 {
46 fprintf(fp, "E%p\n", (int *)this);
47 }
48
49
50 void __cyg_profile_func_exit( void *this,void *callsite )
51 {
52 fprintf(fp, "X%p\n", (int *)this);
53 }
54
3.修改工程的Makefile文件
在Makefile中的编译选项中添加如下命令:
-g –fininstrument-functions instrument.c
4.运行程序生成trace.txt文件
5.pvtrace 目标程序 生成graph.dot文件
6. 运行dot –Tjpg graph.dot –o graph.jpg命令生成.jpg调用图
相关文章推荐
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用Graphviz可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用
- 用 Graphviz 可视化函数调用