Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[NEW] Simple error handling and verification of directories, issue #38

[CHANGED] Combined kind and humanKind variables, issue #39
commit b56c195ad580ed61ebdfa69acb8e4df1e92c928a 1 parent a565d32
@jokkedk authored
View
2  config.php
@@ -45,7 +45,7 @@ class Webgrind_Config{
# BELOW NOT FOR EDITING #
#########################
- static $webgrindVersion = '1.0';
+ static $webgrindVersion = '1.0.1';
/**
* Regex that matches the trace files generated by xdebug
View
0  img/call_green.png → img/call_class.png
File renamed without changes
View
0  img/call_grey.png → img/call_include.png
File renamed without changes
View
0  img/call_blue.png → img/call_internal.png
File renamed without changes
View
0  img/call_orange.png → img/call_procedural.png
File renamed without changes
View
0  img/gradient_green.png → img/gradient_class.png
File renamed without changes
View
0  img/gradient_grey.png → img/gradient_include.png
File renamed without changes
View
0  img/gradient_blue.png → img/gradient_internal.png
File renamed without changes
View
0  img/gradient_orange.png → img/gradient_procedural.png
File renamed without changes
View
204 index.php
@@ -8,7 +8,7 @@
require 'library/FileHandler.php';
// TODO: Errorhandling:
-// No files, outputdir not writabel
+// No files, outputdir not writable
set_time_limit(0);
@@ -16,83 +16,78 @@
if (ini_get('date.timezone') == '')
date_default_timezone_set( Webgrind_Config::$defaultTimezone );
+try {
+ switch(get('op')){
+ case 'file_list':
+ echo json_encode(Webgrind_FileHandler::getInstance()->getTraceList());
+ break;
+ case 'function_list':
+ $dataFile = get('dataFile');
+ if($dataFile=='0'){
+ $files = Webgrind_FileHandler::getInstance()->getTraceList();
+ $dataFile = $files[0]['filename'];
+ }
+ $reader = Webgrind_FileHandler::getInstance()->getTraceReader($dataFile, get('costFormat', Webgrind_Config::$defaultCostformat));
+ $functions = array();
+ $shownTotal = 0;
+ $breakdown = array('internal' => 0, 'procedural' => 0, 'class' => 0, 'include' => 0);
-switch(get('op')){
- case 'file_list':
- echo json_encode(Webgrind_FileHandler::getInstance()->getTraceList());
- break;
- case 'function_list':
- $dataFile = get('dataFile');
- if($dataFile=='0'){
- $files = Webgrind_FileHandler::getInstance()->getTraceList();
- $dataFile = $files[0]['filename'];
- }
- $reader = Webgrind_FileHandler::getInstance()->getTraceReader($dataFile, get('costFormat', Webgrind_Config::$defaultCostformat));
- $functions = array();
- $shownTotal = 0;
- $breakdown = array('internal' => 0, 'user' => 0, 'class' => 0, 'include' => 0);
-
- for($i=0;$i<$reader->getFunctionCount();$i++) {
- $functionInfo = $reader->getFunctionInfo($i);
+ for($i=0;$i<$reader->getFunctionCount();$i++) {
+ $functionInfo = $reader->getFunctionInfo($i);
- if (false !== strpos($functionInfo['functionName'], 'php::')) {
- $breakdown['internal'] += $functionInfo['summedSelfCost'];
- $humanKind = 'internal';
- $kind = 'blue';
- } elseif (false !== strpos($functionInfo['functionName'], 'require_once::') ||
- false !== strpos($functionInfo['functionName'], 'require::') ||
- false !== strpos($functionInfo['functionName'], 'include_once::') ||
- false !== strpos($functionInfo['functionName'], 'include::')) {
- $breakdown['include'] += $functionInfo['summedSelfCost'];
- $humanKind = 'include';
- $kind = 'grey';
- } else {
- if (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
- $breakdown['class'] += $functionInfo['summedSelfCost'];
- $humanKind = 'class';
- $kind = 'green';
- } else {
- $breakdown['user'] += $functionInfo['summedSelfCost'];
- $humanKind = 'procedural';
- $kind = 'orange';
- }
- }
- if (!(int)get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) {
- $shownTotal += $functionInfo['summedSelfCost'];
- $functions[$i] = $functionInfo;
- $functions[$i]['nr'] = $i;
- $functions[$i]['kind'] = $kind;
- $functions[$i]['humanKind'] = $humanKind;
- }
+ if (false !== strpos($functionInfo['functionName'], 'php::')) {
+ $breakdown['internal'] += $functionInfo['summedSelfCost'];
+ $humanKind = 'internal';
+ } elseif (false !== strpos($functionInfo['functionName'], 'require_once::') ||
+ false !== strpos($functionInfo['functionName'], 'require::') ||
+ false !== strpos($functionInfo['functionName'], 'include_once::') ||
+ false !== strpos($functionInfo['functionName'], 'include::')) {
+ $breakdown['include'] += $functionInfo['summedSelfCost'];
+ $humanKind = 'include';
+ } else {
+ if (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
+ $breakdown['class'] += $functionInfo['summedSelfCost'];
+ $humanKind = 'class';
+ } else {
+ $breakdown['procedural'] += $functionInfo['summedSelfCost'];
+ $humanKind = 'procedural';
+ }
+ }
+ if (!(int)get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) {
+ $shownTotal += $functionInfo['summedSelfCost'];
+ $functions[$i] = $functionInfo;
+ $functions[$i]['nr'] = $i;
+ $functions[$i]['humanKind'] = $humanKind;
+ }
- }
- usort($functions,'costCmp');
+ }
+ usort($functions,'costCmp');
- $remainingCost = $shownTotal*get('showFraction');
+ $remainingCost = $shownTotal*get('showFraction');
- $result['functions'] = array();
- foreach($functions as $function){
+ $result['functions'] = array();
+ foreach($functions as $function){
- $remainingCost -= $function['summedSelfCost'];
+ $remainingCost -= $function['summedSelfCost'];
$function['file'] = urlencode($function['file']);
- $result['functions'][] = $function;
- if($remainingCost<0)
- break;
- }
- $result['summedInvocationCount'] = $reader->getFunctionCount();
- $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
- $result['dataFile'] = $dataFile;
- $result['invokeUrl'] = $reader->getHeader('cmd');
- $result['runs'] = $reader->getHeader('runs');
- $result['breakdown'] = $breakdown;
- $result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::xdebugOutputDir().$dataFile));
- echo json_encode($result);
- break;
- case 'callinfo_list':
- $reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file'), get('costFormat', Webgrind_Config::$defaultCostformat));
- $functionNr = get('functionNr');
- $function = $reader->getFunctionInfo($functionNr);
+ $result['functions'][] = $function;
+ if($remainingCost<0)
+ break;
+ }
+ $result['summedInvocationCount'] = $reader->getFunctionCount();
+ $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
+ $result['dataFile'] = $dataFile;
+ $result['invokeUrl'] = $reader->getHeader('cmd');
+ $result['runs'] = $reader->getHeader('runs');
+ $result['breakdown'] = $breakdown;
+ $result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::xdebugOutputDir().$dataFile));
+ echo json_encode($result);
+ break;
+ case 'callinfo_list':
+ $reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file'), get('costFormat', Webgrind_Config::$defaultCostformat));
+ $functionNr = get('functionNr');
+ $function = $reader->getFunctionInfo($functionNr);
$result = array('calledFrom'=>array(), 'subCalls'=>array());
$foundInvocations = 0;
@@ -106,44 +101,57 @@
}
$result['calledByHost'] = ($foundInvocations<$function['invocationCount']);
- for($i=0;$i<$function['subCallInfoCount'];$i++){
+ for($i=0;$i<$function['subCallInfoCount'];$i++){
$invo = $reader->getSubCallInfo($functionNr, $i);
$callInfo = $reader->getFunctionInfo($invo['functionNr']);
$invo['file'] = urlencode($function['file']); // Sub call to $callInfo['file'] but from $function['file']
$invo['callerFunctionName'] = $callInfo['functionName'];
$result['subCalls'][] = $invo;
}
- echo json_encode($result);
-
- break;
- case 'fileviewer':
- $file = get('file');
- $line = get('line');
+ echo json_encode($result);
+ break;
+ case 'fileviewer':
+ $file = get('file');
+ $line = get('line');
- if($file && $file!=''){
- $message = '';
- if(!file_exists($file)){
- $message = $file.' does not exist.';
- } else if(!is_readable($file)){
- $message = $file.' is not readable.';
- } else if(is_dir($file)){
- $message = $file.' is a directory.';
- }
- } else {
- $message = 'No file to view';
- }
- require 'templates/fileviewer.phtml';
+ if($file && $file!=''){
+ $message = '';
+ if(!file_exists($file)){
+ $message = $file.' does not exist.';
+ } else if(!is_readable($file)){
+ $message = $file.' is not readable.';
+ } else if(is_dir($file)){
+ $message = $file.' is a directory.';
+ }
+ } else {
+ $message = 'No file to view';
+ }
+ require 'templates/fileviewer.phtml';
- break;
- case 'version_info':
- $response = @file_get_contents('http://jokke.dk/webgrindupdate.json?version='.Webgrind_Config::$webgrindVersion);
- echo $response;
- break;
- default:
- require 'templates/index.phtml';
+ break;
+ case 'version_info':
+ $response = @file_get_contents('http://jokke.dk/webgrindupdate.json?version='.Webgrind_Config::$webgrindVersion);
+ echo $response;
+ break;
+ default:
+ $welcome = '';
+ if (!file_exists(Webgrind_Config::storageDir()) || !is_writable(Webgrind_Config::storageDir())) {
+ $welcome .= 'Webgrind $storageDir does not exist or is not writeable: "'.Webgrind_Config::storageDir().'"<br>';
+ }
+ if (!file_exists(Webgrind_Config::xdebugOutputDir()) || !is_readable(Webgrind_Config::xdebugOutputDir())) {
+ $welcome .= 'Webgrind $profilerDir does not exist or is not readable: "'.Webgrind_Config::xdebugOutputDir().'"<br>';
+ }
+
+ if ($welcome == '') {
+ $welcome = 'Select a cachegrind file above';
+ }
+ require 'templates/index.phtml';
+ }
+} catch (Exception $e) {
+ echo json_encode(array('error' => $e->getMessage().'<br>'.$e->getFile().', line '.$e->getLine()));
+ return;
}
-
function get($param, $default=false){
return (isset($_GET[$param])? $_GET[$param] : $default);
}
View
26 templates/index.phtml
@@ -30,6 +30,11 @@
$.getJSON("index.php",
vars,
function(data){
+ if (data.error) {
+ $("#hello_message").html(data.error);
+ $("#hello_message").show();
+ return;
+ }
callInfoLoaded = new Array();
$("#function_table tbody").empty();
for(i=0;i<data.functions.length;i++){
@@ -46,13 +51,13 @@
$("#runtime_sum").html(data.summedRunTime);
$("#runs").html(data.runs);
- var breakdown_sum = data.breakdown['internal']+data.breakdown['user']+data.breakdown['class']+data.breakdown['include'];
+ var breakdown_sum = data.breakdown['internal']+data.breakdown['procedural']+data.breakdown['class']+data.breakdown['include'];
$("#breakdown").html(
'<img src="img/gradient_left.png" height="20" width="10">'+
- '<img src="img/gradient_blue.png" height="20" width="'+Math.floor(data.breakdown['internal']/breakdown_sum*300)+'">'+
- '<img src="img/gradient_grey.png" height="20" width="'+Math.floor(data.breakdown['include']/breakdown_sum*300)+'">'+
- '<img src="img/gradient_green.png" height="20" width="'+Math.floor(data.breakdown['class']/breakdown_sum*300)+'">'+
- '<img src="img/gradient_orange.png" height="20" width="'+Math.floor(data.breakdown['user']/breakdown_sum*300)+'">'+
+ '<img src="img/gradient_internal.png" height="20" width="'+Math.floor(data.breakdown['internal']/breakdown_sum*300)+'">'+
+ '<img src="img/gradient_include.png" height="20" width="'+Math.floor(data.breakdown['include']/breakdown_sum*300)+'">'+
+ '<img src="img/gradient_class.png" height="20" width="'+Math.floor(data.breakdown['class']/breakdown_sum*300)+'">'+
+ '<img src="img/gradient_procedural.png" height="20" width="'+Math.floor(data.breakdown['procedural']/breakdown_sum*300)+'">'+
'<img src="img/gradient_right.png" height="20" width="10">'+
'<div title="internal functions, include/require, class methods and procedural functions." style="background:url(img/gradient_markers.png);position:relative;top:-20px;left:10px;width:301px;height:19px"></div>'
);
@@ -85,7 +90,12 @@
$.getJSON("index.php",
{'op':'callinfo_list', 'file':currentDataFile, 'functionNr':functionNr, 'costFormat':$("#costFormat").val()},
function(data){
-
+ if (data.error) {
+ $("#hello_message").html(data.error);
+ $("#hello_message").show();
+ return;
+ }
+
if(data.calledByHost)
$("#callinfo_area_"+functionNr).append('<b>Called from script host</b>');
@@ -169,7 +179,7 @@
openLink = (data.file=='php:internal')?'':'<a title="Open file" href="'+sprintf(fileUrlFormat,data.file,-1)+'" target="_blank"><img src="img/file.png" alt="O"></a>';
return '<tr> \
<td> \
- <img src="img/call_'+data.kind+'.png" title="'+data.humanKind+'"> \
+ <img src="img/call_'+data.humanKind+'.png" title="'+data.humanKind+'"> \
</td> \
<td> \
<a href="javascript:toggleCallInfo('+data.nr+')"> \
@@ -317,7 +327,7 @@
</tbody>
</table>
</div>
- <h2 id="hello_message">Select a cachegrind file above</h2>
+ <h2 id="hello_message"><?=$welcome?></h2>
<div id="footer">
<?php if(Webgrind_Config::$checkVersion):?>
<div id="version_info">&nbsp;</div>
Please sign in to comment.
Something went wrong with that request. Please try again.