summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjokkedk <joakim@jokke.dk>2008-03-31 19:27:24 +0000
committerjokkedk <joakim@jokke.dk>2008-03-31 19:27:24 +0000
commitd45571997037699900becac88d39b70a7596a7d4 (patch)
tree95d01a2dfa39508783293dbe0c6a0e4babdeece8
parentdfa659c7117823917f7b592090e432c83673bab1 (diff)
downloadwebgrind-d45571997037699900becac88d39b70a7596a7d4.zip
webgrind-d45571997037699900becac88d39b70a7596a7d4.tar.gz
webgrind-d45571997037699900becac88d39b70a7596a7d4.tar.bz2
- Added percentage to 'called from' output in function listing
-rw-r--r--index.php6
-rw-r--r--lib/Reader.php50
-rw-r--r--templates/index.phtml2
3 files changed, 50 insertions, 8 deletions
diff --git a/index.php b/index.php
index 1025a39..713f6d5 100644
--- a/index.php
+++ b/index.php
@@ -69,11 +69,11 @@ switch(get('op')){
$function = $reader->getFunctionInfo($functionNr);
echo '[';
for($i=0;$i<$function['invocationCount'];$i++){
- $invo = $reader->getInvocation($functionNr, $i);
+ $invo = $reader->getInvocation($functionNr, $i, get('costFormat', 'absolute'));
if($invo['calledFromFunction']==-1){
$invo['callerInfo'] = false;
} else {
- $invo['callerInfo'] = $reader->getFunctionInfo($invo['calledFromFunction']);
+ $invo['callerInfo'] = $reader->getFunctionInfo($invo['calledFromFunction'], get('costFormat', 'absolute'));
}
echo json_encode($invo).',';
}
@@ -97,7 +97,7 @@ function costCmp($a, $b){
return ($a > $b) ? -1 : 1;
}
-function percentCost($cost, $total){
+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 9beea38..cf043a5 100644
--- a/lib/Reader.php
+++ b/lib/Reader.php
@@ -54,19 +54,61 @@ class Reader{
return sizeof($this->functionPos);
}
- function getFunctionInfo($nr){
+ function getFunctionInfo($nr, $costFormat = 'absolute'){
$this->seek($this->functionPos[$nr]);
list($totalSelfCost, $totalInclusiveSelfCost, $totalCallCost, $invocationCount) = $this->read(4);
$this->seek(self::NR_SIZE*self::INVOCATION_LENGTH*$invocationCount, SEEK_CUR);
$file = $this->readLine();
$function = $this->readLine();
- return array('file'=>$file, 'functionName'=>$function, 'totalSelfCost'=>$totalSelfCost, 'totalInclusiveSelfCost'=>$totalInclusiveSelfCost, 'totalCallCost'=>$totalCallCost, 'invocationCount'=>$invocationCount);
+
+ 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
+ );
+ }
}
- function getInvocation($functionNr, $invocationNr){
+ function getInvocation($functionNr, $invocationNr, $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], 'subCalls'=>array());
+
+ 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);
diff --git a/templates/index.phtml b/templates/index.phtml
index 179cc82..4aff70b 100644
--- a/templates/index.phtml
+++ b/templates/index.phtml
@@ -67,7 +67,7 @@
function loadInvocations(functionNr){
if(!invocationsLoaded[functionNr]){
$.getJSON("index.php",
- {'op':'invocation_list','file':currentDataFile,'functionNr':functionNr},
+ {'op':'invocation_list', 'file':currentDataFile, 'functionNr':functionNr, 'costFormat':$("#costFormat").val()},
function(data){
$("#invocation_area_"+functionNr).append(invocationTable(functionNr));
calledByUser = calledBySystem = false;