Here's how to do it.

Introduction

There are 2 methods - each shown below.

NOTE: using profiling with really slow down a program. We're talking 4-10x. So, you may need to (as I did with the box packer) start a Timer (see common/time.php) and bail after a certain number of seconds, e.g.

   $t = new Timer();
   $t->start();
   
   while (1)  // some really huge loop
   {
      // if each iteration is fairly short, then this time check will happen often enough
      if ($t->since > 60)
      {  // bail 
      }
      // do the rest of your work
   }

1. Finding which function is hot

  • Put require_once("common/profiler.php"); in your file
  • Place the following at the point where you want to start your profiling
register_tick_function("__profiler__");
 __profiler__('init');
declare(ticks = 1);
  • Place the following where you want to get the data that has been profiled
new dBug(__profiler__('get'));

You will get a table with column 1 showing the function and column 2 showing the percentage of time spent in that function.

2. Finding what parts of a function are hot

This uses something similar to the 'sampling' technique of Intel's VTune. This takes considerably more work to do.

  • Put require_once("common/profiler.php"); in your file
  • Place the following at the point where you want to start your profiling
register_tick_function("__profiler_sampler__");
 __profiler__('init');
declare(ticks = 1);

-- MattWalsh - 28 Dec 2007

Topic revision: r1 - 28 Dec 2007 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback