VALGRIND
============
We will use valgrind with following tools :-
> memcheck [default]
> callgrind
> cachegrind
> massif
> helgrind
valgrind --tool=memcheck [prog-name] [prog-argumements]
a simple example is valgrind --tool=memcheck ls -al
===================================================
nemesis@nemesis-laptop:~$ valgrind --tool=memcheck ls -al
==3497== Memcheck, a memory error detector
==3497== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==3497== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==3497== Command: ls -al
==3497==
total 13300
==3497==
==3497== HEAP SUMMARY:
==3497== in use at exit: 14,671 bytes in 95 blocks
==3497== total heap usage: 1,902 allocs, 1,807 frees, 150,632 bytes allocated
==3497==
==3497== LEAK SUMMARY:
==3497== definitely lost: 200 bytes in 3 blocks
==3497== indirectly lost: 240 bytes in 20 blocks
==3497== possibly lost: 0 bytes in 0 blocks
==3497== still reachable: 14,231 bytes in 72 blocks
==3497== suppressed: 0 bytes in 0 blocks
==3497== Rerun with --leak-check=full to see details of leaked memory
==3497==
==3497== For counts of detected and suppressed errors, rerun with: -v
==3497== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 10)
===================================================
[NOTE]: In the above trace "3497" which precedes every line of Valgrind output is the pid of the program being run under valgrind i.e. ls -al in this case.
PRE-REQUISITES
==============
1. Strongly recommended to run the program with -g (with debug symbols) option. It is generally true of all profiling tools.
2. Use no optimization or as a compromise -0
No comments:
Post a Comment