Line number in Google Perftools CPU profiler on MacOSX

前端 未结 2 755
无人共我
无人共我 2021-02-01 08:20

I am trying to profile some C++ programs on MacOSX. So I built google-perftools, wrote a program, compiled using MacPorts g++ 4.7, with -g compiler fla

相关标签:
2条回答
  • 2021-02-01 08:58

    This seems to be related to the address space layout randomization (ASLR) introduced in OS X 10.5

    I've filed issue #562 on the gperftools issue tracker. You can disable ASLR by passing -Wl,-no_pie.

    Also, if you're not bound to use gperftools, Instruments (comes with Xcode) is worth a try.

    0 讨论(0)
  • 2021-02-01 09:05

    I believe in this platform the debug symbols stay in the .o file(s), they are not moved to the executable. To get symbols in gdb or profilers you need to save the .o files. This may mean that you need to compile your application in two steps (compile, then link) to preserve the .o files.

    See this question for additional information.

    In looking at the pprof Perl source code, symbol names are obtained via the use of nm and c++filt, so you could try to run those standalone and figure out why they don't work. From the pprof source it looks like it tries a bunch of different command line arguments to cover several versions of nm. This is a summary of the ways

    nm [-D] -n [-f] [--demangle] object-file 2>/dev/nul [| cpp+filt]

    The parts that I put in brackets are those that the script determines at runtime if are required for your platform and versions of nm and c++filt. Try all the combinations of the above and see what works. Then look at what the pprof script does, maybe by adding some printfs to it.

    Good luck.

    0 讨论(0)
提交回复
热议问题