mirror of
https://github.com/dg/dibi.git
synced 2025-08-08 07:06:52 +02:00
profiler fix
This commit is contained in:
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nette Framework
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
|
|
||||||
*
|
|
||||||
* This source file is subject to the "Nette license" that is bundled
|
|
||||||
* with this package in the file license.txt.
|
|
||||||
*
|
|
||||||
* For more information please see http://nettephp.com
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2004, 2010 David Grudl
|
|
||||||
* @license http://nettephp.com/license Nette license
|
|
||||||
* @link http://nettephp.com
|
|
||||||
* @category Nette
|
|
||||||
* @package Nette
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*namespace Nette;*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom output for Nette\Debug.
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2004, 2010 David Grudl
|
|
||||||
* @package Nette
|
|
||||||
*/
|
|
||||||
interface IDebuggable
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns custom panels.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function getPanels();
|
|
||||||
|
|
||||||
}
|
|
@@ -21,10 +21,10 @@
|
|||||||
class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebugPanel
|
class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebugPanel
|
||||||
{
|
{
|
||||||
/** maximum number of rows */
|
/** maximum number of rows */
|
||||||
const MAX_ROWS = 30;
|
static public $maxQueries = 30;
|
||||||
|
|
||||||
/** maximum SQL length */
|
/** maximum SQL length */
|
||||||
const MAX_LENGTH = 500;
|
static public $maxLength = 1000;
|
||||||
|
|
||||||
/** @var string Name of the file where SQL errors should be logged */
|
/** @var string Name of the file where SQL errors should be logged */
|
||||||
private $file;
|
private $file;
|
||||||
@@ -118,32 +118,32 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
|
|||||||
$count = '?';
|
$count = '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(self::$table) < self::MAX_ROWS) {
|
if (count(self::$table) < self::$maxQueries) {
|
||||||
self::$table[] = array(
|
self::$table[] = array(
|
||||||
sprintf('%0.3f', dibi::$elapsedTime * 1000),
|
sprintf('%0.3f', dibi::$elapsedTime * 1000),
|
||||||
strlen($sql) > self::MAX_LENGTH ? substr($sql, 0, self::MAX_LENGTH) . '...' : $sql,
|
strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql,
|
||||||
$count,
|
$count,
|
||||||
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->useFirebug && !headers_sent()) {
|
if ($this->useFirebug && !headers_sent()) {
|
||||||
header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
|
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-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');
|
header('X-Wf-dibi-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
|
||||||
|
|
||||||
$payload = json_encode(array(
|
$payload = json_encode(array(
|
||||||
array(
|
array(
|
||||||
'Type' => 'TABLE',
|
'Type' => 'TABLE',
|
||||||
'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)',
|
'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)',
|
||||||
),
|
),
|
||||||
self::$table,
|
self::$table,
|
||||||
));
|
));
|
||||||
foreach (str_split($payload, 4990) as $num => $s) {
|
foreach (str_split($payload, 4990) as $num => $s) {
|
||||||
$num++;
|
$num++;
|
||||||
header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index
|
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) {
|
if ($this->file) {
|
||||||
@@ -228,19 +228,15 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
|
|||||||
if (!dibi::$numOfQueries) return;
|
if (!dibi::$numOfQueries) return;
|
||||||
|
|
||||||
$content = '<h1>SQL queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>';
|
$content = '<h1>SQL queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>';
|
||||||
if (self::$table) {
|
$content .= '<table class="nette-inner">';
|
||||||
$content .= '<table>';
|
foreach (self::$table as $i => $row) {
|
||||||
foreach (self::$table as $i => $row) {
|
if ($i === 0) {
|
||||||
if ($i === 0) {
|
$content .= "<tr><th>$row[0]</th><th>$row[1]</th><th>$row[2]</th><th>$row[3]</th></tr>";
|
||||||
$content .= "<tr><th>$row[0]</th><th>$row[1]</th><th>$row[2]</th><th>$row[3]</th></tr>";
|
} else {
|
||||||
} else {
|
$content .= "<tr ".($i%2 ? 'class="nette-alt"':'')."><td>$row[0]</td><td><code>$row[1]</code></td><td>$row[2]</td><td>$row[3]</td></tr>";
|
||||||
$content .= "<tr ".($i%2 ? 'class="nette-alt"':'')."><td>$row[0]</td> <td>$row[1]</td><td>$row[2]</td><td>$row[3]</td></tr>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$content .= '</table>';
|
|
||||||
} else {
|
|
||||||
$content .= '<p>no query</p>';
|
|
||||||
}
|
}
|
||||||
|
$content .= '</table>';
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user