Valgrind, callgrind, and Ubuntu

127 views
Skip to first unread message

David Brewer

unread,
Oct 15, 2009, 1:07:52 PM10/15/09
to pdx...@googlegroups.com
Howdy -- I'm trying to do a little valgrind-based performance
debugging in Ubuntu. I'm hoping that someone on the list has already
figured out "the easy way" to get set up for this. The broad strokes
summary of my question: is there an easy way to install debug-enabled
versions of PHP and/or Apache2 on Ubuntu Hardy, preferably
package-based?

Here's the details of the path I've tread so far and the problem I'm facing:

I installed valgrind on my web server (Ubuntu Server 8.04 LTS). I
used this command to get a profiler dump:

sudo valgrind --tool=callgrind --dump-instr=yes --trace-jump=yes -v
/usr/sbin/apache2

I hit the page I am interested in, and get some interresting output
along the lines of "callgrind.out.6667". Opening this up in
KCacheGrind produces some beautiful graphs, but I notice that a lot of
the call information has useless names like it doesn't know what the
functions being called are actually named.

After digging into this for a bit I figure out that the default Ubuntu
packages have their debug symbols stripped out of them. Some googling
turns up a special ubuntu repository containing versions of these
packages with the debug symbols still in place. So I added this to my
apt sources:

deb http://ddebs.ubuntu.com hardy main restricted universe multiverse

Then I installed a ton of dbgsym packages:

sudo aptitude install apache2.2-common-dbgsym
apache2-mpm-prefork-dbgsym libapache2-mod-php5-dbgsym php5-cli-dbgsym
php5-cgi-dbgsym php5-common-dbgsym php5-xapian-dbgsym php5-curl-dbgsym
php5-mysql-dbgsym php5-gd-dbgsym php5-sqlite3-dbgsym
php5-sybase-dbgsym

Generating a new profiler dump resulted in much more readable
information in KCacheGrind. I can see very useful information about
the time Apache is spending starting up, how much time is spend
initializing mod_ssl, and even zend starting up modules and parsing
config files. What I don't see is any information at all about what
php itself is doing. Based on what I've seen at some of Rasmus'
presentations, I was hoping to see information about how much time was
spent in database connections, compiling php code, and so on.

Further googling led me to this page:
http://bugs.php.net/bugs-getting-valgrind-log.php. Based on that, I
now think my problems are:

1) I need an --enable-debug build of PHP.
2) I might need a debug build of apache2. When I call "file
/usr/sbin/apache2" as suggested at the end of the page above, my
apache2 binary reports that it is "stripped" and that page suggests I
need it to say "not stripped".

So this leads to my big question: does anyone know an easy way to get
debug builds of PHP and/or Apache on Ubuntu WITHOUT doing custom
compilation? For stability and ease of setup I would prefer using
prebuilt packages if it's at all feasible... Or am I asking the wrong
questions, and there's something else I need to do?

Thanks to anyone who can help,

David Brewer

Sam Keen

unread,
Oct 15, 2009, 2:14:36 PM10/15/09
to pdx...@googlegroups.com
Hey David,
I've had similar adventures with valgrind on OSX.

If your end goal is to profile PHP Web applications you might try http://code.google.com/p/webgrind/ if you have not.  It does not implement all the features of kcachegrind but maybe enough for your needs and is very easy to set up.

hope this helps,

if you do fine a good PHP profiling Ubuntu build recipe, share with us if you can.  You can trade it for a Pint at the next PDXPHP meeting :)

regards,
sam
--
Sam Keen
@samkeen

David Brewer

unread,
Oct 15, 2009, 2:29:54 PM10/15/09
to pdx...@googlegroups.com
I've managed to get "inside php" profiling working fine by using
xdebug to save out profiler information which I then open with
kcachegrind. I think this is similar information to what is produced
by webgrind. I should try it and compare just to verify.

However, what I'm looking for is a bit lower level than that. Rather
than just seeing what's happening inside php itself, I want a bigger
picture of the whole web server, time spent in apache modules and php
extensions, and so on. The kind of stuff that Rasmus is looking at in
his typical optimization presentations like:
http://talks.php.net/show/oscon06/1

I'm starting to get a picture that maybe this is easier in later
versions of Ubuntu than Hardy. Post Hardy there is a 'php5-dbg'
package. I might be trying that out later on.

If I find a great solution I'll be sure to pass it on!

David

David Brewer

unread,
Oct 16, 2009, 7:09:27 PM10/16/09
to pdx...@googlegroups.com
A status update on this little project of mine: it's looking as if
there aren't any 'no-brainer' packages for installing debug-enabled
php under Ubuntu. The path I'm now looking into is downloading the
source packages for php5 on ubuntu, adding specifically the flags I
need for meaningful debugging, and then compiling new php5 packages
specifically for profiling. Fun, eh?

This isn't something I would recommend doing on a production server,
of course, or for that matter even your main dev box. I think the
approach I'm going to take is creating a virtual machine specifically
for profiling and installing the profiling-specific packages there.
Unless anyone has a better suggestion as to how to manage multiple
subtly different versions of PHP and Apache on the same machine? :-)

Once I have the kinks worked out I will try to remember to post what I
did to the list.

David
Reply all
Reply to author
Forward
0 new messages