Quick course in using tools for Valgrind. These tools will analyze your program's execution and tell you what parts are running slow. The results are accurate because of the way Valgrind works and help you spot problems such as lines of code that execute too much, hot spots, memory access problems, and even CPU cache misses.
[Callgrind documentation] (http://valgrind.org/docs/manual/cl-manual.html).
Callgrind is a tool in part of the Valgrind toolchain. It is running in Valgrind framework. The principle is not the same. When you use Callgrind to profile an application, your application is transformed in an intermediate language and then ran in a virtual processor emulated by valgrind. This has a huge run-time overhead, but the precision is really good and your profiling data is complete. An application running in Callgrind can be 10 to 50 times slower than normally.
valgrind --tool=callgrind ./HelloC++
kcachegrind
[Memcheck documentation] (http://valgrind.org/docs/manual/mc-manual.html).
Memcheck is a memory error detector. It can detect the following problems that are common in C and C++ programs:
- Accessing memory you shouldn't
- Using undefined values
- Incorrect freeing of heap memory
- Memory leaks
valgrind --tool=memcheck --leak-check=yes --log-file=example.log ./HelloC++