summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlpha <ngcoder@live.com>2015-07-23 10:33:56 -0400
committerAlpha <ngcoder@live.com>2015-07-23 10:33:56 -0400
commit3f42a3f8c724f7a39b4e492a0a4a781d9be3104b (patch)
tree4aa6760a669bcbe0c7b57879267e49436ce2face
parentc64e82bd340cec4829199564a90904b0066e4a12 (diff)
parenta3ef3df752e246ff1845b3a8d115e015fd0c4fae (diff)
downloadwebgrind-3f42a3f8c724f7a39b4e492a0a4a781d9be3104b.zip
webgrind-3f42a3f8c724f7a39b4e492a0a4a781d9be3104b.tar.gz
webgrind-3f42a3f8c724f7a39b4e492a0a4a781d9be3104b.tar.bz2
Merge pull request #43 from KarneAsada/master
Added config option to change graph image output type
-rw-r--r--config.php6
-rw-r--r--index.php26
-rw-r--r--library/Preprocessor.php6
3 files changed, 25 insertions, 13 deletions
diff --git a/config.php b/config.php
index bf3234c..7f536d6 100644
--- a/config.php
+++ b/config.php
@@ -24,6 +24,12 @@ class Webgrind_Config extends Webgrind_MasterConfig {
*/
static $preprocessedSuffix = '.webgrind';
+ /**
+ * Image type of graph to output
+ * Can be png or svg
+ */
+ static $graphImageType = 'png';
+
static $defaultTimezone = 'Europe/Copenhagen';
static $dateFormat = 'Y-m-d H:i:s';
static $defaultCostformat = 'percent'; // 'percent', 'usec' or 'msec'
diff --git a/index.php b/index.php
index 4826904..d89dc85 100644
--- a/index.php
+++ b/index.php
@@ -45,7 +45,7 @@ try {
if (false !== strpos($functionInfo['functionName'], 'php::')) {
$breakdown['internal'] += $functionInfo['summedSelfCost'];
$humanKind = 'internal';
- } elseif (false !== strpos($functionInfo['functionName'], 'require_once::') ||
+ } else if (false !== strpos($functionInfo['functionName'], 'require_once::') ||
false !== strpos($functionInfo['functionName'], 'require::') ||
false !== strpos($functionInfo['functionName'], 'include_once::') ||
false !== strpos($functionInfo['functionName'], 'include::')) {
@@ -102,7 +102,7 @@ try {
$result = array('calledFrom'=>array(), 'subCalls'=>array());
$foundInvocations = 0;
- for($i=0;$i<$function['calledFromInfoCount'];$i++){
+ for ($i=0; $i<$function['calledFromInfoCount']; $i++) {
$invo = $reader->getCalledFromInfo($functionNr, $i);
$foundInvocations += $invo['callCount'];
$callerInfo = $reader->getFunctionInfo($invo['functionNr']);
@@ -126,13 +126,13 @@ try {
$file = get('file');
$line = get('line');
- if($file && $file!=''){
+ if ($file && $file!='') {
$message = '';
- if(!file_exists($file)){
+ if (!file_exists($file)) {
$message = $file.' does not exist.';
- } else if(!is_readable($file)){
+ } else if (!is_readable($file)) {
$message = $file.' is not readable.';
- } else if(is_dir($file)){
+ } else if (is_dir($file)) {
$message = $file.' is a directory.';
}
} else {
@@ -144,14 +144,20 @@ try {
case 'function_graph':
$dataFile = get('dataFile');
$showFraction = 100 - intval(get('showFraction') * 100);
- if($dataFile == '0'){
+ if ($dataFile == '0') {
$files = Webgrind_FileHandler::getInstance()->getTraceList();
$dataFile = $files[0]['filename'];
}
- header("Content-Type: image/png");
- $filename = Webgrind_Config::storageDir().$dataFile.'-'.$showFraction.Webgrind_Config::$preprocessedSuffix.'.png';
+
+ if (Webgrind_Config::$graphImageType == 'svg') {
+ header("Content-Type: image/svg+xml");
+ } else {
+ header("Content-Type: image/".Webgrind_Config::$graphImageType);
+ }
+
+ $filename = Webgrind_Config::storageDir().$dataFile.'-'.$showFraction.Webgrind_Config::$preprocessedSuffix.'.'.Webgrind_Config::$graphImageType;
if (!file_exists($filename)) {
- shell_exec(Webgrind_Config::$pythonExecutable.' library/gprof2dot.py -n '.$showFraction.' -f callgrind '.Webgrind_Config::xdebugOutputDir().''.$dataFile.' | '.Webgrind_Config::$dotExecutable.' -Tpng -o ' . $filename);
+ shell_exec(Webgrind_Config::$pythonExecutable.' library/gprof2dot.py -n '.$showFraction.' -f callgrind '.Webgrind_Config::xdebugOutputDir().''.$dataFile.' | '.Webgrind_Config::$dotExecutable.' -T'.Webgrind_Config::$graphImageType.' -o ' . $filename);
}
readfile($filename);
break;
diff --git a/library/Preprocessor.php b/library/Preprocessor.php
index 59a33cd..2291006 100644
--- a/library/Preprocessor.php
+++ b/library/Preprocessor.php
@@ -88,7 +88,7 @@ class Webgrind_Preprocessor
$functions[$index]['summedSelfCost'] += $cost;
$functions[$index]['summedInclusiveCost'] += $cost;
}
- } elseif (substr($line,0,4)==='cfn=') {
+ } else if (substr($line,0,4)==='cfn=') {
// Found call to function. ($function should contain function call originates from)
$calledFunctionName = substr(trim($line),4);
// Skip call line
@@ -115,7 +115,7 @@ class Webgrind_Preprocessor
$functions[$index]['subCallInformation'][$calledKey]['callCount']++;
$functions[$index]['subCallInformation'][$calledKey]['summedCallCost'] += $cost;
- } elseif (strpos($line,': ')!==false) {
+ } else if (strpos($line,': ')!==false) {
// Found header
$headers[] = $line;
}
@@ -129,7 +129,7 @@ class Webgrind_Preprocessor
// Make room for function addresses
fseek($out,self::NR_SIZE*$functionCount, SEEK_CUR);
$functionAddresses = array();
- foreach($functions as $index=>$function){
+ foreach ($functions as $index=>$function) {
$functionAddresses[] = ftell($out);
$calledFromCount = sizeof($function['calledFromInformation']);
$subCallCount = sizeof($function['subCallInformation']);