How to install qcachegrind (kcachegrind) on Mac OSX Snow Leopard

Guest post by Mike! I had originally posted this as a gist on github, but Paul selflessly insisted that I blog about it, so here you go.

I like to use kcachegrind for doing profiling of my ruby code via ruby-prof. This works fantastically if you’re on a platform that has KDE installed. However, most of my development is done on OSX, and while you can install kcachegrind via macports, it takes hours and hours because it has to build KDE, as well. Much to my surprise, the fine folks who wrote kcachegrind also made a QT version, qcachegrind. I was able to build this on OSX in about 10 minutes without too much effort, only having to install QT and GraphViz. Yippie!

I should note that I’m running OSX 10.6.7, with Xcode 4. My default gcc/g++ version is 4.2. I’m sure it will build just fine on earlier versions of Xcode, but I haven’t tested it.

Step 1: Install QT

You could do this via “brew install qt” if you have homebrew, but this takes a long time, so I downloaded the binary distribution of version 4.7.3 for OSX 10.5/10.6 from this page. Installing is easy: open up the dmg, and install QT via the mpkg file contained within.

Step 2: Install Graphviz

Second, you should install Graphviz so that qcachegrind can generate pretty call graphs for you. Like before, you could install this via “brew install graphviz”, but this also takes a really long time and I’m super impatient, so I just downloaded the latest binary installer from this page.

The only component of Graphviz that qcachegrind uses, to the best of my knowledge, is the dot binary. By default, the Graphviz installer drops dot to /usr/local/bin/dot, which qcachgrind.app might not find since /usr/local/bin isn’t in PATH by default (at least, not on my system). In order
# to ensure that qcachegrind can find dot, I created a symlink from /usr/bin/dot to /usr/local/bin/dot:
sudo ln -s /usr/local/bin/dot /usr/bin/dot

Step 3: Building qcachegrind

This is actually simple. Check out the source code for kcachegrind and switch to the qcachegrind directory:

svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdesdk/kcachegrind kcachegrind
cd kcachegrind/qcachegrind

You build the application by running ‘qmake’, a QT utility that can generate a boring-old Makefile, if we ask it nicely enough. By default, qmake wanted to build an xcode project on my box. I pointed it at spec profile that generates a Makefile that will build using g++, and things seemed to work fine. You can see all the profiles available in this directory: /usr/local/Qt4.7/mkspecs. This command also managed to spit out a whole bunch of errors and warnings, yet everything seemed to build properly.

qmake -spec 'macx-g++'
make

Step 4: Enjoy!

You should now have a beautiful little “qcachegrind.app” sitting in your build directory. You can run this directly via “open qcachegrind.app”, or you can drop it in your /Applications directory for easy access.

Update (Aug 30, 2011):

  • I removed the step where I would apply a patch that added the ability to open any file name. The qcachegrind source has since been updated to include a functionally identical change.
  • There are several comments about installing Qt via brew, and trying to build qcachegrind using that, yet failing. John Rood, looking to enable other gluttons for punishment, suggested installing Qt like so will get you on your way
    brew install qt --with-qt3support

    (I haven’t tested this out, myself).

  • For those who have installed Qt via brew and are having problems: try uninstalling it if you’re not using it for anything else (‘brew uninstall qt’). You may or may not have to reinstall the binary version, afterward; I’m not sure.

