Valgrind Memory Check Parser

Complete: 3

Valgrind Memcheck produces a large output which is hard and time consuming to read through manually.

As often developers are interested in memory leaks in just a specific part of the code, scripts have been designed to filter the logs and produce an HTML output, possibly integrated with a graphical display of the leaks using graphviz. (HTML output only)

The program, can be found in Utilities/ReleaseScripts/scripts, and can run on any lx64slc4 machine (or on whatever machine that has the needed perl modules: CGI, Date::Format, Getopt::Long); a CSS stylesheet is also provided in the Utilities/ReleaseScripts/data folder to have a more readable output.

The syntax of the program is ./ [options] logfile > outfile.html

In order to have a full list of options, just call ./ -h | more


Filters are available both at library level (using -l option) and at stack trace level (using -t); the argument of the option is a PERL-compatible regexp that must match in order to have the leak reported.

If one instead wants to exclude from the report all leaks which match the specified regexp, it's enough to prefix the option with a minus sign. (i.e. -t -TCint to exclude everything which has "TCint" in the stack trace)

Multiple filters can be specified either with multiple "-t" options, or by putting the regexps separated by comas as "-t reg1,reg2,-reg3"


Filtering in or out some common patterns, like EDProducers and ESProducers, or excluding ROOT internals, might require a large number of filters, so pre-configured lists of filters are already available and callable with a simple syntax --preset something

The list of presets can be obtained again through ./ -h, and it is possible to find out the list of regexps in each preset using ./ --dump-preset name.

Presets can be prefixed by a minus sign, to exclude any item for which at least one of the regexps match, or a plus sign to require all the regexps to match each leak.

Standard presets for CMSSW

  • To look for leaks in EDProducers, including those within EventSetup: --preset=prod
  • To look for leaks in EDProducers, excluding as much as possible those from EventSetup: --preset=prod,-prod1+ (-prod1 without the + is an older preset which leaves some more ES stuff in)
  • To get leaks from EventSetup which you excluded in the step before: --preset=prod,prod1+

Finding other types of memory bugs can also look for other types of bugs. The type of bug to search for can be specified using a command line option (no option means look for leaks)

  • --uninitialized or -u: uses of uninitialized memory
  • --free or -f: bad uses of free()

This features are not supported in the


The output HTML page is linked to LXR; by using the --rel option it is possible to choose the CMSSW release appropriate for the linking. (graphical output)

This new script displays the stack traces of the memory leaks graphically as trees, using graphviz.

This can be useful when the leak of a big object causes the loss of many other ones, and thus multiple leaks: by inspecting the plot one can get hints on where the first leak was.

The stack trace elements are displayed as orange boxes if there is a leak originating in that element, otherwise they're in green; clicking on the boxes brings you to the list of stack traces where a specific element appears, and from there other links allow to see the individual stack traces as in uses much of the code of , so its usage is similar.

The notable differences are:

  • instead of dumping an HTML to standard output, it writes some files to a directory specified using the --out command line option
    if the directory is not already there, it is created by the program.
  • this program can't search for uninitialized memory or bad free() , only for memory leaks
  • if there are too many leaks passing the selection, the program could crash due to graphviz failing to produce the plot.
  • you need a version of graphviz with libpng, which is not provided on lx64slc4. If you don't have one already, you can use one from my afs area with
      export LD_LIBRARY_PATH=/afs/${LD_LIBRARY_PATH}
      export PATH=/afs/${PATH}
(use setenv instead of export if you have tcsh instead of bash)

Review Status

Editor/Reviewer and date Comments
GiovanniPetrucciani - 11 Jun 2007 First version
GiovanniPetrucciani - 28 Mar 2008 Expanded documentation, added graphic script

Responsible: GiovanniPetrucciani
Last reviewed by:

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2008-03-28 - GiovanniPetrucciani

    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback