gprof:如何为链接到主程序的共享库中的函数生成调用图 [英] gprof : How to generate call graph for functions in shared library that is linked to main program
问题描述
- 列车包编译时生成libtrain.so
- test_train链接到libtrain.so并生成可执行列车测试
现在我想使用gprof生成一个调用图,显示在主程序中调用函数序列以及libtrain.so中的函数序列
我正在使用-pg选项编译和链接这两个软件包,调试级别为o0。
我做了./train-test之后,生成了gmon.out。然后我做:
$ gprof -q ./train-test gmon.out
这里,输出显示列车测试中功能的调用图,但不显示在libtrain.so中。
什么可能是问题?
gprof
将无法正常工作,您需要使用 sprof
。我发现这些链接有帮助:
第二个链接的摘要:
- 在调试(-g)模式下编译共享库(libmylib.so)。导出LD_PROFILE = libmylib.so
- 导出LD_PROFILE_OUTPUT =`pwd`
- -f $ LD_PROFILE.profile
- 执行加载libmylib.so的程序
- sprof PATH-TO-LIB / $ LD_PROFILE $ LD_PROFILE.profile - p> log
- 查看日志
我发现在步骤2中,成为现有的目录 - 否则你会得到一个有用的警告。而在第3步中,您可能需要将库指定为 libmylib.so.X
(甚至可以 .XY
不确定) - 否则你不会收到任何警告。
I am working on Linux environment. I have two 'C' source packages train and test_train.
- train package when compiled generates libtrain.so
- test_train links to libtrain.so and generates executable train-test
Now I want to generate a call graph using gprof which shows calling sequence of functions in main program as well as those inside libtrain.so
I am compiling and linking both packages with -pg option and debugging level is o0. After I do ./train-test , gmon.out is generated. Then I do:
$ gprof -q ./train-test gmon.out
Here, output shows call graph of functions in train-test but not in libtrain.so
What could be the problem ?
gprof
won't work, you need to use sprof
instead. I found these links helpful:
- How to use sprof?
- http://greg-n-blog.blogspot.com/2010/01/profiling-shared-library-on-linux-using.html
Summary from the 2nd link:
- Compile your shared library (libmylib.so) in debug (-g) mode. No -pg.
- export LD_PROFILE_OUTPUT=`pwd`
- export LD_PROFILE=libmylib.so
- rm -f $LD_PROFILE.profile
- execute your program that loads libmylib.so
- sprof PATH-TO-LIB/$LD_PROFILE $LD_PROFILE.profile -p >log
- See the log.
I found that in step 2, it needs to be an existing directory -- otherwise you get a helpful warning. And in step 3, you might need to specify the library as libmylib.so.X
(maybe even .X.Y
, not sure) -- otherwise you get no warning whatsoever.
这篇关于gprof:如何为链接到主程序的共享库中的函数生成调用图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!