codeviz 过程分析

来源:互联网 发布:淘宝卖家版怎么注册 编辑:程序博客网 时间:2024/06/07 04:57
0) sudo apt-get install build-essential
1)网址
该项目网址为
http://www.csn.ul.ie/~mel/projects/codeviz
在此下载codeviz-1.0.11.tar.gz放到希望的目录里
http://www.csn.ul.ie/~mel/projects/codeviz/#download

2)过程
     1. 安装 GraphViz
    用新立得软件管理器
    2. 安装CodeViz
       tar zxvf codeviz-1.0.11.tar.gz
       2.1安装带patch的gcc:
        下载gcc-3.4.6.tar.gz
http://gcc.parentingamerica.com/releases/gcc-3.4.6/
        mv gcc-3.4.6.tar.gz codeviz-1.0.11/compilers
        cd codeviz-1.0.11/compilers
        sudo ./install_gcc-3.4.6.sh /usr/local/gcc-graph
       2.2 安装 CodeViz, cd */codeviz-1.0.11
          sudo  ./configure --gccgraph=/usr/local/gcc-graph
           sudo  make install-codeviz
        3. 使用
        #include <stdio.h>
         void test(void);
          int  main(void)
            {
                  test();
              return ;
                }
          void test()
            {
                      return;
          }

将*/codeviz-1.0.11/bin 当作工作目录 cd */codeviz-1.0.11/bin
test.c 放到此目录
    $/usr/local/gcc-graph/bin/gcc test.c
         ------
      编译$/usr/local/gcc-graph/bin/gcc test.c,这时可以看到test.c文件所          在目录生成文件test.c.cdepn。编译成功!
      ------
生成调用图:使用genfull创建full.graph文件
      $genfull test.c.cdepn
使用gengraph获取需要的调用信息。
    $gengraph –output-type “png” -f main
则将full.graph由dot处理然后查看生成的postscript文件
//------------------------------------------------------------------
// Appendix 后边这些不想的话,可以不看
//------------------------------------------------------------------
为了理解ipv6代码方便,使用codeviz,显示函数调用关系。
安装的过程比较简答:
1)apt-get install graphviz
2)  下载codeviz,不同版本对应不同的gcc。configure --help 的时候可以得知。
3)下载对应版本的gcc,cp到compiler目录下,执行make,这回对gcc打patch。
这就算安装完成了。
如果要分析哪个代码,需要设置CC为对应的gcc。会为每一个c文件生成cdepn文件。
    CodeViz 使用两个脚本来生成调用图,一个是 genfull,该脚本可以生成项目的完整调
用图,因此调用图可能很大很复杂,缺省使用 cdepn 文件来创建调用图;另一个是
gengraph,该脚本可以对给定一组函数生成一个小的调用图,
 genfull 的-s 选项,-s 指定了检测哪些子目录。
