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

吃可爱长大的小学妹 提交于 2019-11-30 14:29:07

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
Mike Dunlavey

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!