配置文件共享对象,无需重新编译主程序
我目前正在开发一个用于加载到 PostgreSQL 的共享库(作为 C 语言函数,请参阅
我尝试使用 callgrind
valgrind --tool=callgrind path/to/postgres arguments-to-postgres
这为我提供了 PostgreSQL 本身的分析信息,但无法记录我感兴趣的共享库。
我也尝试过 sprof,但我不知道如何让该库工作。
任何想法都会受到高度赞赏。
PS:请不要建议只是在调试器中暂停应用程序。由于函数运行时间低于 0.01 秒,我需要更详细的结果。
I currently am developing a shared lilbrary for loading into PostgreSQL (as C-Language functions, see here). Now I would like to profile the function in this library without recompiling PostgreSQL itself.
I tried callgrind using
valgrind --tool=callgrind path/to/postgres arguments-to-postgres
This gives me profiling information for PostgreSQL itself, but fails to log the shared library I am interested in.
I also tried sprof
, but I have no idea how to get that one working.
Any ideas would be highly appriciated.
P.S.: Please do not suggest just pausing the application in a debugger. With function runtimes way below 0.01 seconds I need more detailled results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 callgrind 应该可以按预期工作。为了测试这一点,我使用简单的库和主函数Makefile设置了一个简单的项目:
lib.c是一个包含2个函数的简单库:
exe.c是一个非常简单的可执行文件:
使用Makefile构建可执行文件并使用valgrind运行它,如下所示:
如果检查 callgrind 输出,您将在共享库中找到这两个函数的分析数据。如果您看不到这些功能,您可能正在使用不支持此功能的非标准环境。我使用的是 Linux Mint 11 x64,带有最新的补丁。
Using callgrind should work as expected. To test this I setup a simple project using a simple library and main functionMakefile:
lib.c is a simple library containing 2 functions:
exe.c is a very simple executable:
Use the Makefile to build the executable and run it using valgrind like so:
If you examine the callgrind output, you will find the profiling data for both functions in the shared library. If you cannot see these functions you may be using a non-standard environment that does not support this functionality. I'm using Linux Mint 11 x64, with the latest patches.
第 1 点:Valgrind 似乎存在权限升级问题,这很可能是由 Postgres 执行的,请参阅 http://www.mail-archive.com/[email protected]/msg02355.html
第 2 点:您是否尝试证明(例如使用strace)你的SL实际上是在同一个进程中加载的?您是否尝试过 --trace-children=yes ?
第3点:我尝试通过使用-g0编译exe.o和exe并使用dlopen加载文件来修改测试,即:
并
与callgrind一起使用。也许 Postgres 没有使用 -ldl 来打开目标文件?
Point 1: Valgrind seems to have issues with privilege escalation, which is VERY likely to be performed by Postgres, see http://www.mail-archive.com/[email protected]/msg02355.html
Point 2: Have you tried to prove (e.g. with strace) that your SL is actually loaded in the same process? Have you tried to --trace-children=yes?
Point 3: I've tried to modify the test by compiling exe.o and exe with -g0 and using dlopen to load the file, i.e.:
and
Works with callgrind. Maybe Postgres is not using -ldl to open the object files?