gengraph
-d 指定最大调用层数
-s 仅仅显示指定函数,而不对其调用进行展开
-i 忽略指定函数
gengraph - Generate a call graph for a given set of functions
Usage:
    gengraph [options]
      Main Options:
      -f, --function    Top level functions to graph, quote if more than one
      -t, --trim        Ignore a set of Linux kernel functions (Kernel specific)
      -i, --ignore      Functions to ignore
      -s, --show        Show a function but not the sub-functions
      -d, --maxdepth    Maximum depth of graph
      -r, --reverse     Place the function at the bottom and graph callers
      -g, --graph       Source graph from by genfull (Default: ./full.graph)
      -l, --location    Show the location of the function declarations
      -a, --all-locs    Show the location of declarations and calls
      -k, --keep        Keep the sub.graph file
      -o, --output      Output postscript filename
      -v, --verbose     Verbose output
      -h, --help        Print this message
      --no-extern       Ignore functions not defined in the current source
      --output-type     Set the output type: ps, html png or gif (default: ps)
      --output-font     What font to use for output graph (default: Helvetica)
      --output-fontsize Size of output font (default: 12)
      --output-layout   Layout direction: LR|RL|BT|TB (default TB)
      --version         Print the version number

      HTML Options (specify --output-type=html above):
      -e, --source      Root of the source code being graphed
      --html-fragment   Generate HTML suitable for including in another page
      --base-url        Template URL to use for hyperlinks in the web page
      --shighlight      Use source-highlight for HTML links
      --scss            Cascading style-sheet to use for source-highlight

      Regular Expression Options:
      -z, --func-re     Regular expressions of top-level functions to graph
      -j, --ignore-re   Regular expressions of functions to ignore
      -y, --show-re     Regular expressions of functions to show but not traverse

      Post-Processing Options:
      --pp-stack        Show stack usage and highlight excessive usage
      --pp-cstack       Show cumulative usage in a given set of code paths
      Daemon Options:
      -p, --daemon      Run gengraph as a daemon
      -q, --client      Run gengraph as a client to a gengraph daemon
      --plain           Output the dot graph file but do not use dot
      --stdout          Use this file as standard out instead of normal
      --stderr          Print errors to this file instead of STDERR
    genfull [options]
     Main Options:
      -d, --toplevel Top level source directory (Default: current)
      -f, --file     Files to scan for data     (Default: find all files)
      -s, --subdirs  Subdirectories to graph    (Default: all)
      -g, --method   Method for collecting data (Default: cdepn)
      -o, --output   Output graph               (Default: ./full.graph)
      -h, --help     Print this message
      --version      Print the version number
     Post-Processing Options:
      --skip         Skip collection and only post-process
      --pp-stack     Calculate stack usage
     For Linux kernel call graphs, the following calling is recommended
     genfull -s "arch/i386 net lib ipc mm fs net kernel init drivers"
使用cs模式
gengraph -p -g /usr/src/linux-2.4.20-clean/full.graph
 When this returns, the daemon is running. To generate a graph using the daemon, run
gengraph -q -t -d 2 -f alloc_pages
 Note the use of the -q switch which says that gengraph should run as a client to the daemon instance. If you are bored, compare the difference in running times between normal gengraph and when it is used as a client :-) . To stop the daemon, do the following
echo QUIT > /tmp/codeviz.pipe
为了理解ipv6代码方便,使用codeviz,显示函数调用关系。
安装的过程比较简答:
1)apt-get install graphviz
2)下载codeviz,不同版本对应不同的gcc。configure --help 的时候可以得知。
3)下载对应版本的gcc,cp到compiler目录下,执行make,这回对gcc打patch。
这就算安装完成了。
如果要分析哪个代码,需要设置CC为对应的gcc。会为每一个c文件生成cdepn文件。
    CodeViz 使用两个脚本来生成调用图,一个是 genfull,该脚本可以生成项目的完整调
用图,因此调用图可能很大很复杂,缺省使用 cdepn 文件来创建调用图;另一个是
gengraph,该脚本可以对给定一组函数生成一个小的调用图,
 genfull 的-s 选项,-s 指定了检测哪些子目录。
