Tags:
tag this topic
create new tag
view all tags
[[http://valgrind.org/][Valgrind]] is a software suite that includes many useful tools, like a memory checker and a cache profiler. ---+++++ Installation I'm not really sure how to install this on Windows. I've only installed this on my own machine running Ubuntu 9.10. To install, just open a terminal and type: * =sudo apt-get install valgrind= and it should do the rest. I also find [[http://kcachegrind.sourceforge.net/html/Home.html][KCacheGrind]] to be a very useful tool for visualizing the output of Callgrind. Installation instructions can be found [[http://kcachegrind.sourceforge.net/html/Installation.html][here]], but I also just used apt-get: * =sudo apt-get install kcachegrind=. ---+++++ Memcheck usage Memcheck is used for checking for memory leaks and memory errors, and is also useful for debugging segmentation faults. Basic usage of memcheck is: * Compile your code with =-g -O0= flags. =-g= enables debugging mode and allows memcheck to display line numbers. =-O0= compiles with no optimizations; higher levels can be used, but you might get false positives. Memcheck recommends using less than level O2. * Note: compiling with these flags can be done by setting the =CMAKE_CXX_FLAGS= and =CMAKE_C_FLAGS= variables in the main =CMakeLists.txt= file. Better yet, set a =CMAKE_CXX_FLAGS_DEBUG= and =CMAKE_C_FLAGS_DEBUG= and configure using =ccmake= to use compile a Debug version. * Run =valgrind [program]=, where =[program]= is what you would normally type to run your program, including all flags and arguments. This will give you a summary of memory leaks and basic memory errors. * If you get memory leaks, try running =valgrind --leak-check=full [program]= to see exactly where leaks are happening. I believe this will make your program run a lot slower, so you may have to sit around and wait for a while. If it's too slow, try compiling with a higher optimization level. [[http://valgrind.org/docs/manual/mc-manual.html#mc-manual.overview][Here]]'s a nice overview of memcheck in general. Section 4.2 will give you a basic description of all the error messages, while section 4.3 will give you more command line options. ---+++++ Callgrind usage Callgrind is used for profiling your program. To use: * Compile code with =-g= flag. * Run =valgrind --tool=callgrind [program]=, where =[program]= is what you would normally type to run your program, including all flags and arguments. * A file should be generated in your current working directory called =callgrind.out.[pid]=, where =[pid]= is the pid of the process you just profiled. * If you have kCacheGrind installed, you should be able to run the file just by double-clicking it, or type in the console: =kcachegrind callgrind.out.[pid]=. * If everything worked, you should now get a nice GUI view of your program's profile. * "Incl." is the time the function/method takes to run + the time all the functions it calls takes to run. * "Self" is the time the function/method takes to run excluding all functions it calls. * "Called" is the number of times the function was called.
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2010-05-25
-
jayzhang
Home
Site map
BETA web
Communications web
Faculty web
Imager web
LCI web
Main web
SPL web
Sandbox web
TWiki web
TestCases web
BETA Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback