A 'profiler with visualization' for PHP with `full backtrace visualization`?

1.4k views Asked by At

Currently, I am using xdebug profiler & KCacheGrind. But GallGrind format does not store full call trace, just the parent child call traces (look at Kcachegrind/callgrind is inaccurate for dispatcher functions? for what I am talking about.)

Is there a profiler with visualization with full backtrace visualization available for PHP?

I have looked at

2

There are 2 answers

4
Yada On BEST ANSWER

I had to do some major PHP profiling for a previous project a few months ago.

The best option I was able to find was facebook's xhprof with xhprof-ui.

Read about how to install both of them here:

http://blog.preinheimer.com/index.php?/archives/355-A-GUI-for-XHProf.html

Some pros:

  • easy to use interface
  • database backend to save previous profiling session
  • nice callgraphs
3
Mike Dunlavey On

If you just want to look at profiler output, that's one thing. If you're trying to optimize your code, don't forget about this method. I know you can do it in xdebug.

It's based on a very simple idea. Suppose your program is doing more than it needs to, so it could be speeded up. In fact suppose, for argument's sake, it is doing 9 times more than it needs to, so altogether if it was supposed to take 1 second it's actually taking 10. Those 9 seconds of unnecessary work may or may not be thoroughly mixed in, like sugar and flour.

OK, during those 10 seconds, you just hit ^C to halt it, and then you look carefully to see what it was doing at that moment.

What is the probability that you caught it doing the wasteful thing? Actually, it's very unlikely you didn't catch it doing the wasteful thing.

If you're not sure, just repeat.

The wastage doesn't have to be as large as that. In fact, if you keep pausing it like that, as soon as you see it doing something on more than one occasion, if it's something you could get rid of, you'll get a nice speedup, guaranteed.

For example, if you pause it 5 times, and you see it doing something it doesn't really have to do on 2 of those occasions, how much could you save? You don't exactly know, but it will be somewhere around 40%. It could be as small as 20%. It could just as easily be as large as 60%. So you don't know how much it will save, but you don't throw away a gold nugget just because you're not sure how much it weighs.

Finally, there is no problem the profiler can find that this won't. The converse is not true.