ubuntuvalgrind

Set callgrind as default tool of valgrind


I need to profile a program with callgrind which is started by some script, I don't have control over. I can tell the script to start valgrind, but I cant tell the script which tools or parameters to use.

I found in the valgrind manual (section 2.7.7, "Setting Default Options"), that it is possible to use a variable $VALGRIND_OPTS, or a .valgrindrc file. This works for tool specific options. For instance, I can write in the ~/.valgrindrc

--callgrind:callgrind-out-file=<somefile>

And when I execute some test program a.out

valgrind --tool=callgrind a.out

the output file is written as defined in .valgrindrc. But I can't specify the tool (callgrind) I want to use.

I have tried:

--tool=callgrind

and

--valgrind:tool=callgrind

Both have no effect and memcheck is started as default. Any hints would be appreciated!


Solution

  • You can create an alias in your shell:

    $ alias valgrind="valgrind --tool=callgrind"
    

    and call the script:

    $ ./the_script
    

    The alias will get expanded to valgrind --tool=callgrind inside the script.