gprof a library - question

青春壹個敷衍的年華 提交于 2019-12-06 02:49:01

问题


I need to gprof a library in our system to examine the function calls and see if we can optimize it any more. Basically, what I have is

Executable A which uses a shared Library myLib.so

I want to gprof the myLib.so. When I compile myLib.so source using -pg option, it produces a .so file just fine.

But, recompiling the Executable A against that library is not producing the *.gmon file for some reason. What needs to be done? Should I link the myLib statically? If so, please tell me how. I am a newbie, so pardon my ignorance. I am learning everyday

thanks in advance.


回答1:


You can do better than gprof.

You could use a good sampling profiler like RotateRight/Zoom, or you could try this technique. Also lsstack serves well. pstack does too, but is more work for you.




回答2:


I have the same issue, but I think the best thing to do is to create a small C/C++ program that uses the library with some test calls, compile it with the library using -pg, and profile that. That way you nicely isolate the profiling issues of the library from other stuff, too.

As http://sourceware.org/binutils/docs/gprof/Implementation.html and https://stackoverflow.com/a/7290284/885650 point out, you need -pg when linking, as it adds extra code everywhere.



来源:https://stackoverflow.com/questions/2434488/gprof-a-library-question

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