valgrind基础
valgrind
官網(wǎng)
原理
官網(wǎng)解釋
Your program is then run on a synthetic CPU provided by the Valgrind core. As new code is executed for the first time, the core hands the code to the selected tool. The tool adds its own instrumentation code to this and hands the result back to the core, which coordinates the continued execution of this instrumented code.
stackoverflow解釋
valgrind provides a virtual processor that executes your application. However, before your application instructions are processed, they are passed to tools (such as memcheck). These tools are kind of like plugins, and they are able to modify your application before it is run on the processor.
The great thing about this approach is that you don't have to modify or relink your program at all to run it in valgrind. It does cause your program to run slower, however valgrind isn't meant to measure performance or run during normal execution of your application, so this isn't really an issue.
安裝
源碼地址
使用如下命令更簡單些
yum install valgrind參數(shù)
# When enabled, Valgrind will trace into sub-processes initiated via the exec system call. # This is necessary for multi-process programs. # Note that Valgrind does trace into the child of a fork (it would be difficult not to, # since fork makes an identical copy of a process), so this option is arguably badly named. # However, most children of fork calls immediately call exec anyway.--trace-children=<yes|no> [default: no]Memcheck
功能
使用
#編譯文件,加參數(shù) -g clang++ -g -Wall memcheck_test.cc -o memcheck_test #--tool=memcheck 參數(shù)缺省 #--leak-check=full,內(nèi)存泄的具體信息 #--log-file=log_file.txt,輸出信息重定向到文件中 valgrind --leak-check=full --log-file=log_file.txt memcheck_testHelgrind
功能
使用
valgrind --tool=helgrind memcheck_test如何高效實(shí)用Helgrind
鏈接
callgrind
功能
Callgrind is a profiling tool that records the call history among functions in a program's run as a call-graph.
使用
valgrind --tool=callgrind --separate-threads=yes ./callgrind_test #函數(shù)調(diào)用情況總覽 callgrind_annotate callgrind.out.<pid>#結(jié)合源文件 #注意.cc文件目錄格式要和上面命令產(chǎn)生的路徑格式一致 callgrind_annotate callgrind.out.<pid> callgrind_test.cc使用kcachegrind工具
yum install kcachegrind yum install graphviz kcachegrind callgrind.out.<pid>QA
鏈接
總結(jié)
以上是生活随笔為你收集整理的valgrind基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式——代理模式
- 下一篇: 《慕课React入门》总结