gperftools - profile file not dumped

我怕爱的太早我们不能终老 提交于 2020-02-28 07:52:08

问题


I've configured and built gpreftools. however, I can't seem to find the generated profile file of my program to display it.

I took the following actions:

  1. Adding the -lprofiler linker flag to my .pro, building the program and the flag is added correctly at the linking stage. QMAKE_LFLAGS += -lprofiler

  2. Running with: $ CPUPROFILE=/tmp/prof.out /path/to/executable

  3. Executing: $ pprof --gv /path/to/MyExe /tmp/prof.out

Then I get the following:

Failed to get profile: curl -s --max-time 90 'http:///pprof/profile?seconds=30' > /home/eslam/pprof/.tmp.MyExe.1509005857.: No such file or directory.

Anyone has a resolve on this?


回答1:


Check that your program actually links to libprofiler.so. Some OSes (e.g. AFAIK some versions of ubuntu) do not actually add .so if none of it's symbols are actually used. E.g. ldd ./yourprogram should list libprofiler.so. If this does not happen, then you should prepend something like -Wl,--no-as-needed to your linker flags.




回答2:


Besides passing -Wl,--no-as-needed,-lprofiler,--as-needed at build time mentioned by Eslam, you can also get it to work without modifying the build by passing the LD_PRELOAD option at runtime as:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libprofiler.so CPUPROFILE=prof.out ./main.out

You can find libprofiler.so easily with locate libprofiler.so.

See also: How can I profile C++ code running on Linux?

Tested in Ubuntu 18.04.



来源:https://stackoverflow.com/questions/46949407/gperftools-profile-file-not-dumped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!