如何在不分析主机应用程序的情况下分析共享对象?
我有一个主机应用程序,并且编写了一个插件。我将插件编译为共享对象(例如 foo.so),主机应用程序将通过 dlopen 加载它。在这种情况下,我的主机应用程序是来自 llvm 的 opt 工具(尽管我认为这对这个问题并不重要)。
我想在启用分析的情况下编译我的插件(即 g++ -pg
、gprof
)。但是,当我这样做时,配置文件输出文件 gmon.out 永远不会创建。也许 gprof 希望有人调用设置例程或类似的东西。
由于各种原因,我想避免使用 -pg 重新编译主机应用程序。我很好奇是否可以在不分析主机应用程序 opt 的情况下分析共享对象 foo.so 。
我还研究了其他分析工具; HP 的 qprof 应该能够处理这种情况,但它无法解析共享对象中的函数名称(它以一种非常幼稚的方式回退到 addr2line)。
谢谢, 缺口
I have a host application and I have written a plug-in. I compile my plug-in down to a shared object (say foo.so), and the host application will load it via dlopen. In this case, my host application is the opt tool from llvm (though I don't think that's important to the question).
I'd like to compile my plug-in with profiling enabled (i.e. g++ -pg
, gprof
). However, when I do this, the profile output file gmon.out is never created. Maybe gprof expects someone to call a setup routine, or something like that.
For various reasons, I would like to avoid recompiling the host app with -pg. I am curious if it is possible to profile a shared object foo.so without profiling the host application opt.
I've also looked into other profiling tools; qprof from HP should be able to handle this situation, but it is unable to resolve the names of functions in the shared object (it falls back to addr2line in a very naive way).
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您想要这样做的原因是找到优化插件的方法(而不是仅仅获取计时信息)。
您可以在调试器或 IDE 下运行主机应用程序吗? IDE 是否有暂停按钮,或者您可以使用 Ctrl-C 或类似的键来中断它吗?
然后,您可以使用此技术快速找到成本高昂的代码。仅在插件运行时才采集样本,或者如果您无法做到这一点,请忽略不以插件结尾的样本。
即使您使用 gprof 或类似的分析器,您我们可能会失望。
I assume the reason you want to do this is to find ways to optimize the plugin (as opposed to just getting timing information).
Can you run the host app under a debugger or IDE? Does the IDE have a pause button, or can you interrupt it with Ctrl-C or some such key?
Then you can quickly find the costly code by using this technique. Only take samples when your plugin is running, or if you can't do that, just ignore samples that don't end in your plugin.
Even if you get gprof to work, or a similar profiler, you're likely to be disappointed.