Profiling PHP
PEAR's Benchmark_Timer can be used to profile PHP code. To use:
Fetch http://pfsense.org/~cmb/tools/profiling/Timer.php.txt to /etc/inc/Timer.php
Add code like the following to the page you wish to profile.
require_once("Timer.php");
$timer = new Benchmark_Timer;
$timer->start();Then add markers to time execution between specific points in the code.
$timer->setMarker('marker1');When finished, the following code stops the timer and logs the time of each marker and the total time to the System log.
$timer->stop();
$profiling = $timer->getProfiling();
foreach($profiling as $time) {
log_error("profiling: {$time['name']} : {$time['diff']}");
}
log_error("Total time: {$time['total']}");Example Usage
http://pfsense.org/~cmb/tools/profiling/interfaces_vlan_edit.php.txt shows Benchmark_Timer in use.
this is the resultant log file
http://pfsense.org/~cmb/tools/profiling/profiling_logs.png
marker times are the time since the previous marker point. i.e. it took 6.08 seconds to get from marker9 to marker10.