/ Published in: PHP
Rather simple profiler for > php5, if you want to find out where the heck those 0.5 sec function time goes into
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // simple profiler class // by Patrik Plihal class myProfiler{ var $cnt = 0; // in fact count(%timestamps)+1 var $style = '<style type="text/css">.profiler{width: 420px; font-size: 11px; border: solid 1px #45A} .tar{text-align:right;} th{background-color: #D9D9D9 !important} .names{width: 150px;} .time1{width: 120px;background-color: #AAD} .time2{width: 120px;background-color: #DDA}</style>'; var $factor; var $unit; function __construct($unit="s",$lazy = false){ if(!$lazy) $this->capture('start'); $this->unit = $unit; switch($unit){ case "ms": $this->factor = 1000; break; case "µs": $this->factor = 1000000; break; default: $this->factor = 1; break; } } function capture($desc){ $this->cnt++; } function getReport(){ if($this->cnt < 2) return ""; $rep = "\n capturepoint | absolute relative\n"; for($i = 1; $i < $this->cnt; $i++){ } return $rep."\n\n"; } function getHTMLReport(){ if($this->cnt < 2) return ""; $rep = $this->style."<div><table class=\"profiler\" border=0>\n"; $rep .= "<thead><tr><th class=\"names tar\">capturepoint</th>\n<th class=\"time1 tar\">absolute</th><th class=\"time2 tar\">relative</th></tr></thead><tbody>\n"; for($i = 1; $i < $this->cnt; $i++){ } $rep .= "</tbody><tfoot><tr><th class=\"names tar\">summary</th>\n<th class=\"time1 tar\">".round($profiletime,5)." sec</th><th class=\"time2 tar\">100 %</th></tr></tfoot>\n"; return $rep."</table></div>\n"; } function test(){ print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; print '<html><head></head><body>'; $this->capture(($i/((float)4))); } print $this->getHTMLReport(); print '</body></html>'; } } class myTimeStamp{ var $name; var $time; function __construct($n,$t = false){ $this->name = $n; } } ?>