6

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

Community
  • 1
  • 1
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81

2 Answers2

3

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
Yada
  • 30,349
  • 24
  • 103
  • 144
  • +1 for xhprof recommendation, though it's quite a bit different to use than xdebug's profiler – Mark Baker Jan 10 '12 at 21:15
  • But it doesn't seem to have any visualization tool for calltrace. +1 for suggesting it though. – ThinkingMonkey Jan 10 '12 at 21:16
  • @ThinkingMonkey yes it does have calltrace with GraphViz package. http://techportal.ibuildings.com/2009/12/01/profiling-with-xhprof/ – Yada Jan 10 '12 at 21:24
  • I played around with Xhprof. XHProf keeps track of only one level of calling context and is therefore only able to answer questions about a function looking either one level up or down. So, XHProf does not provide full backtrace. But _XHProf is definitely better in terms of the data presentation & better call graphs_. Thanks for suggesting this! – ThinkingMonkey Jan 11 '12 at 06:11
1

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • :) the smiley because, this is what I have been doing from the time I started programming. This is my first time with a profiler. – ThinkingMonkey Jan 11 '12 at 06:12
  • @Think: Heh. Glad to hear it. If you have better luck with a profiler, let me know. – Mike Dunlavey Jan 11 '12 at 14:01
  • Nothing special help from profiler. But, (I am very absent minded and over sighted sometimes) It helped me to notice some function call which was not required. And I had missed to remove when I had done an optimization (to use cache). – ThinkingMonkey Jan 11 '12 at 15:37