Static Oneplus 不可控制论

2014/11/27 - by Oneplus • valgrindcppprofiling

Valgrind Cheatsheet

Valgrind is a great tools for dynamic checking.

Basic Usage

The most basic use of valgrind is checking memory leak.

valgrind --tool=memcheck --leak-check=full <program>

Profiling with calgrind

The second use of valgrind is to show the dynamic running time for certain function and the invoking relation between functions.

valgrind --tool=callgrind <program>

To visualize the calgrind result, my best practice is an combination and graphviz. can be obtained from pypi or the project homepage. Luckily, the author is still maintaining this tools.

Combining these tools can be easily done by the following commands:

valgrind --tool=callgrind --callgrind-out-file=/tmp/callgrind.output <program>
./ --format=callgrind --output=/tmp/ -w /tmp/callgrind.output
dot -Tpng -o /tmp/graph.png /tmp/

At the end, you will get a .png file representing the function executing time and relations between their invoking.

blog comments powered by Disqus