32 Comments

  1. Wez Furlong June 26, 2011

    There’s a broken binary search that causes it to hang when prepping the callgraph; this seems to allow it to make progress:

    https://gist.github.com/1047826

  2. Mario Guenterberg June 26, 2011

    Hey, great tutorial. I will adopt and translate this into german in the next days. Is it okay for you?

  3. Mnkras June 28, 2011

    I followed your instructions, but I used Brew instead of the pre compiled binaries, 10.6.8, Errors:

    g++ -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_NO_DEBUG -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Cellar/qt/4.7.3/mkspecs/macx-g++ -I. -I/usr/local/Cellar/qt/4.7.3/lib/QtCore.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/include/QtCore -I/usr/local/Cellar/qt/4.7.3/lib/QtGui.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/include/QtGui -I/usr/local/Cellar/qt/4.7.3/include/Qt3Support -I/usr/local/Cellar/qt/4.7.3/include -I../libcore -I../libviews -I. -I. -F/usr/local/Cellar/qt/4.7.3/lib -o ../.obj/costlistitem.o ../libviews/costlistitem.cpp
    In file included from ../libviews/costlistitem.cpp:19:
    ../libviews/costlistitem.h:22:24: error: q3listview.h: No such file or directory
    In file included from ../libviews/costlistitem.cpp:19:
    ../libviews/costlistitem.h:26: error: expected class-name before ‘{’ token
    ../libviews/costlistitem.h:28: error: expected `)' before ‘*’ token
    ../libviews/costlistitem.h:31: error: expected `)' before ‘*’ token
    ../libviews/costlistitem.h:34: error: ‘Q3ListViewItem’ has not been declared
    ../libviews/costlistitem.cpp:33: error: expected `)' before ‘*’ token
    make: *** [../.obj/costlistitem.o] Error 1
    

    Any help would be great

  4. Ash Cairo June 29, 2011

    I just followed the steps using the brew route and it compiled fine.

    Try again now.

  5. John Rood July 8, 2011

    @Mnkras

    Try brewing qt with the –with-qt3support option and qcachegrind will compile just fine.

  6. Glenn Roberts August 23, 2011

    It seems your patch hates freedom.

    Either that, or the svn checkout has since moved on… :-)

    $ patch -p0 < qcachegrind_filename_filter.patch
    patching file qcgtoplevel.cpp
    Hunk #1 FAILED at 795.
    Hunk #2 FAILED at 842.
    2 out of 2 hunks FAILED — saving rejects to file qcgtoplevel.cpp.rej

    (great article btw! I should have listened to your advice about building it. Make is still running after 40mins…)

  7. Patrick Thurmond August 30, 2011

    @John Rood – Your trick doesn’t work. I get the following error with that parameter “Error: No available formula for –with-qt3support”. The command I run for that is “brew install qt –with-qt3support”. I tried it with a double-dash as well just in case.

    I tried using homebrew for the first install (using the article instructions) and got tons of errors when compiling this. So then I tried the pre-made binary (the 200MB one) and now I just get a few errors when running make.

    g++ -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_DBUS_SUPPORT -DQT_NO_DEBUG -DQT_DBUS_LIB -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Cellar/qt/4.7.3/mkspecs/macx-g++ -I. -I/usr/local/Cellar/qt/4.7.3/lib/QtCore.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/lib/QtCore.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/lib/QtGui.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/lib/QtGui.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/include/Qt3Support -I/usr/local/Cellar/qt/4.7.3/lib/QtDBus.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/lib/QtDBus.framework/Versions/4/Headers -I/usr/local/Cellar/qt/4.7.3/include -I../libcore -I../libviews -I. -I. -F/usr/local/Cellar/qt/4.7.3/lib -o ../.obj/costlistitem.o ../libviews/costlistitem.cpp
    In file included from ../libviews/costlistitem.cpp:19:
    ../libviews/costlistitem.h:22:24: error: q3listview.h: No such file or directory
    In file included from ../libviews/costlistitem.cpp:19:
    ../libviews/costlistitem.h:26: error: expected class-name before ‘{’ token
    ../libviews/costlistitem.h:28: error: expected `)’ before ‘*’ token
    ../libviews/costlistitem.h:31: error: expected `)’ before ‘*’ token
    ../libviews/costlistitem.h:34: error: ‘Q3ListViewItem’ has not been declared
    ../libviews/costlistitem.cpp:33: error: expected `)’ before ‘*’ token
    make: *** [../.obj/costlistitem.o] Error 1

    So the question is now what do I do since it does not create the app file.

  8. justfalter August 30, 2011

    @John Thank you for that. I’ve updated the post to include that information on how to properly install Qt via brew.

    @Glenn The maintainers of qcachegrind have updated their code to include a functionally identical change, so I’ve removed it from this post. Last I heard, it still hates freedom.

    @Patrick It looks like you still have qt installed via brew (‘-I/usr/local/Cellar/qt/4.7.3/…’ gives it away). Do a ‘brew uninstall qt’ and try again.

  9. Mac Os X September 1, 2011

    Cheers man that was helpful, Hey, great tutorial, again thanks!

    Sid :mrgreen:

  10. Anna Filina October 31, 2011

    Compiled with no issues as per the instructions on my Snow Leopard. Thanks.

  11. Derek Downey November 2, 2011

    Works great for me, thanks for this!

  12. Brano November 3, 2011

    thanks for nice tutorial, compiled successfully on Snow Leopard. Now I run into a problem:

    > qcachegrind
    QPainter::begin: A paint device can only be painted by one painter at a time.
    Segmentation fault
    Exit 139

    I believe, when I restart OSX, it will work, but I don’t know how to run it OK without restarting…

  13. rICh November 9, 2011

    *Hugely* helpful, straightforward, and saved me tons of time.

    Thank you!!! :mrgreen:

  14. Karteek Addanki November 14, 2011

    Works perfectly. Thanks a lot. :razz:

  15. Bert November 14, 2011

    Works nicely with 10.7.2 Lion.
    Although had to apply this fix:
    https://bugs.kde.org/show_bug.cgi?id=284921

    with graphviz 2.29

  16. Ben November 21, 2011

    Great stuff. Thanks – you were right about the error messages when make-ing, but everything works like a charm. The xdebug site is helpful for tweaking the config settings.

    Also, can’t say strongly enough that those permissions for the output directory matter.

  17. Alan Storm November 22, 2011

    Thanks for going to the trouble of writing all this up, so few people do these days.

    Mainly for the Googles, my make kept failing with

    make: *** [/.obj/context.o] Error 1

    I managed to fix this by removing the macports

    /opt/*

    directories from my path.

  18. Bob Fanger November 26, 2011

    My qcachegrind Formula (based on this howto :grin: ) is now in the official homebrew repository.
    Hombrew users can now install qcachegrind by issuing 2 commands:

    brew install qt –with-qt3support
    brew install qcachegrind

  19. dave December 30, 2011

    I compiled this just fine, but when I launch it qcachegrind crashes reporting a EXC_BAD_ACCESS exception. Anyone have issues like this?

  20. Sam December 30, 2011

    This works fine on Snow Leopard and Lion (10.7.2). Make sure you run brew update after installing brew. I also had to run “brew doctor” and fix a lot of things before it would work. Ultimately, I only had to do:

    intall brew:

    /usr/bin/ruby -e “$(curl -fsSL https://raw.github.com/gist/323731)”

    brew doctor

    (fix a lot of stuff)

    brew update
    brew install qt –with-qt3support
    brew install qcachegrind

  21. justfalter January 3, 2012

    For what it’s worth, it appears that as of ~Sep 23, 2011 (r1255176), qcachegrind no longer requires qt3 in order to build. I think this may mean that plain old qt4 could do the trick, for those who are building qt with brew.

  22. fracarro January 28, 2012

    When I run qcachegrind the application crashes because of a EXC_BAD_ACCESS exception. No problem received during the compilation of qcachegrind. I’m using snow leopard (64 bit running ) and I did not used brew. Did Someone else met and solved this problem?

  23. Alex February 2, 2012

    My qcachegrind.app also crashes with a EXC_BAD_ACCESS (SIGSEGV) error. Lion 10.7.1

  24. Trove February 10, 2012

    [...] settled on the QT version of kcachegrind. I used a variant of the instructions found on this page.Essentially, I installed qt via homebrew (which is in a bottle now so its pretty fast.) If you [...]

  25. Colin Curtin March 15, 2012

    Lion 10.7.3, got EXC_BAD_ACCESS (SIGSEGV) also. Trying with brew to see if that works (Sam’s instructions)

  26. Niklas Andersson March 21, 2012

    I have the same problem as reported by several others – qcachegrind.app crashes with a (SIGSEGV) on Lion 10.7.3. Did anyone resolve this issue?

  27. Tammy March 27, 2012

    I also had the same EXC_BAD_ACCESS (SIGSEGV) errors on Snow Lepoard. I fixed by by uninstalling qt 4.8:

    sudo /Developer/Tools/uninstall-qt.py

    And then installing qt 4.7 (not the 4.8 the page above links to):
    http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.0.dmg

    Everything else in the tutorial worked perfectly after that.

  28. Robert Cesaric June 16, 2012

    Thanks, that worked really well for me on Snow Leopard.

    If it helps anyone, I tried installing KCacheGrind via MacPorts but it had a dependency no qt3 and I have qt4 installed (qt4-mac @4.8.2_0+quartz). So I installed Graphviz via MacPorts and was able to build KCacheGrind via the instructions above just fine.

  29. Jeff Whiting June 26, 2012

    Brew is the way to go.

    brew install qt –with-qt3support
    brew install qcachegrind

    Worked the first time for me on lion with no issues.

  30. marton July 3, 2012

    Alan’s solution for

    make: *** [/.obj/context.o] Error 1

    works also for fink. Remove /sw/* directories from your path.

  31. Laurent December 11, 2012

    Your procedure works very well (step 1 and 2 I grab the precompiled as you did)
    I got no error/warning out of qmake.
    Thanks so much

  32. Alex March 1, 2013

    Seems like they moved from SVN to GIT:
    git clone git://anongit.kde.org/kcachegrind

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>