cvs: pear /Benchmark Profiler.php Timer.php

From: Date: Wed, 01 Mar 2006 13:41:39 +0000
Subject: cvs: pear /Benchmark Profiler.php Timer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38784@lists.php.net to get a copy of this message
matthias Wed Mar 1 13:41:39 2006 UTC Modified files: /pear/Benchmark Profiler.php Timer.php Log: Bug #6157: option to choose output format http://cvs.php.net/viewcvs.cgi/pear/Benchmark/Profiler.php?r1=1.17&r2=1.18&diff_format=u Index: pear/Benchmark/Profiler.php diff -u pear/Benchmark/Profiler.php:1.17 pear/Benchmark/Profiler.php:1.18 --- pear/Benchmark/Profiler.php:1.17 Fri Feb 17 16:29:44 2006 +++ pear/Benchmark/Profiler.php Wed Mar 1 13:41:39 2006 @@ -14,7 +14,7 @@ // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // -// $Id: Profiler.php,v 1.17 2006/02/17 16:29:44 toggg Exp $ +// $Id: Profiler.php,v 1.18 2006/03/01 13:41:39 matthias Exp $ // require_once 'PEAR.php'; @@ -232,19 +232,22 @@ /** * Returns formatted profiling information. * + * @param string output format (auto, plain or html), default auto * @see display() * @access private */ - function _getOutput() { - if (function_exists('version_compare') && - version_compare(phpversion(), '4.1', 'ge')) { - $http = isset($_SERVER['SERVER_PROTOCOL']); - } else { - global $HTTP_SERVER_VARS; - $http = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']); + function _getOutput($format) { + if ($format == 'auto') { + if (function_exists('version_compare') && + version_compare(phpversion(), '4.1', 'ge')) { + $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; + } else { + global $HTTP_SERVER_VARS; + $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; + } } - if ($http) { + if ($format == 'html') { $out = '<table style="border: 1px solid #000000; ">'."\n"; $out .= '<tr><td>&nbsp;</td><td align="center"><b>total ex. time</b></td>'. @@ -286,7 +289,7 @@ $callers_str .= "$key ($val)"; } - if ($http) { + if ($format == 'html') { $out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>"; if (is_numeric($values['percentage'])) { $out .= "<td align=\"right\">{$values['percentage']}%</td>\n"; @@ -295,7 +298,7 @@ } $out .= "<td>$calls_str</td><td>$callers_str</td></tr>"; } else { - $out .= str_pad($name, $this->_maxStringLength, ' '); + $out .= str_pad($name, $this->_maxStringLength); $out .= str_pad($values['time'], 22); $out .= str_pad($values['netto_time'], 22); $out .= str_pad($values['num_calls'], 22); @@ -313,10 +316,11 @@ /** * Returns formatted profiling information. * + * @param string output format (auto, plain or html), default auto * @access public */ - function display() { - echo $this->_getOutput(); + function display($format = 'auto') { + echo $this->_getOutput($format); } /** http://cvs.php.net/viewcvs.cgi/pear/Benchmark/Timer.php?r1=1.15&r2=1.16&diff_format=u Index: pear/Benchmark/Timer.php diff -u pear/Benchmark/Timer.php:1.15 pear/Benchmark/Timer.php:1.16 --- pear/Benchmark/Timer.php:1.15 Fri Feb 17 16:29:44 2006 +++ pear/Benchmark/Timer.php Wed Mar 1 13:41:39 2006 @@ -14,7 +14,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Timer.php,v 1.15 2006/02/17 16:29:44 toggg Exp $ +// $Id: Timer.php,v 1.16 2006/03/01 13:41:39 matthias Exp $ // require_once 'PEAR.php'; @@ -210,26 +210,28 @@ * Return formatted profiling information. * * @param boolean $showTotal Optionnaly includes total in output, default no + * @param string $format output format (auto, plain or html), default auto * @return string * @see getProfiling() * @access public */ - function getOutput($showTotal = FALSE) - { - if (function_exists('version_compare') && - version_compare(phpversion(), '4.1', 'ge')) - { - $http = isset($_SERVER['SERVER_PROTOCOL']); - } else { - global $HTTP_SERVER_VARS; - $http = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']); + function getOutput($showTotal = FALSE, $format = 'auto') { + if ($format == 'auto') { + if (function_exists('version_compare') && + version_compare(phpversion(), '4.1', 'ge')) + { + $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; + } else { + global $HTTP_SERVER_VARS; + $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; + } } $total = $this->TimeElapsed(); $result = $this->getProfiling(); $dashes = ''; - if ($http) { + if ($format == 'html') { $out = '<table border="1">'."\n"; $out .= '<tr><td>&nbsp;</td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'. ($showTotal ? @@ -250,7 +252,7 @@ $perc = (($v['diff'] * 100) / $total); $tperc = (($v['total'] * 100) / $total); - if ($http) { + if ($format == 'html') { $out .= "<tr><td><b>" . $v['name'] . "</b></td><td>" . $v['time'] . "</td><td>" . $v['diff'] . @@ -277,7 +279,7 @@ $out .= $dashes; } - if ($http) { + if ($format == 'html') { $out .= "<tr style='background: silver;'><td><b>total</b></td><td>-</td><td>${total}</td><td>100.00%</td>".($showTotal ? "<td>-</td><td>-</td>" : "")."</tr>\n"; $out .= "</table>\n"; } else { @@ -295,11 +297,12 @@ * Prints the information returned by getOutput(). * * @param boolean $showTotal Optionnaly includes total in output, default no + * @param string $format output format (auto, plain or html), default auto * @see getOutput() * @access public */ - function display($showTotal = FALSE) { - print $this->getOutput($showTotal); + function display($showTotal = FALSE, $format = 'auto') { + print $this->getOutput($showTotal, $format); } /**

« previous php.pear.cvs (#38784) next »