How To Install Valgrind On MacOsX
I have been tested a lot of times to install Valgrind on MacOs and I always got problem. Finally I installed Valgrind without any problem.
It is very easy to install and I want to share with you. Because, Valgrind is wonderful application for detecting memory leak and profiling codes. In my opinion, every C++ developer should have Valgrind on their PC, if there using unix based OS.
Requirements
- XCode
- Git
- root rights (just kidding)
Installing
1 | git clone git://sourceware.org/git/valgrind.git |
If you get exception something like that:1
2
3
4
5make[3]: Nothing to be done for `all-am'.
Making all in coregrind
make[2]: *** No rule to make target `/usr/include/mach/mach_vm.defs', needed by `m_mach/mach_vmUser.c'. Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
it means you are not using latest version of XCode and you need to do execute following shell command.
1 | xcode-select --install |
and then execute make command again. That is all.
Let’s do some small examples.
First we can profile codes line by line.
Create new C/C++ application for testing. I did it as symspelltest application.1
valgrind --tool=callgrind --simulate-cache=yes ./symspelltest
Valgrind generate log file when execution finished.
I assume, you are already installed homebrew.1
brew install qcachegrind --with-graphviz
Now, check call stacks.1
qcachegrind callgrind.out.212