21 septembrie 2016

Valgrind (notite)

VALGRIND
tools available: memcheck (for memory leaks), cachegrind (detects cache misses), massif (heap and stack profiling), helgrind, callgrind, DRD
- cannot be attached to a already running process (Valgrind wants to have full control from the very start)
- results are given for the whole process but you can find the errors coming from a specific shared object
Memcheck
> valgrind --tool=memcheck --leak-check=yes --track-children=yes --log-file=log.txt java Example
Types of errors (counting the occurrences):
  • illegal read/write
    cat log.txt | grep "Invalid" | wc -l
  • use of uninitialised values
    cat log.txt | grep "uninitialised" | wc -l 
Results at the end of log file:
  • definitely lost = program is leaking memory
  • indirectly = leaking memory in a pointer-based structure
  • possibly = leaking memory unless pointers do something awesome
  • still rechable = it just didn't free some memory it could have freed
  • suppressed = to be ignored
Cachegrind
> valgrind --tool=cachegrind --log-file=log.txt java -Djava.library.path=/home/gtache/workspace/MKL/lib Example
Results in the log file, miss rates for L1, L2, L3. 

Massif
valgrind --tool=massif --stacks=yes --time-unit=B --log-file=log.txt java --massif-out-file=massif.out.txt -Djava.library.path=/home/gtache/workspace/MKL/lib Example
Results in massif.out
> vim massif.out  or  ms_print massif.out # snapshots of total memory consumption for heap/stack at different moments of time
  • mem_heap_B = the number of useful heap bytes allocated at that point
  • mem_heap_extra_B = the number of bytes allocated in the excess of what the program asked for (might be associated with alignment)
  • mem_stacks_B = size of the stack
Sometimes it gives the detailed heap tree for a snapshot.
massif_visualizer massif.out # graphical output

Niciun comentariu: