如何在 Valgrind 上设置分析的开始和结束

How to set start and end of profiling on Valgrind

要在 valgrind 上创建配置文件转储,请执行以下操作:

valgrind --tool=callgrind 程序 [program_options]

[来自 http://valgrind.org/docs/manual/cl-manual.html]

我想在一些源文件中设置分析的开始和结束。例如

开始main.cpp:30 停止 main.cpp:44

我想这已经在 Android 上使用这种技术进行了分析。这在 Valgrind 上可行吗?

根据参考手册http://valgrind.org/docs/manual/cl-manual.html#cl-manual.basics,您至少可以根据自己的客户请求启动和停止分析:

If the program section you want to profile is somewhere in the middle of the run, it is beneficial to fast forward to this section without any profiling, and then enable profiling. This is achieved by using the command line option --instr-atstart=no and running, in a shell: callgrind_control -i on just before the interesting code section is executed. To exactly specify the code position where profiling should start, use the client request CALLGRIND_START_INSTRUMENTATION.

http://valgrind.org/docs/manual/cl-manual.html#cr.start-instr

CALLGRIND_START_INSTRUMENTATION Start full Callgrind instrumentation if not already enabled. When cache simulation is done, this will flush the simulated cache and lead to an artifical cache warmup phase afterwards with cache misses which would not have happened in reality. See also option --instr-atstart.

CALLGRIND_STOP_INSTRUMENTATION Stop full Callgrind instrumentation if not already disabled. This flushes Valgrinds translation cache, and does no additional instrumentation afterwards: it effectivly will run at the same speed as Nulgrind, i.e. at minimal slowdown. Use this to speed up the Callgrind run for uninteresting code parts. Use CALLGRIND_START_INSTRUMENTATION to enable instrumentation again. See also option --instr-atstart.