-
Notifications
You must be signed in to change notification settings - Fork 1
Add Memory support #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ada7f44
648de4c
b638910
b5aa9f6
0cfb031
30066e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,10 +42,11 @@ class Webgrind_Preprocessor | |
| * @param string $outFile File to write preprocessed data to | ||
| * @return void | ||
| */ | ||
| static function parse($inFile, $outFile) | ||
| static function parse($inFile, $outFile, $readMemory = false) | ||
| { | ||
| $costPattern = $readMemory ? "%*d %d" : "%d"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the reason for this pattern?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, every "cost line" looks like this: When we want to read memory, we effectively need to skip the time cost and read the last number (which is normally unread). |
||
| // If possible, use the binary preprocessor | ||
| if (self::binaryParse($inFile, $outFile)) { | ||
| if (self::binaryParse($inFile, $outFile, $readMemory)) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -74,17 +75,17 @@ static function parse($inFile, $outFile) | |
| $buffer = fgets($in); | ||
| if(strlen($buffer) > 0 && ctype_digit($buffer[0])) { | ||
| // Cost line | ||
| sscanf($buffer, "%d %d", $lnr, $cost); | ||
| sscanf($buffer, "%d $costPattern", $lnr, $cost); | ||
| } else { | ||
| // Special case for ENTRY_POINT - it contains summary header | ||
| $headers[] = fgets($in); | ||
| fgets($in); | ||
| // Cost line | ||
| fscanf($in, "%d %d", $lnr, $cost); | ||
| fscanf($in, "%d $costPattern", $lnr, $cost); | ||
| } | ||
| } else { | ||
| // Cost line | ||
| fscanf($in, "%d %d", $lnr, $cost); | ||
| fscanf($in, "%d $costPattern", $lnr, $cost); | ||
| } | ||
|
|
||
| if (!isset($functionNames[$function])) { | ||
|
|
@@ -114,7 +115,7 @@ static function parse($inFile, $outFile) | |
| // Skip call line | ||
| fgets($in); | ||
| // Cost line | ||
| fscanf($in, "%d %d", $lnr, $cost); | ||
| fscanf($in, "%d $costPattern", $lnr, $cost); | ||
|
|
||
| // Current function is a proxy -> skip | ||
| if (isset($proxyQueue[$index])) { | ||
|
|
@@ -139,15 +140,25 @@ static function parse($inFile, $outFile) | |
|
|
||
| $key = $index.$lnr; | ||
| if (!isset($functions[$calledIndex]['calledFromInformation'][$key])) { | ||
| $functions[$calledIndex]['calledFromInformation'][$key] = array('functionNr'=>$index,'line'=>$lnr,'callCount'=>0,'summedCallCost'=>0); | ||
| $functions[$calledIndex]['calledFromInformation'][$key] = array( | ||
| 'functionNr'=>$index, | ||
| 'line'=>$lnr, | ||
| 'callCount'=>0, | ||
| 'summedCallCost'=>0, | ||
| ); | ||
| } | ||
|
|
||
| $functions[$calledIndex]['calledFromInformation'][$key]['callCount']++; | ||
| $functions[$calledIndex]['calledFromInformation'][$key]['summedCallCost'] += $cost; | ||
|
|
||
| $calledKey = $calledIndex.$lnr; | ||
| if (!isset($functions[$index]['subCallInformation'][$calledKey])) { | ||
| $functions[$index]['subCallInformation'][$calledKey] = array('functionNr'=>$calledIndex,'line'=>$lnr,'callCount'=>0,'summedCallCost'=>0); | ||
| $functions[$index]['subCallInformation'][$calledKey] = array( | ||
| 'functionNr'=>$calledIndex, | ||
| 'line'=>$lnr, | ||
| 'callCount'=>0, | ||
| 'summedCallCost'=>0, | ||
| ); | ||
| } | ||
|
|
||
| $functions[$index]['subCallInformation'][$calledKey]['callCount']++; | ||
|
|
@@ -171,14 +182,27 @@ static function parse($inFile, $outFile) | |
| $functionAddresses[] = ftell($out); | ||
| $calledFromCount = sizeof($function['calledFromInformation']); | ||
| $subCallCount = sizeof($function['subCallInformation']); | ||
| fwrite($out, pack(self::NR_FORMAT.'*', $function['line'], $function['summedSelfCost'], $function['summedInclusiveCost'], $function['invocationCount'], $calledFromCount, $subCallCount)); | ||
| fwrite($out, pack(self::NR_FORMAT.'*', | ||
| $function['line'], | ||
| $function['summedSelfCost'], | ||
| $function['summedInclusiveCost'], | ||
| $function['invocationCount'], | ||
| $calledFromCount, $subCallCount)); | ||
| // Write called from information | ||
| foreach ((array)$function['calledFromInformation'] as $call) { | ||
| fwrite($out, pack(self::NR_FORMAT.'*', $call['functionNr'], $call['line'], $call['callCount'], $call['summedCallCost'])); | ||
| fwrite($out, pack(self::NR_FORMAT.'*', | ||
| $call['functionNr'], | ||
| $call['line'], | ||
| $call['callCount'], | ||
| $call['summedCallCost'])); | ||
| } | ||
| // Write sub call information | ||
| foreach ((array)$function['subCallInformation'] as $call) { | ||
| fwrite($out, pack(self::NR_FORMAT.'*', $call['functionNr'], $call['line'], $call['callCount'], $call['summedCallCost'])); | ||
| fwrite($out, pack(self::NR_FORMAT.'*', | ||
| $call['functionNr'], | ||
| $call['line'], | ||
| $call['callCount'], | ||
| $call['summedCallCost'])); | ||
| } | ||
|
|
||
| fwrite($out, $function['filename']."\n".$functionNames[$index]."\n"); | ||
|
|
@@ -233,14 +257,14 @@ static function getCompressedName($name, $isFile) | |
| * @param string $outFile File to write preprocessed data to | ||
| * @return bool True if binary preprocessor was executed | ||
| */ | ||
| static function binaryParse($inFile, $outFile) | ||
| static function binaryParse($inFile, $outFile, $readMemory) | ||
| { | ||
| $preprocessor = Webgrind_Config::getBinaryPreprocessor(); | ||
| if (!is_executable($preprocessor)) { | ||
| return false; | ||
| } | ||
|
|
||
| $cmd = escapeshellarg($preprocessor).' '.escapeshellarg($inFile).' '.escapeshellarg($outFile); | ||
| $cmd = escapeshellarg($preprocessor).' '.escapeshellarg($inFile).' '.escapeshellarg($outFile).' '.($readMemory ? '1' : '0'); | ||
| foreach (Webgrind_Config::$proxyFunctions as $function) { | ||
| $cmd .= ' '.escapeshellarg($function); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Cool, you are creating two pre-processed files (one for memory, one for CPU)