diff options
author | oetting <jacob@oettinger.dk> | 2008-05-07 08:21:10 +0000 |
---|---|---|
committer | oetting <jacob@oettinger.dk> | 2008-05-07 08:21:10 +0000 |
commit | 81d8b757c0c43103dd223dda08f6d70d202a4228 (patch) | |
tree | a2d9cbdfc339518fc435b03da1d7c99a53bc573b | |
parent | eab81ebf05b84a94cf46b251434276eaa5131c13 (diff) | |
download | webgrind-81d8b757c0c43103dd223dda08f6d70d202a4228.zip webgrind-81d8b757c0c43103dd223dda08f6d70d202a4228.tar.gz webgrind-81d8b757c0c43103dd223dda08f6d70d202a4228.tar.bz2 |
Cost format cleanup.
Small ui change.
-rw-r--r-- | config.php | 4 | ||||
-rw-r--r-- | index.php | 18 | ||||
-rw-r--r-- | library/FileHandler.php | 8 | ||||
-rw-r--r-- | library/Reader.php | 55 | ||||
-rw-r--r-- | styles/style.css | 3 | ||||
-rw-r--r-- | templates/index.phtml | 8 |
6 files changed, 56 insertions, 40 deletions
@@ -35,9 +35,7 @@ class Webgrind_Config{ */ static $dateFormat = 'Y-m-d H:i:s'; - static $timeFormat = 'msec'; // or 'msec' - - static $defaultCostformat = 'percentage'; // or 'absolute' + static $defaultCostformat = 'percent'; // 'percent', 'usec' or 'msec' static $defaultFunctionPercentage = 90; @@ -26,12 +26,12 @@ switch(get('op')){ $files = Webgrind_FileHandler::getInstance()->getTraceList(); $dataFile = $files[0]['filename']; } - $reader = Webgrind_FileHandler::getInstance()->getTraceReader($dataFile); + $reader = Webgrind_FileHandler::getInstance()->getTraceReader($dataFile, get('costFormat', Webgrind_Config::$defaultCostformat)); $functions = array(); $shownTotal = 0; for($i=0;$i<$reader->getFunctionCount();$i++) { - $functionInfo = $reader->getFunctionInfo($i,get('costFormat')); + $functionInfo = $reader->getFunctionInfo($i); if (!(int)get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) { $shownTotal += $functionInfo['summedSelfCost']; @@ -55,23 +55,23 @@ switch(get('op')){ break; } $result['summedInvocationCount'] = $reader->getFunctionCount(); - $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'absolute'); + $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec'); $result['dataFile'] = $dataFile; $result['invokeUrl'] = $reader->getHeader('cmd'); $result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::$xdebugOutputDir.$dataFile)); echo json_encode($result); break; case 'callinfo_list': - $reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file')); + $reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file'), get('costFormat', Webgrind_Config::$defaultCostformat)); $functionNr = get('functionNr'); - $function = $reader->getFunctionInfo($functionNr, get('costFormat')); + $function = $reader->getFunctionInfo($functionNr); $result = array('calledFrom'=>array(), 'subCalls'=>array()); $foundInvocations = 0; for($i=0;$i<$function['calledFromInfoCount'];$i++){ - $invo = $reader->getCalledFromInfo($functionNr, $i, get('costFormat', 'absolute')); + $invo = $reader->getCalledFromInfo($functionNr, $i); $foundInvocations += $invo['callCount']; - $callerInfo = $reader->getFunctionInfo($invo['functionNr'], get('costFormat', 'absolute')); + $callerInfo = $reader->getFunctionInfo($invo['functionNr']); $invo['callerFile'] = $callerInfo['file']; $invo['callerFunctionName'] = $callerInfo['functionName']; $result['calledFrom'][] = $invo; @@ -79,8 +79,8 @@ switch(get('op')){ $result['calledByHost'] = ($foundInvocations<$function['invocationCount']); for($i=0;$i<$function['subCallInfoCount'];$i++){ - $invo = $reader->getSubCallInfo($functionNr, $i, get('costFormat', 'absolute')); - $callInfo = $reader->getFunctionInfo($invo['functionNr'], get('costFormat', 'absolute')); + $invo = $reader->getSubCallInfo($functionNr, $i); + $callInfo = $reader->getFunctionInfo($invo['functionNr']); $invo['callerFile'] = $callInfo['file']; $invo['callerFunctionName'] = $callInfo['functionName']; $result['subCalls'][] = $invo; diff --git a/library/FileHandler.php b/library/FileHandler.php index 44c54e3..50920b6 100644 --- a/library/FileHandler.php +++ b/library/FileHandler.php @@ -102,16 +102,18 @@ class Webgrind_FileHandler{ * * If the file has not been preprocessed yet this will be done first. * + * @param string File to read + * @param Cost format for the reader * @return Webgrind_Reader Reader for $file */ - public function getTraceReader($file){ + public function getTraceReader($file, $costFormat){ $prepFile = Webgrind_Config::$storageDir.$file.Webgrind_Config::$preprocessedSuffix; try{ - $r = new Webgrind_Reader($prepFile); + $r = new Webgrind_Reader($prepFile, $costFormat); } catch (Exception $e){ // Preprocessed file does not exist or other error Webgrind_Preprocessor::parse(Webgrind_Config::$xdebugOutputDir.$file, $prepFile); - $r = new Webgrind_Reader($prepFile); + $r = new Webgrind_Reader($prepFile, $costFormat); } return $r; } diff --git a/library/Reader.php b/library/Reader.php index acfcb7e..eab5f53 100644 --- a/library/Reader.php +++ b/library/Reader.php @@ -49,15 +49,25 @@ class Webgrind_Reader */ private $headers=null; + /** + * Format to return costs in + * + * @var string + */ + private $costFormat; + /** * Constructor * @param string Data file to read + * @param string Format to return costs in **/ - function __construct($dataFile){ + function __construct($dataFile, $costFormat){ $this->fp = @fopen($dataFile,'rb'); if(!$this->fp) throw new Exception('Error opening file!'); + + $this->costFormat = $costFormat; $this->init(); } @@ -88,10 +98,9 @@ class Webgrind_Reader * Returns information about function with nr $nr * * @param $nr int Function number - * @param $costFormat Format to return costs in. 'absolute' (default) or 'percentual' * @return array Function information */ - function getFunctionInfo($nr, $costFormat = 'absolute'){ + function getFunctionInfo($nr){ $this->seek($this->functionPos[$nr]); list($summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(5); @@ -109,8 +118,8 @@ class Webgrind_Reader 'calledFromInfoCount'=>$calledFromCount, 'subCallInfoCount'=>$subCallCount ); - $result['summedSelfCost'] = $this->formatCost($result['summedSelfCost'], $costFormat); - $result['summedInclusiveCost'] = $this->formatCost($result['summedInclusiveCost'], $costFormat); + $result['summedSelfCost'] = $this->formatCost($result['summedSelfCost']); + $result['summedInclusiveCost'] = $this->formatCost($result['summedInclusiveCost']); return $result; } @@ -120,10 +129,9 @@ class Webgrind_Reader * * @param $functionNr int Function number * @param $calledFromNr int Called from position nr - * @param $costFormat Format to return costs in. 'absolute' (default) or 'percentual' * @return array Called from information */ - function getCalledFromInfo($functionNr, $calledFromNr, $costFormat = 'absolute'){ + function getCalledFromInfo($functionNr, $calledFromNr){ // 5 = number of numbers before called from information $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*(self::CALLINFORMATION_LENGTH*$calledFromNr+5)); $data = $this->read(self::CALLINFORMATION_LENGTH); @@ -135,7 +143,7 @@ class Webgrind_Reader 'summedCallCost'=>$data[3] ); - $result['summedCallCost'] = $this->formatCost($result['summedCallCost'], $costFormat); + $result['summedCallCost'] = $this->formatCost($result['summedCallCost']); return $result; } @@ -145,10 +153,9 @@ class Webgrind_Reader * * @param $functionNr int Function number * @param $subCallNr int Sub call position nr - * @param $costFormat Format to return costs in. 'absolute' (default) or 'percentual' * @return array Sub call information */ - function getSubCallInfo($functionNr, $subCallNr, $costFormat = 'absolute'){ + function getSubCallInfo($functionNr, $subCallNr){ // 4 = number of numbers before sub call count $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*3); $calledFromInfoCount = $this->read(); @@ -162,7 +169,7 @@ class Webgrind_Reader 'summedCallCost'=>$data[3] ); - $result['summedCallCost'] = $this->formatCost($result['summedCallCost'], $costFormat); + $result['summedCallCost'] = $this->formatCost($result['summedCallCost']); return $result; } @@ -194,24 +201,30 @@ class Webgrind_Reader } /** - * Formats $cost as per config + * Formats $cost using the format in $this->costFormat or optionally the format given as input * * @param int $cost Cost - * @param string $format absolute or percentual - * @return int Cost formatted per config and $format paramter + * @param string $format 'percent', 'msec' or 'usec' + * @return int Formatted cost */ - function formatCost($cost, $format) + function formatCost($cost, $format=null) { - if ($format == 'percentual') { + if($format==null) + $format = $this->costFormat; + + if ($format == 'percent') { $total = $this->getHeader('summary'); $result = ($total==0) ? 0 : ($cost*100)/$total; return number_format($result, 2, '.', ''); - } else { - if (Webgrind_Config::$timeFormat == 'msec') { - return round($cost/1000, 0); - } - return $cost; + } + + if ($format == 'msec') { + return round($cost/1000, 0); } + + // Default usec + return $cost; + } private function read($numbers=1){ diff --git a/styles/style.css b/styles/style.css index 3ca0cc2..f1845b5 100644 --- a/styles/style.css +++ b/styles/style.css @@ -56,7 +56,8 @@ h2 { } #runtime_sum, -#invocation_sum { +#invocation_sum, +#shown_sum { font-weight: bold; } diff --git a/templates/index.phtml b/templates/index.phtml index 81f319c..6cc98aa 100644 --- a/templates/index.phtml +++ b/templates/index.phtml @@ -39,6 +39,7 @@ $("#data_file").html(data.dataFile); $("#invoke_url").html(data.invokeUrl); $("#mtime").html(data.mtime); + $("#shown_sum").html(data.functions.length); $("#invocation_sum").html(data.summedInvocationCount); $("#runtime_sum").html(data.summedRunTime); @@ -195,8 +196,9 @@ <div style="float:right;"> <label style="margin:0 5px">in</label> <select id="costFormat" name="costFormat"> - <option value="percentual" <?php echo (Webgrind_Config::$defaultCostformat=='percentual') ? 'selected' : ''?>>percent</option> - <option value="absolute" <?php echo (Webgrind_Config::$defaultCostformat=='absolute') ? 'selected' : ''?>>seconds</option> + <option value="percent" <?php echo (Webgrind_Config::$defaultCostformat=='percent') ? 'selected' : ''?>>percent</option> + <option value="msec" <?php echo (Webgrind_Config::$defaultCostformat=='msec') ? 'selected' : ''?>>milliseconds</option> + <option value="usec" <?php echo (Webgrind_Config::$defaultCostformat=='usec') ? 'selected' : ''?>>microseconds</option> </select> </div> <div style="float:right;"> @@ -232,7 +234,7 @@ <span id="data_file"></span> @ <span id="mtime"></span> </div> <div style="float:right;"> - <span id="invocation_sum"></span> functions called in <span id="runtime_sum"></span> <?php echo Webgrind_Config::$timeFormat?> + <span id="invocation_sum"></span> different functions called in <span id="runtime_sum"></span> milliseconds (<span id="shown_sum"></span> shown) </div> <div style="clear:both"></div> <table class="tablesorter" id="function_table" cellspacing="0"> |