gengraph
-d 指定最大调用层数
-s 仅仅显示指定函数,而不对其调用进行展开
-i 忽略指定函数
gengraph - Generate a call graph for a given set of functions
Usage:
    gengraph [options]
      Main Options:
      -f, --function    Top level functions to graph, quote if more than one
      -t, --trim        Ignore a set of Linux kernel functions (Kernel specific)
      -i, --ignore      Functions to ignore
      -s, --show        Show a function but not the sub-functions
      -d, --maxdepth    Maximum depth of graph
      -r, --reverse     Place the function at the bottom and graph callers
      -g, --graph       Source graph from by genfull (Default: ./full.graph)
      -l, --location    Show the location of the function declarations
      -a, --all-locs    Show the location of declarations and calls
      -k, --keep        Keep the sub.graph file
      -o, --output      Output postscript filename
      -v, --verbose     Verbose output
      -h, --help        Print this message
      --no-extern       Ignore functions not defined in the current source
      --output-type     Set the output type: ps, html png or gif (default: ps)
      --output-font     What font to use for output graph (default: Helvetica)
      --output-fontsize Size of output font (default: 12)
      --output-layout   Layout direction: LR|RL|BT|TB (default TB)
      --version         Print the version number
      HTML Options (specify --output-type=html above):
      -e, --source      Root of the source code being graphed
      --html-fragment   Generate HTML suitable for including in another page
      --base-url        Template URL to use for hyperlinks in the web page
      --shighlight      Use source-highlight for HTML links
      --scss            Cascading style-sheet to use for source-highlight
      Regular Expression Options:
      -z, --func-re     Regular expressions of top-level functions to graph
      -j, --ignore-re   Regular expressions of functions to ignore
      -y, --show-re     Regular expressions of functions to show but not traverse
      Post-Processing Options:
      --pp-stack        Show stack usage and highlight excessive usage
      --pp-cstack       Show cumulative usage in a given set of code paths
      Daemon Options:
      -p, --daemon      Run gengraph as a daemon
      -q, --client      Run gengraph as a client to a gengraph daemon
      --plain           Output the dot graph file but do not use dot
      --stdout          Use this file as standard out instead of normal
      --stderr          Print errors to this file instead of STDERR




    genfull [options]

     Main Options:
      -d, --toplevel Top level source directory (Default: current)
      -f, --file     Files to scan for data     (Default: find all files)
      -s, --subdirs  Subdirectories to graph    (Default: all)
      -g, --method   Method for collecting data (Default: cdepn)
      -o, --output   Output graph               (Default: ./full.graph)
      -h, --help     Print this message
      --version      Print the version number

     Post-Processing Options:
      --skip         Skip collection and only post-process
      --pp-stack     Calculate stack usage

     For Linux kernel call graphs, the following calling is recommended
     genfull -s "arch/i386 net lib ipc mm fs net kernel init drivers"


使用cs模式
gengraph -p -g /usr/src/linux-2.4.20-clean/full.graph
 When this returns, the daemon is running. To generate a graph using the daemon, run
gengraph -q -t -d 2 -f alloc_pages
 Note the use of the -q switch which says that gengraph should run as a client to the daemon instance. If you are bored, compare the difference in running times between normal gengraph and when it is used as a client :-) . To stop the daemon, do the following
echo QUIT > /tmp/codeviz.pipe

//---------------------------------------------------------------------
//http://blog.csdn.net/freedom1013/article/details/4335778
//---------------------------------------------------------------------
 CodeViz源代码中函数调用关系的调用图生成工具

 分类: 5 Linux/Unix环境编程
2009-07-09 19:44 678人阅读 评论(0) 收藏 举报

 
1. 安装 GraphViz
用新立得软件管理器

2. 安装CodeViz
tar zxvf codeviz-1.0.11.tar.gz
2.1安装带patch的gcc:
下载gcc-3.4.6.tar.gz
mv gcc-3.4.6.tar.gz codeviz-1.0.11/compilers
cd codeviz-1.0.11/compilers
sudo ./install_gcc-3.4.6.sh /usr/local/gcc-graph

2.2 安装 CodeViz
./configure --gccgraph=/usr/local/gcc-graph
make install-codeviz


3. 使用
 #include <stdio.h>
 void test(void);
  int
  main(void)
  {
          test();
          return 0;
  }
  void test()
  {
          return;
  }

$/usr/local/gcc-graph/bin/gcc test.c

$genfull test.c.cdepn

$gengraph –output-type “png” -f main

skill:
--output-type,指定输出类型,例如png、gif、html和ps,缺省为ps。

解决函数名字冲突:分析哪些目录
使用genfull的-s选项,-s指定了检测哪些子目录。例如kernel中在
mm目录和drivers/char/drm目录下都定义了alloc_pages函数,那么可以以下列方式调用
genfull:
  genfull -s "mm include/linux drivers/block arch/i386"
 
 使用 Daemon/Client 模式:
    当full.graph很大时,大量的时间花费到读取输入文件上了,例如kernel的
