1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-07 14:46:50 +02:00

profiler fix

This commit is contained in:
David Grudl
2010-04-03 22:51:46 +02:00
parent 3f6a075251
commit 52f8128a2f
3 changed files with 81 additions and 1035 deletions

View File

@@ -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();
}

View File

@@ -21,10 +21,10 @@
class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebugPanel
{
/** maximum number of rows */
const MAX_ROWS = 30;
static public $maxQueries = 30;
/** maximum SQL length */
const MAX_LENGTH = 500;
static public $maxLength = 1000;
/** @var string Name of the file where SQL errors should be logged */
private $file;
@@ -118,14 +118,13 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
$count = '?';
}
if (count(self::$table) < self::MAX_ROWS) {
if (count(self::$table) < self::$maxQueries) {
self::$table[] = array(
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,
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
);
}
if ($this->useFirebug && !headers_sent()) {
header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
@@ -145,6 +144,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
}
header("X-Wf-dibi-1-1-d$num: |$s|");
}
}
if ($this->file) {
$this->writeFile(
@@ -228,19 +228,15 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
if (!dibi::$numOfQueries) return;
$content = '<h1>SQL queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>';
if (self::$table) {
$content .= '<table>';
$content .= '<table class="nette-inner">';
foreach (self::$table as $i => $row) {
if ($i === 0) {
$content .= "<tr><th>$row[0]</th><th>$row[1]</th><th>$row[2]</th><th>$row[3]</th></tr>";
} else {
$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 .= "<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 .= '</table>';
} else {
$content .= '<p>no query</p>';
}
return $content;
}

File diff suppressed because one or more lines are too long