gprof:如何为链接到主程序的共享库中的函数生成调用图 [英] gprof : How to generate call graph for functions in shared library that is linked to main program

查看:178
本文介绍了gprof:如何为链接到主程序的共享库中的函数生成调用图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事Linux环境。我有两个'C'源码包和test_train。


  1. 列车包编译时生成libtrain.so

  2. test_train链接到libtrain.so并生成可执行列车测试

现在我想使用gprof生成一个调用图,显示在主程序中调用函数序列以及libtrain.so中的函数序列



我正在使用-pg选项编译和链接这两个软件包,调试级别为o0。
我做了./train-test之后,生成了gmon.out。然后我做:

  $ gprof -q ./train-test gmon.out 

这里,输出显示列车测试中功能的调用图,但不显示在libtrain.so中。



什么可能是问题?

解决方案

gprof 将无法正常工作,您需要使用 sprof 。我发现这些链接有帮助:





第二个链接的摘要:


  1. 在调试(-g)模式下编译共享库(libmylib.so)。导出LD_PROFILE = libmylib.so

  2. 导出LD_PROFILE_OUTPUT =`pwd`

  3. -f $ LD_PROFILE.profile

  4. 执行加载libmylib.so的程序

  5. sprof PATH-TO-LIB / $ LD_PROFILE $ LD_PROFILE.profile - p> log

  6. 查看日志

我发现在步骤2中,成为现有的目录 - 否则你会得到一个有用的警告。而在第3步中,您可能需要将库指定为 libmylib.so.X (甚至可以 .XY 不确定) - 否则你不会收到任何警告。


I am working on Linux environment. I have two 'C' source packages train and test_train.

  1. train package when compiled generates libtrain.so
  2. 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:

Summary from the 2nd link:

  1. Compile your shared library (libmylib.so) in debug (-g) mode. No -pg.
  2. export LD_PROFILE_OUTPUT=`pwd`
  3. export LD_PROFILE=libmylib.so
  4. rm -f $LD_PROFILE.profile
  5. execute your program that loads libmylib.so
  6. sprof PATH-TO-LIB/$LD_PROFILE $LD_PROFILE.profile -p >log
  7. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