diff options
author | Jacob Oettinger <jacob@oettinger.dk> | 2011-09-27 09:06:16 +0200 |
---|---|---|
committer | Jacob Oettinger <jacob@oettinger.dk> | 2011-09-27 09:06:16 +0200 |
commit | 44878d1b34a540556870e3ee68e4c1409bff020e (patch) | |
tree | 8a6b1e6a37d38e4dc7bcf94055aff7f5659ae56d | |
parent | ffb7cadda73a811b39864e17c39849bfc408fcbd (diff) | |
download | webgrind-44878d1b34a540556870e3ee68e4c1409bff020e.zip webgrind-44878d1b34a540556870e3ee68e4c1409bff020e.tar.gz webgrind-44878d1b34a540556870e3ee68e4c1409bff020e.tar.bz2 |
xdebug 2.2 fixes a bug that makes it possible to link to function/method definitions
Enable links directly to function definitions if xdebug version is greater than or equal to 2.2.
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | library/Reader.php | 22 | ||||
-rw-r--r-- | templates/index.phtml | 10 |
3 files changed, 27 insertions, 9 deletions
@@ -87,6 +87,10 @@ try { $result['runs'] = $reader->getHeader('runs'); $result['breakdown'] = $breakdown; $result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::xdebugOutputDir().$dataFile)); + + $version = preg_replace('/[^0-9\.]/', '', $reader->getHeader('creator')); + $result['linkToFunctionLine'] = version_compare($version, '2.2') > 0; + echo json_encode($result); break; case 'callinfo_list': diff --git a/library/Reader.php b/library/Reader.php index c5e1b56..f4bf9e3 100644 --- a/library/Reader.php +++ b/library/Reader.php @@ -28,7 +28,12 @@ class Webgrind_Reader */ const CALLINFORMATION_LENGTH = 4; - /** + /** + * Length of a function information block + */ + const FUNCTIONINFORMATION_LENGTH = 6; + + /** * Address of the headers in the data file * * @var int @@ -103,7 +108,7 @@ class Webgrind_Reader function getFunctionInfo($nr){ $this->seek($this->functionPos[$nr]); - list($summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(5); + list($line, $summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(self::FUNCTIONINFORMATION_LENGTH); $this->seek(self::NR_SIZE*self::CALLINFORMATION_LENGTH*($calledFromCount+$subCallCount), SEEK_CUR); $file = $this->readLine(); @@ -111,6 +116,7 @@ class Webgrind_Reader $result = array( 'file'=>$file, + 'line'=>$line, 'functionName'=>$function, 'summedSelfCost'=>$summedSelfCost, 'summedInclusiveCost'=>$summedInclusiveCost, @@ -132,8 +138,12 @@ class Webgrind_Reader * @return array Called from information */ 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)); + $this->seek( + $this->functionPos[$functionNr] + + self::NR_SIZE + * (self::CALLINFORMATION_LENGTH * $calledFromNr + self::FUNCTIONINFORMATION_LENGTH) + ); + $data = $this->read(self::CALLINFORMATION_LENGTH); $result = array( @@ -156,8 +166,8 @@ class Webgrind_Reader * @return array Sub call information */ function getSubCallInfo($functionNr, $subCallNr){ - // 4 = number of numbers before sub call count - $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*3); + // Sub call count is the second last number in the FUNCTION_INFORMATION block + $this->seek($this->functionPos[$functionNr] + self::NR_SIZE * (self::FUNCTIONINFORMATION_LENGTH - 2)); $calledFromInfoCount = $this->read(); $this->seek( ( ($calledFromInfoCount+$subCallNr) * self::CALLINFORMATION_LENGTH + 1 ) * self::NR_SIZE,SEEK_CUR); $data = $this->read(self::CALLINFORMATION_LENGTH); diff --git a/templates/index.phtml b/templates/index.phtml index e8770c7..7c3771a 100644 --- a/templates/index.phtml +++ b/templates/index.phtml @@ -39,7 +39,7 @@ $("#function_table tbody").empty(); for(i=0;i<data.functions.length;i++){ callInfoLoaded[data.functions[i].nr] = false; - $("#function_table tbody").append(functionTableRow(data.functions[i])); + $("#function_table tbody").append(functionTableRow(data.functions[i], data.linkToFunctionLine)); } currentDataFile = data.dataFile; $("#data_file").html(data.dataFile); @@ -185,11 +185,15 @@ } } - function functionTableRow(data){ + function functionTableRow(data, linkToFunctionLine){ if (data.file=='php%3Ainternal') { openLink = '<a title="Lookup function" href="<?php echo ini_get('xdebug.manual_url')?>/'+data.functionName.substr(5)+'" target="_blank"><img src="img/file.png" alt="O"></a>';; } else { - openLink = '<a title="Open file" href="'+sprintf(fileUrlFormat,data.file,-1)+'" target="_blank"><img src="img/file.png" alt="O"></a>'; + if(linkToFunctionLine){ + openLink = '<a title="Open file and show line" href="'+sprintf(fileUrlFormat, data.file, data.line)+'" target="_blank"><img src="img/file_line.png" alt="O"></a>'; + } else { + openLink = '<a title="Open file" href="'+sprintf(fileUrlFormat, data.file, -1)+'" target="_blank"><img src="img/file.png" alt="O"></a>'; + } } return '<tr> \ <td> \ |