1

I've been developing a php framework for some time now and use it on 10 or so sites with our own CMS.

Its getting to a point now where its quite complex and there seem to be ever increasing delays for certain classes/functions.

I want to try and find out where the biggest delays are occurring but not sure how i would go about this.

I've tried installing xdebug but it didn't work and im not even sure how it would be used anyway.

Does anyone know how i can track calls to classes and functions and even time them?

any help appreciated, Dan.

Quamis
  • 10,924
  • 12
  • 50
  • 66
v3nt
  • 2,845
  • 6
  • 36
  • 50
  • 1
    you need a profiler so i sugget you to get to know x-debug – Anton S Dec 13 '10 at 11:49
  • 2
    **It didn't work** is not a valid problem description. If you are not sure how XDebug works, either [go through the documentation](http://www.xdebug.org/docs/) or put your issues with it into a proper question. In any case, XDebug is your best choice. – Gordon Dec 13 '10 at 11:49
  • 1
    possible duplicate of [Good Free PHP debugger?](http://stackoverflow.com/questions/1494288/good-free-php-debugger/1494339#1494339) – Gordon Dec 13 '10 at 11:51
  • would the following link be of any help ? http://php.net/manual/en/function.debug-backtrace.php – Poelinca Dorin Dec 13 '10 at 12:01
  • well i read the question and I saw that daniel is looking for solutions to avoid proper tools for the job so my suggestion was to make x-debug work and use it. But he might as well use zend debugger for profiling the code. debugging tools are built in almost every popular IDE (like zend, eclipse, phpstorm). Thats why i added this as a comment not an answer – Anton S Dec 13 '10 at 12:01
  • @poelinca debug_backtrace does not give information about execution times. It only gives you a trace of which functions have been called. – Gordon Dec 13 '10 at 12:04
  • yeh - really trying with xdecode but the extensions just don't seem to be loading so when i call anything for xdecode i get Fatal error: Call to undefined function xdebug_is_enabled() in /Volumes/Groups/Projects/483_Modern_Activity_Website/web/index.php on line 12. All the files seem to be in right place and edited php.ini files as instructed but no joy (using mamp pro) – v3nt Dec 13 '10 at 12:52
  • @daniel , did you restart apache after changing php.ini ? @Gordon yes you are right but i was thinking if you place it at the end of you're app then you'll have a view of all functions called then you can tell how many of each has runned , tough the output of it isn't realy user friendly – Poelinca Dorin Dec 13 '10 at 13:28
  • ok - its now working. had to trawl through the mamp forums. It didn't even need installing but had to download a new xdebug.so from http://downloads.activestate.com/Komodo/releases/6.0.3/remotedebugging/Komodo-PHPRemoteDebugging-6.0.3-59641-macosx.tar.gz and uncomment a line in the php5.3 template in mamp. – v3nt Dec 13 '10 at 13:45
  • Also had to comment out xcache.so. – v3nt Dec 13 '10 at 13:54

1 Answers1

0

You want to try and find out where the biggest delays are occurring and are not sure how to go about it.

Everyone's first instinct is to start measuring times used by methods, and counting how many times they are called, and progressively narrowing down, and using intuition to make a smart guess as to what could be fixed. However, there's another way to think about it, not in terms of time, but in terms of necessity.

The program walks a call tree. The main routine calls A, then it calls B, and so on. A calls C, then D, etc. That is walking the call tree, all the way down to the leaves, which are simple statements, system calls, and I/O. If all of those activities simply must be done, then the program is as fast as possible.

Since there are delays, some of those activities are not strictly necessary, and the way for them to be not necessary is for one of the branches leading to them (the call points) to be not strictly necessary.

Suppose your delay costs 50% of the time. Then those call points are active and on the call stack for 50% of the time. So if you pause the program at random and display the stack, the chance you will see it is 50%. If you do this 10 times, it will appear on 5 of them, more or less.

In fact, if you do such random pausing and examining the stack, if a call point appears on only one sample, it tells you nothing. But if it appears on more than one sample, and if it is something you could avoid doing, you've found a delay, and fixing it will make the program faster. What's more, there is almost no delay you can fix that can escape this kind of scrutiny.

As a program becomes larger and more complex, such non-strictly-necessary call points tend to creep in, just like bugs. Unlike bugs, they don't demand that you fix them; they only slow the program down, so it's good to do this once in a while.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135