diff options
author | oetting <jacob@oettinger.dk> | 2008-04-06 20:59:13 +0000 |
---|---|---|
committer | oetting <jacob@oettinger.dk> | 2008-04-06 20:59:13 +0000 |
commit | 8959cfdb58e609e1e738d21457f478eadfe8bcf0 (patch) | |
tree | 46a0795ebd17d7e333c3f2fead7ddfa4dff851cb | |
parent | 6d1724b7bc43a610abc253d50824c9153ab5078f (diff) | |
download | webgrind-8959cfdb58e609e1e738d21457f478eadfe8bcf0.zip webgrind-8959cfdb58e609e1e738d21457f478eadfe8bcf0.tar.gz webgrind-8959cfdb58e609e1e738d21457f478eadfe8bcf0.tar.bz2 |
Removed unused data from json results.
Fixed inner total
-rw-r--r-- | index.php | 46 | ||||
-rw-r--r-- | lib/Reader.php | 90 | ||||
-rw-r--r-- | license.txt | 2 | ||||
-rw-r--r-- | templates/index.phtml | 6 |
4 files changed, 75 insertions, 69 deletions
@@ -25,30 +25,33 @@ switch(get('op')){ $reader = FileHandler::getInstance()->getTraceReader($dataFile); $count = $reader->getFunctionCount(); $functions = array(); - $totalCost = array('self' => 0, 'inclusive' => 0); + $totalCost = $shownTotal = 0; $result['totalRunTime'] = $reader->getHeader('summary'); for($i=0;$i<$count;$i++) { - $functionInfo = $reader->getFunctionInfo($i); - + $functionInfo = $reader->getFunctionInfo($i,'absolute'); + unset($functionInfo['totalCallCost']); + $totalCost += $functionInfo['totalSelfCost']; + if (!(int)get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) { - $totalCost['self'] += $functionInfo['totalSelfCost']; - $totalCost['inclusive'] += $functionInfo['totalInclusiveSelfCost']; - $functions[$i] = $functionInfo; + $shownTotal += $functionInfo['totalSelfCost']; + $functions[$i] = $functionInfo; $functions[$i]['nr'] = $i; } } usort($functions,'costCmp'); - $remainingCost = $totalCost['self']*get('showFraction'); + $remainingCost = $shownTotal*get('showFraction'); $result['functions'] = array(); foreach($functions as $function){ $remainingCost -= $function['totalSelfCost']; - if(get('costFormat')=='percentual'){ - $function['totalSelfCost'] = percentCost($function['totalSelfCost'], $result['totalRunTime']); - $function['totalInclusiveSelfCost'] = percentCost($function['totalInclusiveSelfCost'], $result['totalRunTime']); + + if(get('costFormat')=='percent'){ + $function['totalSelfCost'] = $reader->percentCost($function['totalSelfCost']); + $function['totalInclusiveSelfCost'] = $reader->percentCost($function['totalInclusiveSelfCost']); } + $result['functions'][] = $function; if($remainingCost<0) break; @@ -56,7 +59,7 @@ switch(get('op')){ $result['dataFile'] = $dataFile; $result['invokeUrl'] = $reader->getHeader('cmd'); $result['mtime'] = date(Config::$dateFormat,filemtime(Config::$xdebugOutputDir.$dataFile)); - $result['totalSelftime'] = $totalCost['self']; + $result['totalSelftime'] = $totalCost; echo json_encode($result); break; case 'invocation_list': @@ -70,12 +73,17 @@ switch(get('op')){ echo '['; for($i=$start;$i<$end;$i++){ - $invo = $reader->getInvocation($functionNr, $i, get('costFormat', 'absolute')); + $invo = $reader->getInvocation($functionNr, $i, false, get('costFormat', 'absolute')); if($invo['calledFromFunction']==-1){ - $invo['callerInfo'] = false; + $invo['callerFile'] = false; + $invo['callerFunctionName'] = false; } else { - $invo['callerInfo'] = $reader->getFunctionInfo($invo['calledFromFunction'], get('costFormat', 'absolute')); + $callerInfo = $reader->getFunctionInfo($invo['calledFromFunction'], get('costFormat', 'absolute')); + $invo['callerFile'] = $callerInfo['file']; + $invo['callerFunctionName'] = $callerInfo['functionName']; } + unsetMultiple($invo, array('callCost','calledFromFunction','calledFromInvocation')); + echo json_encode($invo).','; } echo ']'; @@ -88,6 +96,11 @@ function get($param, $default=false){ return (isset($_GET[$param])? $_GET[$param] : $default); } +function unsetMultiple(&$array, $fields){ + foreach($fields as $field) + unset($array[$field]); +} + function costCmp($a, $b){ $a = $a['totalSelfCost']; $b = $b['totalSelfCost']; @@ -97,8 +110,3 @@ function costCmp($a, $b){ } return ($a > $b) ? -1 : 1; } - -function percentCost($cost, $total){ - $result = ($total==0) ? 0 : ($cost*100)/$total; - return number_format($result, 3, '.', ''); -} diff --git a/lib/Reader.php b/lib/Reader.php index cf043a5..acefc07 100644 --- a/lib/Reader.php +++ b/lib/Reader.php @@ -61,58 +61,49 @@ class Reader{ $file = $this->readLine(); $function = $this->readLine(); - if ($costFormat == 'percentual') { - $totalTime = $this->getHeader('summary'); - return array( - 'file'=>$file, - 'functionName'=>$function, - 'totalSelfCost'=>percentCost($totalSelfCost, $totalTime), - 'totalInclusiveSelfCost'=>percentCost($totalInclusiveSelfCost, $totalTime), - 'totalCallCost'=>$totalCallCost, - 'invocationCount'=>$invocationCount - ); - } else { - return array( - 'file'=>$file, - 'functionName'=>$function, - 'totalSelfCost'=>$totalSelfCost, - 'totalInclusiveSelfCost'=>$totalInclusiveSelfCost, - 'totalCallCost'=>$totalCallCost, - 'invocationCount'=>$invocationCount - ); - } + $result = array( + 'file'=>$file, + 'functionName'=>$function, + 'totalSelfCost'=>$totalSelfCost, + 'totalInclusiveSelfCost'=>$totalInclusiveSelfCost, + 'totalCallCost'=>$totalCallCost, + 'invocationCount'=>$invocationCount + ); + if ($costFormat == 'percentual') { + $result['totalSelfCost'] = $this->percentCost($result['totalSelfCost']); + $result['totalInclusiveSelfCost'] = $this->percentCost($result['totalInclusiveSelfCost']); + $result['totalCallCost'] = $this->percentCost($result['totalCallCost']); + } + + return $result; } - function getInvocation($functionNr, $invocationNr, $costFormat = 'absolute'){ + function getInvocation($functionNr, $invocationNr, $includeSubCalls, $costFormat = 'absolute'){ $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*(self::INVOCATION_LENGTH*$invocationNr+4)); $data = $this->read(self::INVOCATION_LENGTH); + + $result = array( + 'selfCost'=>$data[0], + 'inclusiveSelfCost'=>$data[1], + 'callCost'=>$data[2], + 'calledFromFunction'=>$data[3], + 'calledFromInvocation'=>$data[4], + 'calledFromLine'=>$data[5], + ); if ($costFormat == 'percentual') { - $totalTime = $this->getHeader('summary'); - $result = array( - 'selfCost'=>percentCost($data[0], $totalTime), - 'inclusiveSelfCost'=>percentCost($data[1], $totalTime), - 'callCost'=>$data[2], - 'calledFromFunction'=>$data[3], - 'calledFromInvocation'=>$data[4], - 'calledFromLine'=>$data[5], - 'subCalls'=>array() - ); - } else { - $result = array( - 'selfCost'=>$data[0], - 'inclusiveSelfCost'=>$data[1], - 'callCost'=>$data[2], - 'calledFromFunction'=>$data[3], - 'calledFromInvocation'=>$data[4], - 'calledFromLine'=>$data[5], - 'subCalls'=>array() - ); - } - $this->seek($data[7]); - for($i=0;$i<$data[6];$i++){ - $scData = $this->read(self::SUBCALL_LENGTH); - $result['subCalls'][] = array('functionNr'=>$scData[0], 'invocationNr'=>$scData[1], 'line'=>$scData[2], 'cost'=>$scData[3]); + $result['selfCost'] = $this->percentCost($result['selfCost']); + $result['inclusiveSelfCost'] = $this->percentCost($result['inclusiveSelfCost']); + $result['callCost'] = $this->percentCost($result['callCost']); + } + + if($includeSubCalls){ + $result['subCalls'] = array(); + $this->seek($data[7]); + for($i=0;$i<$data[6];$i++){ + $scData = $this->read(self::SUBCALL_LENGTH); + $result['subCalls'][] = array('functionNr'=>$scData[0], 'invocationNr'=>$scData[1], 'line'=>$scData[2], 'cost'=>$scData[3]); + } } return $result; } @@ -133,4 +124,11 @@ class Reader{ return $headers[$header]; } + function percentCost($cost){ + $total = $this->getHeader('summary'); + $result = ($total==0) ? 0 : ($cost*100)/$total; + return number_format($result, 3, '.', ''); + } + + } diff --git a/license.txt b/license.txt index c271ea1..781751c 100644 --- a/license.txt +++ b/license.txt @@ -18,7 +18,7 @@ permitted provided that the following conditions are met: * Neither the name of Jacob Oettinger and Joakim Nygård nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior - written permission of Yahoo! Inc. + written permission of Jacob Oettinger and Joakim Nygård. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A diff --git a/templates/index.phtml b/templates/index.phtml index 473222d..c6bf184 100644 --- a/templates/index.phtml +++ b/templates/index.phtml @@ -74,7 +74,7 @@ function(data){ calledByUser = calledBySystem = false; for(i=0;i<data.length;i++){ - if(data[i].callerInfo){ + if(data[i].callerFile){ $("#invocation_table_"+functionNr+" tbody").append(invocationTableRow(invocationsLoaded[functionNr]+i, data[i])); calledByUser = true; } else { @@ -125,10 +125,10 @@ function invocationTableRow(nr,data){ return '<tr> \ <td>'+nr+'</td> \ - <td>'+data.callerInfo.functionName+'</td> \ + <td>'+data.callerFunctionName+'</td> \ <td>'+data.selfCost+'</td> \ <td>'+data.inclusiveSelfCost+'</td> \ - <td><a title="Open file and show line" href="'+sprintf(fileUrlFormat,data.callerInfo.file,data.calledFromLine)+'" target="_blank"><img src="img/file_line.png" alt="O"/></a></td> \ + <td><a title="Open file and show line" href="'+sprintf(fileUrlFormat,data.callerFile,data.calledFromLine)+'" target="_blank"><img src="img/file_line.png" alt="O"/></a></td> \ </tr>'; } |