Difference between revisions of "Development/Tools/Valgrind"

Jump to: navigation, search
(use {{file}})
(Add --track-origins flag for valgrind)
 
(One intermediate revision by one user not shown)
Line 10: Line 10:
 
As valgrind can produce a lot of output (and thus scroll out of your terminal), you can call valgrind redirecting its output to a file, so nothing gets lost.
 
As valgrind can produce a lot of output (and thus scroll out of your terminal), you can call valgrind redirecting its output to a file, so nothing gets lost.
 
  > valgrind --tool=memcheck --leak-check=yes -v ''appname'' 2>&1 | tee valgrind.log
 
  > valgrind --tool=memcheck --leak-check=yes -v ''appname'' 2>&1 | tee valgrind.log
This will call valgrind as seen above, and will redirect all the output coming from both our application and valgrind to a file in the current directory called {{file|valgrind.log}} (of course it is possible to use any file name of the log).
+
This will call valgrind as seen above, and will redirect all the output coming from both our application and valgrind to a file in the current directory called {{path|valgrind.log}} (of course it is possible to use any file name of the log).
  
 
=== Minor tweaks ===
 
=== Minor tweaks ===
  
 
* executing valgrind with <tt>--leak-check=full</tt> instead of <tt>--leak-check=yes</tt> can give a more detailed output, especially about the found leaks
 
* executing valgrind with <tt>--leak-check=full</tt> instead of <tt>--leak-check=yes</tt> can give a more detailed output, especially about the found leaks
 +
 +
* Using the <tt>--track-origins=yes</tt> flag is even slower than normal Valgrind but gives you the location where the memory used incorrectly was allocated in many situations.
  
 
== References ==
 
== References ==
 
* [http://www.valgrind.org/ The Valgrind Homepage]
 
* [http://www.valgrind.org/ The Valgrind Homepage]
 
* [http://www.tldp.org/HOWTO/Valgrind-HOWTO/ Excellent tutorial at TLDP]
 
* [http://www.tldp.org/HOWTO/Valgrind-HOWTO/ Excellent tutorial at TLDP]

Latest revision as of 03:44, 16 July 2009

Valgrind is a tool to analyze a program regarding memory leaks.

[edit] Leak Detection

One of the valgrind tools is the memcheck, that can be used to detect memory leaks during the execution of an application.

To do that, valgrind can be started as:

> valgrind --tool=memcheck --leak-check=yes -v appname

where appname is the application you want to run, including its parameters, if it have to be called with any.

As valgrind can produce a lot of output (and thus scroll out of your terminal), you can call valgrind redirecting its output to a file, so nothing gets lost.

> valgrind --tool=memcheck --leak-check=yes -v appname 2>&1 | tee valgrind.log

This will call valgrind as seen above, and will redirect all the output coming from both our application and valgrind to a file in the current directory called valgrind.log (of course it is possible to use any file name of the log).

[edit] Minor tweaks

  • executing valgrind with --leak-check=full instead of --leak-check=yes can give a more detailed output, especially about the found leaks
  • Using the --track-origins=yes flag is even slower than normal Valgrind but gives you the location where the memory used incorrectly was allocated in many situations.

[edit] References


This page was last modified on 16 July 2009, at 03:44. This page has been accessed 12,733 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal