在程序执行过程中将 callgrind/valgrind 附加到程序

lib*_*.so 2 c++ valgrind callgrind

我使用 Valgrind 通过从头开始运行程序来检测问题。现在我在程序的一个非常特定的时刻遇到了内存/性能问题。不幸的是,没有可行的方法从一开始就可以走捷径到达这个地方。

有没有办法在 c++ 程序( Valgrind/Callgrind )的中途执行中进行检测,例如附加到进程?

已经在这里回答: How use callgrind to profiling only a certain period of programexecution?

phd*_*phd 5

无法在已经运行的程序上使用 valgrind。

然而,对于 callgrind,您可以通过仅在稍后执行期间记录数据来稍微加快速度。

为此,您可以查看 callgrind 选项

    --instr-atstart=no|yes    Do instrumentation at callgrind start [yes]
    --collect-atstart=no|yes  Collect at process/thread start [yes]
    --toggle-collect=<func>   Toggle collection on enter/leave function
Run Code Online (Sandbox Code Playgroud)

您还可以在程序中控制这些方面。

有关更多详细信息,请参阅 valgrind/callgrind 用户手册。