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 | make[3]: Nothing to be done for `all-am'. |
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 |