How to use calltree and Graphviz/CodeViz

1. calltree
Download source codes from Ref(1) or (2), and compile it.
Then copy the "calltree" utility to /usr/local/bin/
You also need a special script which called tree2dot-filter.sh
to make life easy, and it can be get from Ref(3).
By using the following example, you will get fuction calling relations
in a picture test_calltree.jpg.

sandbox$ which calltree tree2dot-filter.sh
/usr/local/bin/calltree
/usr/local/bin/tree2dot-filter.sh

sandbox$ cat test_calltree.c
#include <stdio.h>
#include <stdlib.h>

void do_something_firstly()
{
    char *str = NULL;

    str = malloc(100);
    free(str);
}

void do_something_finally()
{
    printf("Bingo!\n");
}

int main()
{
    printf("Hello, call tree :-)\n");

    do_something_firstly();
    do_something_finally();

    return 0;
}

sandbox$ calltree -mb -np test_calltree.c
main:
|   do_something_finally
|   |   printf
|   do_something_firstly
|   |   free
|   |   malloc
|   printf

sandbox$ calltree -mb -np test_calltree.c | tree2dot-filter.sh > test_calltree.dot
sandbox$ dot -Tjpg test_calltree.dot -o test_calltree.jpg

2. Graphviz and CodeViz
Download source codes from Ref(6) and (7), and compile them.
Then copy the "gcc-graph", "genfull", and "gengraph" utility to /usr/local/bin/
By using the following example, you will get fuction calling relations
in a picture main.png.

sandbox$ which gcc-graph genfull gengraph
/usr/local/bin/gcc-graph
/usr/local/bin/genfull
/usr/local/bin/gengraph

sandbox$ gcc-graph test_calltree.c
sandbox$ genfull
sandbox$ gengraph --output-type "png" -f main


Reference:
(1) http://directory.fsf.org/project/calltree/
(2) http://linux.softpedia.com/progDownload/calltree-Download-971.html
(3) http://download.csdn.net/source/3567869
(4) http://www.linuxsir.org/bbs/printthread.php?t=246389
(5) http://blog.csdn.net/cqbamboo/article/details/6736627
(6) http://www.graphviz.org/
(7) http://www.csn.ul.ie/~mel/projects/codeviz/
(8) http://www.ibm.com/developerworks/cn/linux/l-graphvis/
(9) http://blog.csdn.net/cqbamboo/article/details/6739024
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值