funny graphviz -- 捕获函数调用路径

实例

1 两个c文件

/***d.c***/

void fun()
{
    int i;

    i = 0;
}

int main()
{
    int i;

    i = 0;
    while(i++ < 10)
        fun();

    return 0;

}

 

/***test.c***/

#include <stdio.h>
#include <stdlib.h>

/* Constructor and Destructor Prototypes */
void main_constructor( void ) __attribute__ ((no_instrument_function, constructor));
void main_destructor( void ) __attribute__ ((no_instrument_function, destructor));


void __cyg_profile_func_enter( void *this, void *callsite )__attribute__ ((no_instrument_function, destructor));
void __cyg_profile_func_exit( void *this, void *callsite )__attribute__ ((no_instrument_function, destructor));

/* Output trace file pointer */
static FILE *fp;

void main_constructor( void )
{
  fp = fopen( "trace.txt ", "w" );
  if (fp == NULL) exit(-1);
}

void main_deconstructor( void )
{
  fclose( fp );
}

void __cyg_profile_func_enter( void *this, void *callsite )
{
  /* Function Entry Address */
  fprintf(fp, "E%p/n", (int *)this);
}

void __cyg_profile_func_exit( void *this, void *callsite )
{
  /* Function Exit Address */
  fprintf(fp, "X%p/n", (int *)this);
}

*****************华*丽*的*分*割*线 ****************

 

编译:gcc -o foo d.c test.c -g -finstrument-functions

执行:./foo ,生成了trace.txt文件

E0x80484f9
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
E0x80484c4
X0x80484c4
X0x80484f9
E(nil)
X(nil)

执行:./pvtrace foo,生成graph.dot

digraph foo {

  main [shape=rectangle]
  fun [shape=ellipse]
  main -> fun [label="10 calls" fontsize="10"]

}

dot -Tjpg graph.dot -o graph.jpg 生成图片

 

详情参考

参考 http://www.ibm.com/developerworks/cn/linux/l-graphvis/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值