学一下gconv, gprof等知识

scons、gcc、gdb、valgrind、gcov

 

SCons 是一个用 Python 语言编写的类似于 make 工具的程序。与 make 工具相比较,SCons 的配置文件更加简单清晰明了。

 

gconv 覆盖率

(1) 编译

 

# gcc -fprofile-arcs -ftest-coverage -o test test.c

# ls

test  test.c  test.gcno

-fprofile-arcs -ftest-coverage告诉编译器生成gcov需要的额外信息,并在目标文件中插入gcov需要的extra profiling information。因此,该命令在生成可执行文件test的同时生成test.gcno文件(gcov note文件)

 

(2) 收集信息

# ./test

Success

# ls

test  test.c  test.gcda  test.gcno

执行该程序,生成test.gcda文件(gcov data文件)

 

(3) 报告

# gcov test.c

File 'test.c'

Lines executed:87.50% of 8

test.c:creating 'test.c.gcov'

 

# ls

test  test.c  test.c.gcov  test.gcda  test.gcno

 

3.2 gcov的选项

(1) -a, --all-blocks

(2) -b, --branch-probabilities

(3) -c, --branch-counts

 

gprof 性能分析

一般用法: gprof –b 二进制程序 gmon.out >report.txt

 

有一个方法可以查看应用程序的运行时间组成,在 time 命令下面执行程序。这个命令会显示一个应用程序的实际运行时间、用户空间运行时间、内核空间运行时间。

如 time ./program

输出:

real    2m30.295s

user    0m0.000s

sys     0m0.004s

 

posted @ 2017-03-02 12:03  blcblc  阅读(1453)  评论(0编辑  收藏  举报