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.
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.
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.
sudo ln -s /usr/local/bin/dot /usr/bin/dot
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
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.
brew install qt --with-qt3support
(I haven’t tested this out, myself).
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
Hey, great tutorial. I will adopt and translate this into german in the next days. Is it okay for you?
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 1Any help would be great
I just followed the steps using the brew route and it compiled fine.
Try again now.
@Mnkras
Try brewing qt with the –with-qt3support option and qcachegrind will compile just fine.
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…)
@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.
@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.
Cheers man that was helpful, Hey, great tutorial, again thanks!
Sid
Compiled with no issues as per the instructions on my Snow Leopard. Thanks.
Works great for me, thanks for this!
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…
*Hugely* helpful, straightforward, and saved me tons of time.
Thank you!!!
Works perfectly. Thanks a lot.
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
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.
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
I managed to fix this by removing the macports
directories from my path.
My qcachegrind Formula (based on this howto
) 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
I compiled this just fine, but when I launch it qcachegrind crashes reporting a EXC_BAD_ACCESS exception. Anyone have issues like this?
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
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.
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?
My qcachegrind.app also crashes with a EXC_BAD_ACCESS (SIGSEGV) error. Lion 10.7.1
[...] 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 [...]
Lion 10.7.3, got EXC_BAD_ACCESS (SIGSEGV) also. Trying with brew to see if that works (Sam’s instructions)
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?
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.
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.
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.
Alan’s solution for
make: *** [/.obj/context.o] Error 1works also for fink. Remove /sw/* directories from your path.
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
Seems like they moved from SVN to GIT:
git clone git://anongit.kde.org/kcachegrind