From 52f8128a2fd2f0a0654179ee6468016af37297e9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 3 Apr 2010 22:51:46 +0200 Subject: [PATCH] profiler fix --- dibi/Nette/IDebuggable.php | 39 -- dibi/libs/DibiProfiler.php | 58 +- examples/Nette/Debug.php | 1019 ++---------------------------------- 3 files changed, 81 insertions(+), 1035 deletions(-) delete mode 100644 dibi/Nette/IDebuggable.php diff --git a/dibi/Nette/IDebuggable.php b/dibi/Nette/IDebuggable.php deleted file mode 100644 index da195ff2..00000000 --- a/dibi/Nette/IDebuggable.php +++ /dev/null @@ -1,39 +0,0 @@ - self::MAX_LENGTH ? substr($sql, 0, self::MAX_LENGTH) . '...' : $sql, + strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql, $count, $connection->getConfig('driver') . '/' . $connection->getConfig('name') ); - } - if ($this->useFirebug && !headers_sent()) { - header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); - header('X-Wf-dibi-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0'); - header('X-Wf-dibi-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); + if ($this->useFirebug && !headers_sent()) { + header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); + header('X-Wf-dibi-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0'); + header('X-Wf-dibi-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); - $payload = json_encode(array( - array( - 'Type' => 'TABLE', - 'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)', - ), - self::$table, - )); - foreach (str_split($payload, 4990) as $num => $s) { - $num++; - header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index + $payload = json_encode(array( + array( + 'Type' => 'TABLE', + 'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)', + ), + self::$table, + )); + foreach (str_split($payload, 4990) as $num => $s) { + $num++; + header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index + } + header("X-Wf-dibi-1-1-d$num: |$s|"); } - header("X-Wf-dibi-1-1-d$num: |$s|"); } if ($this->file) { @@ -228,19 +228,15 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug if (!dibi::$numOfQueries) return; $content = '

SQL queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '

'; - if (self::$table) { - $content .= ''; - foreach (self::$table as $i => $row) { - if ($i === 0) { - $content .= ""; - } else { - $content .= ""; - } + $content .= '
$row[0]$row[1]$row[2]$row[3]
$row[0] $row[1]$row[2]$row[3]
'; + foreach (self::$table as $i => $row) { + if ($i === 0) { + $content .= ""; + } else { + $content .= ""; } - $content .= '
$row[0]$row[1]$row[2]$row[3]
$row[0]$row[1]$row[2]$row[3]
'; - } else { - $content .= '

no query

'; } + $content .= ''; return $content; } diff --git a/examples/Nette/Debug.php b/examples/Nette/Debug.php index e6515d11..3cb01fda 100644 --- a/examples/Nette/Debug.php +++ b/examples/Nette/Debug.php @@ -70,733 +70,37 @@ _shutdownHandler(){static$types=array(E_ERROR=>1,E_CORE_ERROR=>1,E_COMPILE_ERROR FatalErrorException($error['message'],0,$error['type'],$error['file'],$error['line'],NULL),TRUE);}if(self::$enabledBar&&!self::$productionMode&&!self::$ajaxDetected){foreach(headers_list()as$header){if(strncasecmp($header,'Content-Type:',13)===0){if(substr($header,14,9)==='text/html'){break;}return;}}$panels=array();foreach(self::$panels as$panel){$panels[]=array('id'=>preg_replace('#[^a-z0-9]+#i','-',$panel->getId()),'tab'=>$tab=(string)$panel->getTab(),'panel'=>$tab?(string)$panel->getPanel():NULL);}?> - - - - - + + + + + + + + @@ -805,17 +109,16 @@ Nette.Debug.Bar = Nette.Class({
    +
  • ',trim($panel['tab']),'
';endif?> -
  • +
  • ×
  • -
    -
    -
    +
    @@ -825,8 +128,8 @@ as$id=>$panel):?>
    - - + ¤ + ×
    @@ -835,18 +138,13 @@ as$id=>$panel):?> - -(new Nette.Debug.Bar).init(); -document.body.appendChild( Nette.Q.factory('#nette-debug').show().dom() ); - -/* ]]> */ - -".self::_dump($var,0)."\n";if(self::$showLocation){$trace=debug_backtrace();$i=isset($trace[1]['class'])&&$trace[1]['class']===__CLASS__?1:0;if(isset($trace[$i]['file'],$trace[$i]['line'])){$output=substr_replace($output,' '.htmlspecialchars("in file {$trace[$i]['file']} on line {$trace[$i]['line']}",ENT_NOQUOTES).'',-8,0);}}if(self::$consoleMode){$output=htmlspecialchars_decode(strip_tags($output),ENT_NOQUOTES);}if($return){return$output;}else{echo$output;return$var;}}public +dump($var,$return=FALSE){if(!$return&&self::$productionMode){return$var;}$output="
    ".self::_dump($var,0)."
    \n";if(self::$showLocation){$trace=debug_backtrace();$i=isset($trace[1]['class'])&&$trace[1]['class']===__CLASS__?1:0;if(isset($trace[$i]['file'],$trace[$i]['line'])){$output=substr_replace($output,' '.htmlspecialchars("in file {$trace[$i]['file']} on line {$trace[$i]['line']}",ENT_NOQUOTES).'',-8,0);}}if(self::$consoleMode){$output=htmlspecialchars_decode(strip_tags($output),ENT_NOQUOTES);}if($return){return$output;}else{echo$output;return$var;}}public static function barDump($var,$title=NULL){if(!self::$productionMode){$dump=array();foreach((is_array($var)?$var:array(''=>$var))as$key=>$val){$dump[$key]=self::dump($val,TRUE);}self::$dumps[]=array('title'=>$title,'dump'=>$dump);}return$var;}private @@ -899,7 +197,7 @@ ReflectionClass($class);$internals[$rc->getFileName()]=TRUE;}}if(class_exists('E _netteDebugPrintCode($file,$line,$count=15){if(function_exists('ini_set')){ini_set('highlight.comment','#999; font-style: italic');ini_set('highlight.default','#000');ini_set('highlight.html','#06b');ini_set('highlight.keyword','#d24; font-weight: bold');ini_set('highlight.string','#080');}$start=max(1,$line-floor($count/2));$source=@file_get_contents($file);if(!$source)return;$source=explode("\n",highlight_string($source,TRUE));$spans=1;echo$source[0];$source=explode('
    ',$source[1]);array_unshift($source,NULL);$i=$start;while(--$i>=1){if(preg_match('#.*(]*>)#',$source[$i],$m)){if($m[1]!==''){$spans++;echo$m[1];}break;}}$source=array_slice($source,$start,$count,TRUE);end($source);$numWidth=strlen((string)key($source));foreach($source as$n=>$s){$spans+=substr_count($s,'Line %{$numWidth}s: %s\n%s",$n,strip_tags($s),preg_replace('#[^>]*(<[^>]+>)[^<]*#','$1',$s));}else{printf("Line %{$numWidth}s: %s\n",$n,$s);}}echo str_repeat('',$spans),'';}function -_netteDump($dump){return'
    '.preg_replace_callback('#(^|\s+)?(.*)\((\d+)\) #','_netteDumpCb',$dump).'
    ';}function +_netteDump($dump){return'
    '.preg_replace_callback('#(^|\s+)?(.*)\((\d+)\) #','_netteDumpCb',$dump).'
    ';}function _netteDumpCb($m){return"$m[1]$m[2]($m[3]) ".(trim($m[1])||$m[3]<7?' ':'