full.graph是很大的,前面生成的大约有15M,这还不是全部内核的函数调用分析信息。
为了节省时间,可以将gengraph以daemon方式运行,这要使用-p选项:
        gengraph -p -g linux-2.6.25/full.graph
该命令返回时gengraph以daemon方式运行,同时在/tmp目录下生成了codeviz.pipe文件。
要生成函数调用图,可以使用-q选项:
        gengraph -q -t -d 2 -f alloc_pages
要终止gengraph的运行,使用如下命令:
        echo QUIT > /tmp/codeviz.pipe
        
一个例子:
现在我们来看如何生成内核的函数调用图,以2.6.25中alloc_pages函数为例。

首先是编译内核,这里我们的目的是查看函数调用关系,并非安装新内核,所以直接
进行配置编译:
make menuconfig
make CC=/usr/local/gcc-graph/bin/gcc bzImage
make CC=/usr/local/gcc-graph/bin/gcc modules

生成调用图:
  genfull -s "mm include/linux drivers/block arch/i386 fs init lib kernel net ipc"
这里使用了-s选项,虽然仍然会产生冲突,但是对于kernel的基本部分来说多数还是没
有冲突的。这里的选择也是为了自己将来分析kernel用,你可以根据自己的需要来生成
full.graph。

生成了full.graph后调用gengraph生成alloc_pages的函数调用图,这里我们先直
接使用项目网站上使用的命令,然后再进行解释:
        gengraph -f alloc_pages -d 5
          -t -s "buffered_rmqueue out_of_memory try_to_free_pages numa_node_id"
          -i "cpuset_zone_allowed"
          --output-font "Arial" –output-type "png"
          

选项:
 -d 指定最大调用层数
 -s 仅仅显示指定函数,而不对其调用进行展开
 -i 忽略指定函数
 
  gengraph -f alloc_pages -d 3 -t --output-font="Arial" --output-type="png"


albertsteven

http://hi.baidu.com/albertsteven/home
周勇胜的Blog

http://blog.csdn.net/chow288/article/details/5631667


