summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/Preprocessor.php36
-rw-r--r--library/Reader.php44
2 files changed, 62 insertions, 18 deletions
diff --git a/library/Preprocessor.php b/library/Preprocessor.php
index 39ea943..5022431 100644
--- a/library/Preprocessor.php
+++ b/library/Preprocessor.php
@@ -16,11 +16,11 @@ class Webgrind_Preprocessor
/**
* Fileformat version. Embedded in the output for parsers to use.
*/
- const FILE_FORMAT_VERSION = 5;
+ const FILE_FORMAT_VERSION = 6;
/**
* Binary number format used.
- * @see http://dk2.php.net/pack
+ * @see http://php.net/pack
*/
const NR_FORMAT = 'V';
@@ -54,6 +54,7 @@ class Webgrind_Preprocessor
$nextFuncNr = 0;
$functions = array();
$headers = array();
+ $calls = array();
// Read information into memory
@@ -62,7 +63,7 @@ class Webgrind_Preprocessor
// Found invocation of function. Read functionname
list($function) = fscanf($in,"fn=%s");
if(!isset($functions[$function])){
- $functions[$function] = array('filename'=>substr(trim($line),3), 'invocationCount'=>0,'nr'=>$nextFuncNr++,'count'=>0,'summedSelfCost'=>0,'summedInclusiveCost'=>0,'callInformation'=>array());
+ $functions[$function] = array('filename'=>substr(trim($line),3), 'invocationCount'=>0,'nr'=>$nextFuncNr++,'count'=>0,'summedSelfCost'=>0,'summedInclusiveCost'=>0,'calledFromInformation'=>array(),'subCallInformation'=>array());
}
$functions[$function]['invocationCount']++;
// Special case for ENTRY_POINT - it contains summary header
@@ -85,11 +86,18 @@ class Webgrind_Preprocessor
$functions[$function]['summedInclusiveCost'] += $cost;
- if(!isset($functions[$calledFunctionName]['callInformation'][$function.':'.$lnr]))
- $functions[$calledFunctionName]['callInformation'][$function.':'.$lnr] = array('functionNr'=>$functions[$function]['nr'],'line'=>$lnr,'callCount'=>0,'summedCallCost'=>0);
+ if(!isset($functions[$calledFunctionName]['calledFromInformation'][$function.':'.$lnr]))
+ $functions[$calledFunctionName]['calledFromInformation'][$function.':'.$lnr] = array('functionNr'=>$functions[$function]['nr'],'line'=>$lnr,'callCount'=>0,'summedCallCost'=>0);
+
+ $functions[$calledFunctionName]['calledFromInformation'][$function.':'.$lnr]['callCount']++;
+ $functions[$calledFunctionName]['calledFromInformation'][$function.':'.$lnr]['summedCallCost'] += $cost;
+
+ if(!isset($functions[$function]['subCallInformation'][$calledFunctionName.':'.$lnr]))
+ $functions[$function]['subCallInformation'][$calledFunctionName.':'.$lnr] = array('functionNr'=>$functions[$calledFunctionName]['nr'],'line'=>$lnr,'callCount'=>0,'summedCallCost'=>0);
+
+ $functions[$function]['subCallInformation'][$calledFunctionName.':'.$lnr]['callCount']++;
+ $functions[$function]['subCallInformation'][$calledFunctionName.':'.$lnr]['summedCallCost'] += $cost;
- $functions[$calledFunctionName]['callInformation'][$function.':'.$lnr]['callCount']++;
- $functions[$calledFunctionName]['callInformation'][$function.':'.$lnr]['summedCallCost'] += $cost;
} else if(strpos($line,': ')!==false){
// Found header
@@ -106,12 +114,18 @@ class Webgrind_Preprocessor
$functionAddresses = array();
foreach($functions as $functionName => $function){
$functionAddresses[] = ftell($out);
- $calledFromCount = sizeof($function['callInformation']);
- fwrite($out, pack(self::NR_FORMAT.'*', $function['summedSelfCost'], $function['summedInclusiveCost'], $function['invocationCount'], $calledFromCount));
- // Write call information
- foreach($function['callInformation'] as $call){
+ $calledFromCount = sizeof($function['calledFromInformation']);
+ $subCallCount = sizeof($function['subCallInformation']);
+ fwrite($out, pack(self::NR_FORMAT.'*', $function['summedSelfCost'], $function['summedInclusiveCost'], $function['invocationCount'], $calledFromCount, $subCallCount));
+ // Write called from information
+ foreach($function['calledFromInformation'] as $call){
fwrite($out, pack(self::NR_FORMAT.'*', $call['functionNr'], $call['line'], $call['callCount'], $call['summedCallCost']));
}
+ // Write sub call information
+ foreach($function['subCallInformation'] as $call){
+ fwrite($out, pack(self::NR_FORMAT.'*', $call['functionNr'], $call['line'], $call['callCount'], $call['summedCallCost']));
+ }
+
fwrite($out, $function['filename']."\n".$functionName."\n");
}
$headersPos = ftell($out);
diff --git a/library/Reader.php b/library/Reader.php
index dbd348c..f4a3232 100644
--- a/library/Reader.php
+++ b/library/Reader.php
@@ -10,7 +10,7 @@ class Webgrind_Reader
/**
* File format version that this reader understands
*/
- const FILE_FORMAT_VERSION = 5;
+ const FILE_FORMAT_VERSION = 6;
/**
* Binary number format used.
@@ -94,9 +94,9 @@ class Webgrind_Reader
function getFunctionInfo($nr, $costFormat = 'absolute'){
$this->seek($this->functionPos[$nr]);
- list($summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount) = $this->read(4);
+ list($summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(5);
- $this->seek(self::NR_SIZE*self::CALLINFORMATION_LENGTH*$calledFromCount, SEEK_CUR);
+ $this->seek(self::NR_SIZE*self::CALLINFORMATION_LENGTH*($calledFromCount+$subCallCount), SEEK_CUR);
$file = $this->readLine();
$function = $this->readLine();
@@ -106,7 +106,8 @@ class Webgrind_Reader
'summedSelfCost'=>$summedSelfCost,
'summedInclusiveCost'=>$summedInclusiveCost,
'invocationCount'=>$invocationCount,
- 'callInfoCount'=>$calledFromCount
+ 'calledFromInfoCount'=>$calledFromCount,
+ 'subCallInfoCount'=>$subCallCount
);
if ($costFormat == 'percentual') {
$result['summedSelfCost'] = $this->percentCost($result['summedSelfCost']);
@@ -124,9 +125,38 @@ class Webgrind_Reader
* @param $costFormat Format to return costs in. 'absolute' (default) or 'percentual'
* @return array Called from information
*/
- function getCallInfo($functionNr, $calledFromNr, $costFormat = 'absolute'){
- // 4 = number of numbers before a call information
- $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*(self::CALLINFORMATION_LENGTH*$calledFromNr+4));
+ function getCalledFromInfo($functionNr, $calledFromNr, $costFormat = 'absolute'){
+ // 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);
+
+ $result = array(
+ 'functionNr'=>$data[0],
+ 'line'=>$data[1],
+ 'callCount'=>$data[2],
+ 'summedCallCost'=>$data[3]
+ );
+
+ if ($costFormat == 'percentual') {
+ $result['summedCallCost'] = $this->percentCost($result['summedCallCost']);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Returns information about functions called by a function
+ *
+ * @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'){
+ // 4 = number of numbers before sub call count
+ $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*3);
+ $calledFromInfoCount = $this->read();
+ $this->seek( ( ($calledFromInfoCount+$subCallNr) * self::CALLINFORMATION_LENGTH + 1 ) * self::NR_SIZE,SEEK_CUR);
$data = $this->read(self::CALLINFORMATION_LENGTH);
$result = array(