mirror of
https://github.com/Oreolek/debug-toolbar.git
synced 2024-06-28 20:34:58 +03:00
add firephp support
This commit is contained in:
parent
0f169d3ad6
commit
ac069fdc9e
|
@ -20,7 +20,11 @@ class DebugToolbar
|
||||||
if (Kohana::config('debug_toolbar.panels.database') === TRUE)
|
if (Kohana::config('debug_toolbar.panels.database') === TRUE)
|
||||||
{
|
{
|
||||||
$queries = self::get_queries();
|
$queries = self::get_queries();
|
||||||
$template->set('queries', $queries['data'])->set('query_count', $queries['count']);
|
$template
|
||||||
|
->set('queries', $queries['data'])
|
||||||
|
->set('query_count', $queries['count'])
|
||||||
|
->set('total_time', $queries['time'])
|
||||||
|
->set('total_memory', $queries['memory']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Files panel
|
// Files panel
|
||||||
|
@ -107,7 +111,7 @@ class DebugToolbar
|
||||||
public static function get_queries()
|
public static function get_queries()
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
$count = 0;
|
$count = $time = $memory = 0;
|
||||||
|
|
||||||
$groups = Profiler::groups();
|
$groups = Profiler::groups();
|
||||||
foreach(Database::$instances as $name => $db)
|
foreach(Database::$instances as $name => $db)
|
||||||
|
@ -117,15 +121,25 @@ class DebugToolbar
|
||||||
|
|
||||||
if ($group)
|
if ($group)
|
||||||
{
|
{
|
||||||
|
$sub_time = $sub_memory = $sub_count = 0;
|
||||||
foreach ($group as $query => $tokens)
|
foreach ($group as $query => $tokens)
|
||||||
{
|
{
|
||||||
|
$sub_count += count($tokens);
|
||||||
foreach ($tokens as $token)
|
foreach ($tokens as $token)
|
||||||
$result[$name][] = array('name' => $query) + Profiler::total($token);
|
{
|
||||||
$count += count($tokens);
|
$total = Profiler::total($token);
|
||||||
|
$sub_time += $total[0];
|
||||||
|
$sub_memory += $total[1];
|
||||||
|
$result[$name][] = array('name' => $query, 'time' => $total[0], 'memory' => $total[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$count += $sub_count;
|
||||||
|
$time += $sub_time;
|
||||||
|
$memory += $sub_memory;
|
||||||
|
$result[$name]['total'] = array($sub_count, $sub_time, $sub_memory);
|
||||||
}
|
}
|
||||||
return array('count' => $count, 'data' => $result);
|
}
|
||||||
|
return array('count' => $count, 'time' => $time, 'memory' => $memory, 'data' => $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,10 +212,10 @@ class DebugToolbar
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add toolbar data to FirePHP console
|
* Add toolbar data to FirePHP console
|
||||||
* @TODO change benchmark logic to KO3 style
|
*
|
||||||
*/
|
*/
|
||||||
private static function firephp()
|
private static function firephp()
|
||||||
{//return;
|
{
|
||||||
$firephp = FirePHP::getInstance(TRUE);
|
$firephp = FirePHP::getInstance(TRUE);
|
||||||
$firephp->fb('KOHANA DEBUG TOOLBAR:');
|
$firephp->fb('KOHANA DEBUG TOOLBAR:');
|
||||||
|
|
||||||
|
@ -232,49 +246,54 @@ class DebugToolbar
|
||||||
|
|
||||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
// Database
|
// Database
|
||||||
$queries = self::get_queries();
|
$query_stats = self::get_queries();
|
||||||
|
|
||||||
$total_time = $total_rows = 0;
|
//$total_time = $total_rows = 0;
|
||||||
$table = array();
|
$table = array();
|
||||||
$table[] = array('SQL Statement','Time','Rows');
|
$table[] = array('DB profile', 'SQL Statement','Time','Memory');
|
||||||
|
|
||||||
foreach ((array)$queries as $query)
|
foreach ((array)$query_stats['data'] as $db => $queries)
|
||||||
|
{unset($queries['total']);
|
||||||
|
foreach ($queries as $query)
|
||||||
{
|
{
|
||||||
$table[] = array(
|
$table[] = array(
|
||||||
str_replace("\n",' ',$query['query']),
|
$db,
|
||||||
number_format($query['time'], 3),
|
str_replace("\n",' ',$query['name']),
|
||||||
$query['rows']
|
number_format($query['time']*1000, 3),
|
||||||
|
number_format($query['memory']/1024, 3),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
$total_time += $query['time'];
|
|
||||||
$total_rows += $query['rows'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = 'Queries: '.count($queries).' SQL queries took '.
|
$message = 'Queries: '.$query_stats['count'].' SQL queries took '.
|
||||||
number_format($total_time, 3).' seconds and returned '.$total_rows.' rows';
|
number_format($query_stats['time'], 3).' seconds and '.$query_stats['memory'].' b';
|
||||||
|
|
||||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
$benchmarks = self::get_benchmarks();
|
$groups = self::get_benchmarks();
|
||||||
|
// application benchmarks
|
||||||
|
$total = array_pop($groups);
|
||||||
|
|
||||||
$table = array();
|
$table = array();
|
||||||
$table[] = array('Benchmark', 'Time', 'Memory');
|
$table[] = array('Group', 'Benchmark', 'Count', 'Time', 'Memory');
|
||||||
|
|
||||||
|
foreach ((array)$groups as $group => $benchmarks)
|
||||||
|
{
|
||||||
foreach ((array)$benchmarks as $name => $benchmark)
|
foreach ((array)$benchmarks as $name => $benchmark)
|
||||||
{
|
{
|
||||||
$table[] = array(
|
$table[] = array(
|
||||||
ucwords(str_replace(array('_', '-'), ' ', str_replace(SYSTEM_BENCHMARK.'_', '', $name))),
|
ucfirst($group),
|
||||||
number_format($benchmark['time'], 3). ' s',
|
ucwords($benchmark['name']),
|
||||||
text::bytes($benchmark['memory'])
|
number_format($benchmark['total_time'], 3). ' s',
|
||||||
|
text::bytes($benchmark['total_memory']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$message = 'Benchmarks: '.count($benchmarks).' benchmarks took '.
|
$message = 'Application tooks '.number_format($total['total_time'], 3).' seconds and '.text::bytes($total['total_memory']).' memory';
|
||||||
number_format($benchmark['time'], 3).' seconds and used up '.
|
|
||||||
text::bytes($benchmark['memory']).' memory';
|
|
||||||
|
|
||||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,10 +107,10 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th align="left">benchmark</th>
|
<th align="left">benchmark</th>
|
||||||
<th align="right">count</th>
|
<th align="right">count</th>
|
||||||
<th align="right">avg_time</th>
|
<th align="right">avg time</th>
|
||||||
<th align="right">total_time</th>
|
<th align="right">total time</th>
|
||||||
<th align="right">avg_memory</th>
|
<th align="right">avg memory</th>
|
||||||
<th align="right">total_memory</th>
|
<th align="right">total memory</th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php if (count($benchmarks)):
|
<?php if (count($benchmarks)):
|
||||||
$application = array_pop($benchmarks);?>
|
$application = array_pop($benchmarks);?>
|
||||||
|
@ -156,25 +156,19 @@
|
||||||
<th>time</th>
|
<th>time</th>
|
||||||
<th>memory</th>
|
<th>memory</th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php $total_time = $total_memory = 0; ?>
|
|
||||||
<?php foreach ($queries as $db_profile => $stats):
|
<?php foreach ($queries as $db_profile => $stats):
|
||||||
$sub_count = $sub_time = $sub_memory = 0; ?>
|
list($sub_count, $sub_time, $sub_memory) = array_pop($stats); ?>
|
||||||
<tr align="left">
|
<tr align="left">
|
||||||
<th colspan="4">DATABASE "<?php echo strtoupper($db_profile) ?>"</th>
|
<th colspan="4">DATABASE "<?php echo strtoupper($db_profile) ?>"</th>
|
||||||
</tr>
|
</tr>
|
||||||
<? foreach ($stats as $query): ?>
|
<? foreach ($stats as $num => $query): ?>
|
||||||
<tr class="<?php echo text::alternate('odd','even') ?>">
|
<tr class="<?php echo text::alternate('odd','even') ?>">
|
||||||
<td><?php echo ++$sub_count ?></td>
|
<td><?php echo $num+1 ?></td>
|
||||||
<td><?php echo $query['name'] ?></td>
|
<td><?php echo $query['name'] ?></td>
|
||||||
<td><?php echo number_format($query[0] * 1000, 3) ?> ms</td>
|
<td><?php echo number_format($query['time'] * 1000, 3) ?> ms</td>
|
||||||
<td><?php echo number_format($query[1] / 1024, 3) ?> kb</td>
|
<td><?php echo number_format($query['memory'] / 1024, 3) ?> kb</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? $sub_time += $query[0];
|
<? endforeach; ?>
|
||||||
$sub_memory += $query[1];
|
|
||||||
endforeach;
|
|
||||||
$total_time += $sub_time;
|
|
||||||
$total_memory += $sub_memory;
|
|
||||||
?>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
<th><?php echo $sub_count ?> total</th>
|
<th><?php echo $sub_count ?> total</th>
|
||||||
|
@ -282,8 +276,8 @@
|
||||||
<tr align="left">
|
<tr align="left">
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>name</th>
|
<th>name</th>
|
||||||
<th>rel_path</th>
|
<th>rel path</th>
|
||||||
<th>abs_path</th>
|
<th>abs path</th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php foreach($modules as $name => $path): ?>
|
<?php foreach($modules as $name => $path): ?>
|
||||||
<tr class="<?php echo text::alternate('odd','even')?>">
|
<tr class="<?php echo text::alternate('odd','even')?>">
|
||||||
|
|
Loading…
Reference in a new issue