CodeViz —— 一款分析C/C++源代码中函数调用关系的调用图生成工具
程序开发中,有时候需要阅读别人的代码,这时理解代码的组织结构就显得非常重要。
CodeViz是一款分析C/C++函数调用关系的调用图生成工具,非常有助于代码的阅读和
理解,该项目网址为http://www.csn.ul.ie/~mel/projects/codeviz。
下图是项目网站上给出的一个kernel-2.6.12中alloc_pages函数调用图例,从中可以
清晰的把握函数调用关系:
该调用图的生成命令为:
gengraph -f alloc_pages -d 5
-t -s "buffered_rmqueue out_of_memory try_to_free_pages numa_node_id"
-i "cpuset_zone_allowed" --output-font=Arial –output-type=png
是不是感觉命令非常复杂。没关系,下面讲解了CodeViz的安装和使用后,再回来看这个
命令你会发现它使用起来非常方便。
安装
1. 安装GraphViz
调用图的生成依赖于GraphViz,所以首先要安装GraphViz。若是安装盘上没有,
可以从http://www.graphviz.org下载。可以下载源码包,也可以下载对应发行版的rpm包
或者deb包,这里直接下载源码包:
http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.20.2.tar.gz
安装:
tar graphviz-2.20.2.tar.gz
cd graphviz-2.20.2
./configure (该步可以看出graphviz支持多种语言,但需要相应的插件支持)
make
su (安装graphviz需要在/usr/local下创建目录和文件)
make install
安装完毕,检测一下whereis graphviz,你将看到:
graphviz: /usr/local/lib/graphviz
2. 简单安装CodeViz
这可不是简化安装,该做的都做了,只是让脚本自动完成而已:
wget http://www.csn.ul.ie/~mel/projects/codeviz/codeviz-1.0.11.tar.gz
tar zxvf codeviz-1.0.11.tar.gz
cd codeviz-1.0.11
./configure (缺省将codeviz安装到/usr/local目录下,而需要的gcc编译器
安装到$HOME/gccgraph目录下。可以通过./configure --help查看缺省配置。)
make
su (缺省安装到/usr/local目录下,需要root权限)
make install
实际上这里会自动下载gcc源码包并安装,所以只要安装了graphviz,按照这些
步骤整个安装过程就算结束了,可以使用了,非常简洁。下面为了清楚一下整个过程做一
下分步安装。
3. 下载GCC 编译器
CodeViz使用了一个patch版本的GCC编译器,而且不同的CodeViz版本使用的
GCC版本也不同,可以下载CodeViz的源码包后查看Makefile文件来确定要使用的GCC版
本,codeviz-1.0.11使用GCC-3.4.6。实际上安装CodeViz时安装脚本会自动下载对应的GCC
并打patch,但是这里我们是分步安装,还是清楚一点好。 此外要注意安装脚本使用的是.
tar.gz文件。
ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-3.4
.6/gcc-3.4.6.tar.gz
4. 安装CodeViz
安装GCC
CodeViz的安装脚本compilers/install_gcc-3.4.6.sh会自动检测compilers目录下
是否有gcc的源码包,若是没有则自动下载并打patch,这里前面已经下载,直接移到该
目录即可,则剩下的就是解压安装了。install_gcc-3.4.6.sh会解压缩gcc,打patch,并将
其安装到指定目录,若是没有指定目录,则缺省使用$HOME/gcc-graph,通常指定/usr/
local/gcc-graph(这时需要root权限)。
tar zxvf codeviz-1.0.11.tar.gz
mv /[path]/gcc-3.4.6.tar.gz codeviz-1.0.11/compilers
cd codeviz-1.0.11/compilers
./install_gcc-3.4.6.sh /usr/local/gcc-graph
安装CodeViz
cd codeviz-1.0.11
./configure –gccgraph=/usr/local/gcc-graph
(前面已经安装了gcc,指定其目录)
# --prefix=$HOME/codeviz (指定安装目录,缺省/usr/local目录下)
# --help 查看配置选项
# make (这里不需要是因为在脚本中不会检测是否已经make了gcc-3.4.6,前
面已经作过了,所以只要安装codeviz即可。编译的目标只是gcc-3.4.6,codeviz不需要编
译。具体查看Makefile文件)
make install-codeviz (前面已经安装了gcc,所谓的安装codeviz只是将
脚本genfull和gengraph复制到/usr/local/bin目录下。codeviz需要perl库的支持,我
的系统上缺省安装了perl,所以没有出现什么问题。若是安装出现问题,则查看
configure和Makefile确定需要安装哪些库即可)
注:实际上通过使用脚本,整个安装过程十分简单,这里只是简单的分析了一下
整个安装过程。要进行实际的定制安装建议阅读codeviz中的安装脚本和配置文件,例如
configure脚本、 Makefile文件和compilers目录下的 install_gcc-3.4.6.sh脚本。具体分
析这里不再详述。
好了,CodeViz安装完成了,下面看一下它的使用吧。
使用
GraphViz支持生成不同风格的调用图,但是一些需要安装额外的支持工具或者库程序,
有兴趣的读者可以到http://www.graphviz.org上查找相关资料。这里重点讲述CodeViz的
使用方法,具体的图像风格控制不再详述。
CodeViz使用两个脚本来生成调用图,一个是genfull,该脚本可以生成项目的完整调
用图,因此调用图可能很大很复杂,缺省使用cdepn文件来创建调用图;另一个是
gengraph,该脚本可以对给定一组函数生成一个小的调用图,还可以生成对应的
postscript文件。安装时这两个脚本被复制到/usr/local/bin目录下,所以可以直接使用
而不需要指定路径。
编译
打了patch的gcc/g++为编译的每个C/C++文件生成.cdepn文件,该文件包含函数调
用信息、声明信息等等。注意到patch的gcc安装到了/usr/local/gcc-graph目录下。多
数项目使用变量CC表示要使用的gcc,所以使用patch的gcc的最方便的方法是
make CC=$HOME/gcc-graph/bin/gcc CXX=$HOME/gcc-graph/bin/g++
或者调整路径变量让你安装的gcc目录出现到系统缺省的gcc目录之前
PATH=/usr/local/gcc-graph/bin:$PATH
若是项目没有使用CC或者CXX宏,则需要你来编辑Makefile文件或者设置路径变量。
文件编译时生成对应的cdepn文件。
下面写一个简单的程序来实验一下:
#include <stdio.h>
void test(void);
int
main(void)
{
test();
return 0;
}
void test()
{
return;
}
编译$/usr/local/gcc-graph/bin/gcc test.c,这时可以看到test.c文件所在目录生成文
件test.c.cdepn。编译成功!
生成调用图
前面已经有了test.c.cdepn文件,下面生成函数调用图。
首先使用genfull创建full.graph文件,可以使用genfull --help或者genfull --
man来查看如何使用。最简单的方式是在项目的顶级目录以无参数方式运行。由于项目的
完全调用信息非常庞大,所以通常只是简单的生成项目的full.graph,然后在后面使用
gengraph获取需要的调用信息。若是需要完整信息则将full.graph由dot处理然后查看
生成的postscript文件。(dot是GraphViz中的一个工具,具体使用没有深究过,感兴趣
的读者可以自行查阅^^)。到test.c文件所在目录运行genfull,可以看到生成了
full.graph文件。
查看full.graph文件cat full.graph可以得到:
digraph fullgraph {
node [ fontname=Helvetica, fontsize=12 ];
"test" [label="test\ntest.c:13:"];
"main" [label="main\ntest.c:6:"];
"main" -> "test" [label="test.c:8"];
}
接下来使用gengraph生成函数调用图,可以使用gengraph –help或者gengraph –
man来查看如何使用。这里关注3个选项:-f,指定顶级函数;-o,指定输出的postfile
文件名;--output-type,指定输出类型,例如png、gif、html和ps,缺省为ps。
执行gengraph -f main,可以看到test.c所在目录下生成了main.ps文件,清楚的描
述了函数调用关系。
使用进阶
选项参数
使用gengraph时的选项使用的参数值要使用“”括起来,例如
gengraph –output-type “png” -f main
命名冲突
在一个复杂的项目中,full.graph并不十分完美。例如,kernel中的模块有许多同名
函数,这时genfull不能区分它们。有两种方法可以解决这个问题。
第一种方法,将由cdepn生成的图与cobjdump生成的图作比较。因为cobjdump是分
析二进制映像得到的信息,所以出错的可能性比较小,只是没有inline函数和宏的信息。
例如,在内核中可以这样:
genfull -g cobjdump -o full.graph-objdump
genfull -g cdepn -o full.graph-cdepn
gengraph -t -d 5 -g full.graph-objdump -f kswapd -o kswapd-objdump.ps
gengraph -t -d 5 -g full.graph-cdepn -f kswapd -o kswapd-cdepn.ps
这里生成了两个调用图,可以通过比较来确保准确性。
另一种方法是使用genfull的-s选项,-s指定了检测哪些子目录。例如kernel中在
mm目录和drivers/char/drm目录下都定义了alloc_pages函数,那么可以以下列方式调用
genfull:
genfull -s "mm include/linux drivers/block arch/i386"
实际的使用中,-s非常方便,建议使用该方式。
使用Daemon/Client 模式
当full.graph很大时,大量的时间花费到读取输入文件上了,例如kernel的
full.graph是很大的,前面生成的大约有15M,这还不是全部内核的函数调用分析信息。
为了节省时间,可以将gengraph以daemon方式运行,这要使用-p选项:
gengraph -p -g linux-2.6.25/full.graph
该命令返回时gengraph以daemon方式运行,同时在/tmp目录下生成了codeviz.pipe文件。
要生成函数调用图,可以使用-q选项:
gengraph -q -t -d 2 -f alloc_pages
要终止gengraph的运行,使用如下命令:
echo QUIT > /tmp/codeviz.pipe
一个例子
现在我们来看如何生成内核的函数调用图,以2.6.25中alloc_pages函数为例。
首先是编译内核,这里我们的目的是查看函数调用关系,并非安装新内核,所以直接
进行配置编译:
make menuconfig
make CC=/usr/local/gcc-graph/bin/gcc bzImage
make CC=/usr/local/gcc-graph/bin/gcc modules
生成调用图:
genfull -s
"mm include/linux drivers/block arch/i386 fs init lib kernel net ipc"
这里使用了-s选项,虽然仍然会产生冲突,但是对于kernel的基本部分来说多数还是没
有冲突的。这里的选择也是为了自己将来分析kernel用,你可以根据自己的需要来生成
full.graph。
生成了full.graph后调用gengraph生成alloc_pages的函数调用图,这里我们先直
接使用项目网站上使用的命令,然后再进行解释:
gengraph -f alloc_pages -d 5
-t -s "buffered_rmqueue out_of_memory try_to_free_pages numa_node_id"
-i "cpuset_zone_allowed"
--output-font "Arial" –output-type "png"
这时生成了alloc_pages.png文件,用图像查看器查看,你会发现图非常复杂,而且不好
显示。这是因为与kernel-2.6.12相比,kerne-2.6.25已经变化了很多,前面指定的一些函
数可能已经不存在或者变换了调用关系。不要紧,我们先讲解该命令是如何定制的,然后
再调整命令来生成适合2.6.25内核版本的alloc_pages函数调用图。
Step 1: gengraph -f alloc_pages
不足:花费时间太长,而且可能有很深的调用层次,导致调用图十分复杂。
Step 2: gengraph -d 5 -f alloc_pages
不足:调用图非常复杂,主要是有很多无意义的工具函数。
Step 3: gengraph -d 5 -t -f alloc_pages
不足:调用图还是很复杂,因为有些函数展开后很复杂,可以只是显示它的
存在,而不展开调用图
Step 4: gengraph -d 5 -t
-s "buffered_rmqueue out_of_memory try_to_free_pages numa_node_id"
-f alloc_pages
不足:函数调用的底层有些函数重复,只是不同的调用方式,比较混乱,可
以忽略这些函数
Step 5: gengraph -d 10 -t
-s "buffered_rmqueue out_of_memory try_to_free_pages numa_node_id"
-i "cpuset_zone_allowed"
-f alloc_pages
-d 指定最大调用层数
-s 仅仅显示指定函数,而不对其调用进行展开
-i 忽略指定函数
注:定制命令的标准是函数调用图简单明了,易于把握,否则就没有意义了
现在知道如何定制命令了,那来生成kernel-2.6.25中alloc_pages函数的调用图吧,
具体的分析过程不描述了,这里直接给出一个简单的定制命令:
gengraph -f alloc_pages -d 3 -t --output-font="Arial" --output-type="png"
对应的函数调用图如下:
是不是太简单了,呵呵,偷一下懒吧,该函数太复杂了,读者可以自行把握,根据自己的
需要设置参数。
小结
本文简单讲解了CodeViz的安装和使用。CodeViz依赖于GraphViz,因而可以生成十
分丰富的函数调用图。具体选项的使用以及图像格式的选择可由读者根据个人需要和喜好
自己揣摩使用。
参考
1. Understanding the Linux Virtual Memory Manager, Mel Gorman
2. http://www.csn.ul.ie/~mel/projects/codeviz

原创粉丝点击