如何使用 gperftools 有条件地分析 C++ 代码?

How to use gperftools to conditionally profile C++ code?

我正在尝试 CPU-profile 一个回调驱动的系统,我只对在回调导致我以某种方式做出反应时进行分析感兴趣?我可以使用 gperftools 来完成这个吗?

ProfilerEnable()/ProfilerDisable() 似乎很有希望,但 header 表示这些已被弃用。我什至不确定这些是否有效。

确实 ProfilerEnable/Disable 不再工作了。

已经有 pausing/unpausing 分析 https://github.com/gperftools/gperftools/issues/597 的请求。但请注意,经常这样做 pausing/unpausing 可能会对性能产生影响。

我认为你应该分析你所有的应用程序,然后使用 pprof 的 --focus 功能来过滤掉不感兴趣的部分。