mirror of
https://github.com/Oreolek/debug-toolbar.git
synced 2024-06-16 23:00:50 +03:00
first commit
This commit is contained in:
commit
3c7d491f96
326
classes/debugtoolbar.php
Normal file
326
classes/debugtoolbar.php
Normal file
|
@ -0,0 +1,326 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class DebugToolbar
|
||||
{
|
||||
public static $benchmark_name = 'debug_toolbar';
|
||||
|
||||
/**
|
||||
* Renders the Debug Toolbar
|
||||
*
|
||||
* @param bool print rendered output
|
||||
* @return string debug toolbar rendered output
|
||||
*/
|
||||
public static function render($print = false)
|
||||
{
|
||||
$token = Profiler::start('custom', self::$benchmark_name);
|
||||
|
||||
$template = new View('toolbar');
|
||||
|
||||
// Database panel
|
||||
if (Kohana::config('debug_toolbar.panels.database') === TRUE)
|
||||
{
|
||||
$queries = self::get_queries();
|
||||
$template->set('queries', $queries['data'])->set('query_count', $queries['count']);
|
||||
}
|
||||
|
||||
// Logs panel
|
||||
if (Kohana::config('debug_toolbar.panels.logs') === TRUE)
|
||||
{
|
||||
$template->set('logs', self::get_logs());
|
||||
}
|
||||
|
||||
// Vars and Config panel
|
||||
if (Kohana::config('debug_toolbar.panels.vars_and_config') === TRUE)
|
||||
{
|
||||
$template->set('configs', self::get_configs());
|
||||
}
|
||||
|
||||
// Files panel
|
||||
if (Kohana::config('debug_toolbar.panels.files') === TRUE)
|
||||
{
|
||||
$template->set('files', self::get_files());
|
||||
}
|
||||
|
||||
// Modules panel
|
||||
if (Kohana::config('debug_toolbar.panels.modules') === TRUE)
|
||||
{
|
||||
$template->set('modules', self::get_modules());
|
||||
}
|
||||
|
||||
// FirePHP
|
||||
if (Kohana::config('debug_toolbar.firephp_enabled') === TRUE)
|
||||
{
|
||||
self::firephp();
|
||||
}
|
||||
|
||||
// Set alignment for toolbar
|
||||
switch (Kohana::config('debug_toolbar.align'))
|
||||
{
|
||||
case 'right':
|
||||
case 'center':
|
||||
case 'left':
|
||||
$template->set('align', Kohana::config('debug_toolbar.align'));
|
||||
break;
|
||||
default:
|
||||
$template->set('align', 'left');
|
||||
}
|
||||
|
||||
// Javascript for toolbar
|
||||
$template->set('scripts', file_get_contents(Kohana::find_file('views', 'toolbar', 'js')));
|
||||
|
||||
// CSS for toolbar
|
||||
$styles = file_get_contents(Kohana::find_file('views', 'toolbar', 'css'));
|
||||
|
||||
Profiler::stop($token);
|
||||
|
||||
// Benchmarks panel
|
||||
if (Kohana::config('debug_toolbar.panels.benchmarks') === TRUE)
|
||||
{
|
||||
$template->set('benchmarks', self::get_benchmarks());
|
||||
}
|
||||
|
||||
if ($output = Request::instance()->response and self::is_enabled())
|
||||
{
|
||||
// Try to add css just before the </head> tag
|
||||
if (stripos($output, '</head>') !== FALSE)
|
||||
{
|
||||
$output = str_ireplace('</head>', $styles.'</head>', $output);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No </head> tag found, append styles to output
|
||||
$template->set('styles', $styles);
|
||||
}
|
||||
|
||||
// Try to add js and HTML just before the </body> tag
|
||||
if (stripos($output, '</body>') !== FALSE)
|
||||
{
|
||||
$output = str_ireplace('</body>', $template->render().'</body>', $output);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closing <body> tag not found, just append toolbar to output
|
||||
$output .= $template->render();
|
||||
}
|
||||
|
||||
Request::instance()->response = $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
$template->set('styles', $styles);
|
||||
|
||||
return ($print ? $template->render() : $template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves query benchmarks from Database
|
||||
*/
|
||||
public static function get_queries()
|
||||
{
|
||||
$result = array();
|
||||
$count = 0;
|
||||
|
||||
$groups = Profiler::groups();
|
||||
foreach(Database::$instances as $name => $db)
|
||||
{
|
||||
$group_name = 'database (' . strtolower($name) . ')';
|
||||
$group = arr::get($groups, $group_name, FALSE);
|
||||
|
||||
if ($group)
|
||||
{
|
||||
foreach ($group as $query => $tokens)
|
||||
{
|
||||
foreach ($tokens as $token)
|
||||
$result[$name][] = array('name' => $query) + Profiler::total($token);
|
||||
$count += count($tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('count' => $count, 'data' => $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a formatted array of all Benchmarks
|
||||
*
|
||||
* @return array formatted benchmarks
|
||||
*/
|
||||
public static function get_benchmarks()
|
||||
{
|
||||
if (Kohana::$profiling == FALSE)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
$groups = Profiler::groups();
|
||||
$result = array();
|
||||
foreach(array_keys($groups) as $group)
|
||||
{
|
||||
if (strpos($group, 'database (') === FALSE)
|
||||
{
|
||||
foreach($groups[$group] as $name => $marks)
|
||||
{
|
||||
$stats = Profiler::stats($marks);
|
||||
$result[$group][] = array
|
||||
(
|
||||
'name' => $name,
|
||||
'count' => count($marks),
|
||||
'total_time' => $stats['total']['time'],
|
||||
'avg_time' => $stats['average']['time'],
|
||||
'total_memory' => $stats['total']['memory'],
|
||||
'avg_memory' => $stats['average']['memory'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// add total stats
|
||||
$total = Profiler::application();
|
||||
$result['application'] = array
|
||||
(
|
||||
'count' => 1,
|
||||
'total_time' => $total['current']['time'],
|
||||
'avg_time' => $total['average']['time'],
|
||||
'total_memory' => $total['current']['memory'],
|
||||
'avg_memory' => $total['average']['memory'],
|
||||
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of included files
|
||||
*
|
||||
* @return array file currently included by php
|
||||
*/
|
||||
public static function get_files()
|
||||
{
|
||||
$files = (array)get_included_files();
|
||||
sort($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array module_name => module_path
|
||||
*/
|
||||
public static function get_modules()
|
||||
{
|
||||
return Kohana::modules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add toolbar data to FirePHP console
|
||||
* @TODO change benchmark logic to KO3 style
|
||||
*/
|
||||
private static function firephp()
|
||||
{return;
|
||||
$firephp = FirePHP::getInstance(TRUE);
|
||||
$firephp->fb('KOHANA DEBUG TOOLBAR:');
|
||||
|
||||
// Globals
|
||||
$globals = array(
|
||||
'Post' => empty($_POST) ? array() : $_POST,
|
||||
'Get' => empty($_GET) ? array() : $_GET,
|
||||
'Cookie' => empty($_COOKIE) ? array() : $_COOKIE,
|
||||
'Session' => empty($_SESSION) ? array() : $_SESSION
|
||||
);
|
||||
|
||||
foreach ($globals as $name => $global)
|
||||
{
|
||||
$table = array();
|
||||
$table[] = array($name,'Value');
|
||||
|
||||
foreach((array)$global as $key => $value)
|
||||
{
|
||||
if (is_object($value))
|
||||
{
|
||||
$value = get_class($value).' [object]';
|
||||
}
|
||||
|
||||
$table[] = array($key, $value);
|
||||
}
|
||||
|
||||
$message = "$name: ".count($global).' variables';
|
||||
|
||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||
}
|
||||
|
||||
// Database
|
||||
$queries = self::get_queries();
|
||||
|
||||
$total_time = $total_rows = 0;
|
||||
$table = array();
|
||||
$table[] = array('SQL Statement','Time','Rows');
|
||||
|
||||
foreach ((array)$queries as $query)
|
||||
{
|
||||
$table[] = array(
|
||||
str_replace("\n",' ',$query['query']),
|
||||
number_format($query['time'], 3),
|
||||
$query['rows']
|
||||
);
|
||||
|
||||
$total_time += $query['time'];
|
||||
$total_rows += $query['rows'];
|
||||
}
|
||||
|
||||
$message = 'Queries: '.count($queries).' SQL queries took '.
|
||||
number_format($total_time, 3).' seconds and returned '.$total_rows.' rows';
|
||||
|
||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||
|
||||
// Benchmarks
|
||||
$benchmarks = self::get_benchmarks();
|
||||
|
||||
$table = array();
|
||||
$table[] = array('Benchmark', 'Time', 'Memory');
|
||||
|
||||
foreach ((array)$benchmarks as $name => $benchmark)
|
||||
{
|
||||
$table[] = array(
|
||||
ucwords(str_replace(array('_', '-'), ' ', str_replace(SYSTEM_BENCHMARK.'_', '', $name))),
|
||||
number_format($benchmark['time'], 3). ' s',
|
||||
text::bytes($benchmark['memory'])
|
||||
);
|
||||
}
|
||||
|
||||
$message = 'Benchmarks: '.count($benchmarks).' benchmarks took '.
|
||||
number_format($benchmark['time'], 3).' seconds and used up '.
|
||||
text::bytes($benchmark['memory']).' memory';
|
||||
|
||||
$firephp->fb(array($message, $table), FirePHP::TABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if all the conditions are correct to display the toolbar
|
||||
* (pretty kludgy, I know)
|
||||
*
|
||||
* @returns bool toolbar enabled
|
||||
*/
|
||||
public static function is_enabled()
|
||||
{
|
||||
// Don't auto render toolbar for ajax requests
|
||||
if (Request::$is_ajax)
|
||||
return FALSE;
|
||||
|
||||
// Don't auto render toolbar if $_GET['debug'] = 'false'
|
||||
if (isset($_GET['debug']) and strtolower($_GET['debug']) == 'false')
|
||||
return FALSE;
|
||||
|
||||
// Don't auto render if auto_render config is FALSE
|
||||
if (Kohana::config('debug_toolbar.auto_render') !== TRUE)
|
||||
return FALSE;
|
||||
|
||||
// Auto render if secret key isset
|
||||
$secret_key = Kohana::config('debug_toolbar.secret_key');
|
||||
if ($secret_key !== FALSE and isset($_GET[$secret_key]))
|
||||
return TRUE;
|
||||
|
||||
// Don't auto render when IN_PRODUCTION (this can obviously be
|
||||
// overridden by the above secret key)
|
||||
if (IN_PRODUCTION)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
1376
classes/firephp.php
Normal file
1376
classes/firephp.php
Normal file
File diff suppressed because it is too large
Load diff
50
config/debug_toolbar.php
Normal file
50
config/debug_toolbar.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/*
|
||||
* If true, the debug toolbar will be automagically displayed
|
||||
* NOTE: if IN_PRODUCTION is set to TRUE, the toolbar will
|
||||
* not automatically render, even if auto_render is TRUE
|
||||
*/
|
||||
$config['auto_render'] = FALSE;
|
||||
|
||||
/*
|
||||
* If true, the toolbar will default to the minimized position
|
||||
*/
|
||||
$config['minimized'] = FALSE;
|
||||
|
||||
/*
|
||||
* Location of icon images
|
||||
* relative to your site_domain
|
||||
*/
|
||||
$config['icon_path'] = 'images';
|
||||
|
||||
/*
|
||||
* Log toolbar data to FirePHP
|
||||
*/
|
||||
$config['firephp_enabled'] = TRUE;
|
||||
|
||||
/*
|
||||
* Enable or disable specific panels
|
||||
*/
|
||||
$config['panels'] = array(
|
||||
'benchmarks' => TRUE,
|
||||
'database' => TRUE,
|
||||
'vars' => TRUE,
|
||||
'logs' => TRUE,
|
||||
'ajax' => TRUE,
|
||||
'files' => TRUE,
|
||||
'modules' => TRUE,
|
||||
);
|
||||
|
||||
/*
|
||||
* Toolbar alignment
|
||||
* options: right, left, center
|
||||
*/
|
||||
$config['align'] = 'right';
|
||||
|
||||
/*
|
||||
* Secret Key
|
||||
*/
|
||||
$config['secret_key'] = FALSE;
|
||||
|
||||
return $config;
|
192
views/toolbar.css
Normal file
192
views/toolbar.css
Normal file
|
@ -0,0 +1,192 @@
|
|||
<style type="text/css">
|
||||
/* Reset */
|
||||
div#kohana-debug-toolbar,
|
||||
div#kohana-debug-toolbar div,
|
||||
div#kohana-debug-toolbar span,
|
||||
div#kohana-debug-toolbar pre,
|
||||
div#kohana-debug-toolbar h1,
|
||||
div#kohana-debug-toolbar img,
|
||||
div#kohana-debug-toolbar a,
|
||||
div#kohana-debug-toolbar ul,
|
||||
div#kohana-debug-toolbar li,
|
||||
div#kohana-debug-toolbar table,
|
||||
div#kohana-debug-toolbar tr,
|
||||
div#kohana-debug-toolbar td,
|
||||
div#kohana-debug-toolbar th {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
font-size: 100%;
|
||||
vertical-align: middle;
|
||||
background: transparent;
|
||||
line-height: 1;
|
||||
text-transform: none;
|
||||
font-size:100%;
|
||||
}
|
||||
div#kohana-debug-toolbar table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
div#kohana-debug-toolbar :focus { outline: 0; }
|
||||
div#kohana-debug-toolbar ul {
|
||||
list-style:none;
|
||||
}
|
||||
|
||||
/* Global */
|
||||
div#kohana-debug-toolbar {
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
color: #333;
|
||||
text-align: left;
|
||||
line-height: 12px;
|
||||
}
|
||||
div#kohana-debug-toolbar h1 {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 10px;
|
||||
padding:0px 5px;
|
||||
border: 0px;
|
||||
background-color: #eee;
|
||||
color: #000;
|
||||
display:block;
|
||||
}
|
||||
div#kohana-debug-toolbar a,
|
||||
div#kohana-debug-toolbar a:hover {
|
||||
text-decoration: none;
|
||||
color: #222;
|
||||
}
|
||||
div#kohana-debug-toolbar pre { line-height: 1.3 }
|
||||
div#kohana-debug-toolbar .top {
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
width: 100%;
|
||||
z-index: 9999;
|
||||
border-bottom: 1px solid #aaa;
|
||||
background-color: #efefef;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
div#kohana-debug-toolbar table {
|
||||
padding: 3px;
|
||||
font-size: 11px;
|
||||
border: 1px solid #999;
|
||||
width: 99%;
|
||||
margin:0px 5px;
|
||||
font-family: monospace;
|
||||
}
|
||||
div#kohana-debug-toolbar td {
|
||||
padding: 3px 3px;
|
||||
vertical-align: top;
|
||||
background-color: #eee;
|
||||
}
|
||||
div#kohana-debug-toolbar tr.odd td {
|
||||
background-color: #ddd;
|
||||
}
|
||||
div#kohana-debug-toolbar th {
|
||||
padding: 3px 5px;
|
||||
vertical-align: top;
|
||||
background-color: #999;
|
||||
color: #eee;
|
||||
white-space: nowrap;
|
||||
}
|
||||
div#kohana-debug-toolbar td,
|
||||
div#kohana-debug-toolbar th {
|
||||
border: 1px solid #efefef;
|
||||
}
|
||||
|
||||
/* Toolbar */
|
||||
div#kohana-debug-toolbar div#debug-toolbar {
|
||||
position: fixed;
|
||||
padding: 0 0 3px 0;
|
||||
top: 0px;
|
||||
opacity: 0.80;
|
||||
filter: alpha(opacity:80);
|
||||
z-index: 10000;
|
||||
white-space: nowrap;
|
||||
line-height: 16px;
|
||||
background-color: #ccc;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-center { left: auto; right: auto; }
|
||||
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-right { right: 0; }
|
||||
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-left { left: 0; }
|
||||
div#kohana-debug-toolbar div#debug-toolbar img { vertical-align: middle; }
|
||||
div#kohana-debug-toolbar div#debug-toolbar ul.menu {
|
||||
padding: 5px;
|
||||
display: inline;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-toolbar ul.menu li {
|
||||
display: inline;
|
||||
list-style: none;
|
||||
padding: 0 5px;
|
||||
border-right: 1px solid #aaa;
|
||||
cursor: pointer;
|
||||
line-height: 16px;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-toolbar ul.menu li.last {
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* Benchmarks */
|
||||
div#kohana-debug-toolbar div#debug-benchmarks { padding: 3px 0px; }
|
||||
|
||||
/* SQL queries */
|
||||
div#kohana-debug-toolbar div#debug-database { padding: 3px 0px; }
|
||||
|
||||
/* Vars & Config */
|
||||
div#kohana-debug-toolbar div#debug-vars {
|
||||
padding: 3px 0px;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars pre {
|
||||
background-color: #ddd;
|
||||
padding: 5px;
|
||||
color: #333;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars .varmenu {
|
||||
margin: 20px 0 0 0;
|
||||
height: 23px;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars .varmenu li {
|
||||
float: left;
|
||||
display: block;
|
||||
padding: 5px;
|
||||
margin: 0 6px 0 0;
|
||||
border-top: 1px solid #999;
|
||||
border-left: 1px solid #999;
|
||||
border-right: 1px solid #999;
|
||||
cursor: pointer;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars .varmenu li.active {
|
||||
background-color: #ddd;
|
||||
color: #000;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu { background-color: #ddd; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li {
|
||||
display: block;
|
||||
padding: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li.odd { background-color: #eee; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li.even { background-color: #fff; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li.odd pre { background-color: #eee; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li.even pre { background-color: #fff; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.odd { background-color: #ddd; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.even { background-color: #ddd; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.odd pre { background-color: #ddd; }
|
||||
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.even pre { background-color: #ddd; }
|
||||
|
||||
/* Logs & Msgs */
|
||||
div#kohana-debug-toolbar div#debug-log {
|
||||
padding: 3px 0px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* Ajax */
|
||||
div#kohana-debug-toolbar div#debug-ajax {
|
||||
padding: 3px 0px;
|
||||
font-size: 11px;
|
||||
}
|
||||
</style>
|
122
views/toolbar.js
Normal file
122
views/toolbar.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
var debugToolbar = {
|
||||
|
||||
// current toolbar section thats open
|
||||
current: null,
|
||||
|
||||
// current vars and config section open
|
||||
currentvar: null,
|
||||
|
||||
// current config section open
|
||||
currentli: null,
|
||||
|
||||
// toggle a toolbar section
|
||||
show : function(obj) {
|
||||
if (obj == debugToolbar.current) {
|
||||
debugToolbar.off(obj);
|
||||
debugToolbar.current = null;
|
||||
} else {
|
||||
debugToolbar.off(debugToolbar.current);
|
||||
debugToolbar.on(obj);
|
||||
debugToolbar.current = obj;
|
||||
}
|
||||
},
|
||||
|
||||
// toggle a vars and configs section
|
||||
showvar : function(li, obj) {
|
||||
if (obj == debugToolbar.currentvar) {
|
||||
debugToolbar.off(obj);
|
||||
debugToolbar.currentli.className = '';
|
||||
debugToolbar.currentli = null;
|
||||
debugToolbar.currentvar = null;
|
||||
} else {
|
||||
debugToolbar.off(debugToolbar.currentvar);
|
||||
if (debugToolbar.currentli)
|
||||
debugToolbar.currentli.className = '';
|
||||
debugToolbar.on(obj);
|
||||
debugToolbar.currentvar = obj;
|
||||
debugToolbar.currentli = li;
|
||||
debugToolbar.currentli.className = 'active';
|
||||
}
|
||||
},
|
||||
|
||||
// turn an element on
|
||||
on : function(obj) {
|
||||
if (document.getElementById(obj) != null)
|
||||
document.getElementById(obj).style.display = '';
|
||||
},
|
||||
|
||||
// turn an element off
|
||||
off : function(obj) {
|
||||
if (document.getElementById(obj) != null)
|
||||
document.getElementById(obj).style.display = 'none';
|
||||
},
|
||||
|
||||
// toggle an element
|
||||
toggle : function(obj) {
|
||||
if (typeof obj == 'string')
|
||||
obj = document.getElementById(obj);
|
||||
|
||||
if (obj)
|
||||
obj.style.display = obj.style.display == 'none' ? '' : 'none';
|
||||
},
|
||||
|
||||
// close the toolbar
|
||||
close : function() {
|
||||
document.getElementById('kohana-debug-toolbar').style.display = 'none';
|
||||
},
|
||||
|
||||
swap: function() {
|
||||
var toolbar = document.getElementById('debug-toolbar');
|
||||
if (toolbar.className == 'debug-toolbar-align-center') {
|
||||
toolbar.className = 'debug-toolbar-align-left';
|
||||
} else if (toolbar.className == 'debug-toolbar-align-left') {
|
||||
toolbar.className = 'debug-toolbar-align-right';
|
||||
} else {
|
||||
toolbar.className = 'debug-toolbar-align-center';
|
||||
}
|
||||
},
|
||||
|
||||
collapse: function() {
|
||||
debugToolbar.toggle('debug-toolbar-menu');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Test for javascript libraries
|
||||
* (only supports jQuery at the moment
|
||||
*/
|
||||
if (typeof jQuery != 'undefined') {
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
// display ajax button in toolbar
|
||||
$('#toggle-ajax').css({display: 'inline'});
|
||||
|
||||
// bind ajax event
|
||||
$('#debug-ajax').bind("ajaxComplete", function(event, xmlrequest, ajaxOptions){
|
||||
|
||||
// add a new row to ajax table
|
||||
$('#debug-ajax table').append(
|
||||
'<tr class="even">' +
|
||||
'<td>' + $('#debug-ajax table tr').size() +'<\/td>' +
|
||||
'<td>jQuery ' + jQuery.fn.jquery + '<\/td>' +
|
||||
'<td>' + xmlrequest.statusText + ' (' + xmlrequest.status + ')<\/td>' +
|
||||
'<td>' + ajaxOptions.url + '<\/td>' +
|
||||
'<\/tr>'
|
||||
);
|
||||
|
||||
// stripe table
|
||||
$('#debug-ajax table tbody tr:nth-child(even)').attr('class', 'odd');
|
||||
|
||||
// update count in toolbar
|
||||
$('#toggle-ajax span').text($('#debug-ajax table tr').size()-1);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof Prototype != 'undefined') {
|
||||
|
||||
}
|
||||
|
297
views/toolbar.php
Normal file
297
views/toolbar.php
Normal file
|
@ -0,0 +1,297 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.') ?>
|
||||
|
||||
<!-- CSS styles (if not added to <head>) -->
|
||||
<?php if (isset($styles)): ?>
|
||||
<?php echo $styles ?>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Javascript -->
|
||||
<script type="text/javascript">
|
||||
<?php echo $scripts ?>
|
||||
</script>
|
||||
|
||||
<div id="kohana-debug-toolbar">
|
||||
|
||||
<!-- Toolbar -->
|
||||
<div id="debug-toolbar" class="debug-toolbar-align-<?php echo $align ?>">
|
||||
|
||||
<!-- Kohana link -->
|
||||
<?php echo html::image(
|
||||
Kohana::config('debug_toolbar.icon_path').'/kohana.png',
|
||||
array('onclick' => 'debugToolbar.collapse()')
|
||||
) ?>
|
||||
|
||||
<!-- Kohana icon -->
|
||||
<?php if (Kohana::config('debug_toolbar.minimized') === TRUE): ?>
|
||||
<ul id="debug-toolbar-menu" class="menu" style="display: none">
|
||||
<?php else: ?>
|
||||
<ul id="debug-toolbar-menu" class="menu">
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Kohana version -->
|
||||
<li>
|
||||
<?php echo html::anchor("http://kohanaphp.com/home", Kohana::VERSION, array('target' => '_blank')) ?>
|
||||
</li>
|
||||
|
||||
<!-- Benchmarks -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.benchmarks')): ?>
|
||||
<!-- Time -->
|
||||
<li id="time" onclick="debugToolbar.show('debug-benchmarks'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/time.png', array('alt' => 'time')) ?>
|
||||
<?php echo round(($benchmarks['application']['total_time'])*1000, 2) ?> ms
|
||||
</li>
|
||||
<!-- Memory -->
|
||||
<li id="memory" onclick="debugToolbar.show('debug-benchmarks'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/memory.png', array('alt' => 'memory')) ?>
|
||||
<?php echo text::bytes($benchmarks['application']['total_memory']) ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Queries -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.database')): ?>
|
||||
<li id="toggle-database" onclick="debugToolbar.show('debug-database'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/database.png', array('alt' => 'queries')) ?>
|
||||
<?php echo isset($queries) ? $query_count : 0 ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Vars -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.vars')): ?>
|
||||
<li id="toggle-vars" onclick="debugToolbar.show('debug-vars'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/config.png', array('alt' => 'vars')) ?>
|
||||
vars & config
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Ajax -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.ajax')): ?>
|
||||
<li id="toggle-ajax" onclick="debugToolbar.show('debug-ajax'); return false;" style="display: none">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/ajax.png', array('alt' => 'ajax')) ?>
|
||||
ajax (<span>0</span>)
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Files -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.files')): ?>
|
||||
<li id="toggle-files" onclick="debugToolbar.show('debug-files'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/page_copy.png', array('alt' => 'files')) ?>
|
||||
files
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Modules -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.modules')): ?>
|
||||
<li id="toggle-modules" onclick="debugToolbar.show('debug-modules'); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/page_copy.png', array('alt' => 'modules')) ?>
|
||||
modules
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Swap sides -->
|
||||
<li onclick="debugToolbar.swap(); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/text_align_left.png', array('alt' => 'align')) ?>
|
||||
</li>
|
||||
|
||||
<!-- Close -->
|
||||
<li class="last" onclick="debugToolbar.close(); return false;">
|
||||
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/close.png', array('alt' => 'close')) ?>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Benchmarks -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.benchmarks')): ?>
|
||||
<div id="debug-benchmarks" class="top" style="display: none;">
|
||||
<h1>Benchmarks</h1>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<th align="left">benchmark</th>
|
||||
<th align="right">count</th>
|
||||
<th align="right">avg_time</th>
|
||||
<th align="right">total_time</th>
|
||||
<th align="right">avg_memory</th>
|
||||
<th align="right">total_memory</th>
|
||||
</tr>
|
||||
<?php if (count($benchmarks)):
|
||||
$application = array_pop($benchmarks);?>
|
||||
<?php foreach ((array)$benchmarks as $group => $marks): ?>
|
||||
<tr>
|
||||
<th colspan="6"><?php echo $group?></th>
|
||||
</tr>
|
||||
<?php foreach($marks as $benchmark): ?>
|
||||
<tr class="<?php echo text::alternate('odd','even')?>">
|
||||
<td align="left"><?php echo $benchmark['name'] ?></td>
|
||||
<td align="right"><?php echo $benchmark['count'] ?></td>
|
||||
<td align="right"><?php echo sprintf('%.2f', $benchmark['avg_time'] * 1000) ?> ms</td>
|
||||
<td align="right"><?php echo sprintf('%.2f', $benchmark['total_time'] * 1000) ?> ms</td>
|
||||
<td align="right"><?php echo text::bytes($benchmark['avg_memory']) ?></td>
|
||||
<td align="right"><?php echo text::bytes($benchmark['total_memory']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
<tr>
|
||||
<th colspan="2" align="left">APPLICATION</th>
|
||||
<th align="right"><?php echo sprintf('%.2f', $application['avg_time'] * 1000) ?> ms</th>
|
||||
<th align="right"><?php echo sprintf('%.2f', $application['total_time'] * 1000) ?> ms</th>
|
||||
<th align="right"><?php echo text::bytes($application['avg_memory']) ?></th>
|
||||
<th align="right"><?php echo text::bytes($application['total_memory']) ?></th>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<tr class="<?php echo text::alternate('odd','even') ?>">
|
||||
<td colspan="6">no benchmarks to display</td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Database -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.database')): ?>
|
||||
<div id="debug-database" class="top" style="display: none;">
|
||||
<h1>SQL Queries</h1>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr align="left">
|
||||
<th>#</th>
|
||||
<th>query</th>
|
||||
<th>time</th>
|
||||
<th>memory</th>
|
||||
</tr>
|
||||
<?php $total_time = $total_memory = 0; ?>
|
||||
<?php foreach ($queries as $db_profile => $stats):
|
||||
$sub_count = $sub_time = $sub_memory = 0; ?>
|
||||
<tr align="left">
|
||||
<th colspan="4">DATABASE "<?php echo strtoupper($db_profile) ?>"</th>
|
||||
</tr>
|
||||
<? foreach ($stats as $query): ?>
|
||||
<tr class="<?php echo text::alternate('odd','even') ?>">
|
||||
<td><?php echo ++$sub_count ?></td>
|
||||
<td><?php echo $query['name'] ?></td>
|
||||
<td><?php echo number_format($query[0] * 1000, 3) ?> ms</td>
|
||||
<td><?php echo number_format($query[1] / 1024, 3) ?> kb</td>
|
||||
</tr>
|
||||
<? $sub_time += $query[0];
|
||||
$sub_memory += $query[1];
|
||||
endforeach;
|
||||
$total_time += $sub_time;
|
||||
$total_memory += $sub_memory;
|
||||
?>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th><?php echo $sub_count ?> total</th>
|
||||
<th><?php echo number_format($sub_time * 1000, 3) ?> ms</th>
|
||||
<th><?php echo number_format($sub_memory / 1024, 3) ?> kb</th>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (count($queries) > 1): ?>
|
||||
<tr>
|
||||
<th colspan="2" align="left"><?php echo $query_count ?> TOTAL</th>
|
||||
<th><?php echo number_format($total_time * 1000, 3) ?> ms</th>
|
||||
<th><?php echo number_format($total_memory / 1024, 3) ?> kb</th>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Vars and Config -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.vars')): ?>
|
||||
<div id="debug-vars" class="top" style="display: none;">
|
||||
<h1>Vars & Config</h1>
|
||||
<ul class="varmenu">
|
||||
<li onclick="debugToolbar.showvar(this, 'vars-post'); return false;">POST</li>
|
||||
<li onclick="debugToolbar.showvar(this, 'vars-get'); return false;">GET</li>
|
||||
<li onclick="debugToolbar.showvar(this, 'vars-server'); return false;">SERVER</li>
|
||||
<li onclick="debugToolbar.showvar(this, 'vars-cookie'); return false;">COOKIE</li>
|
||||
<li onclick="debugToolbar.showvar(this, 'vars-session'); return false;">SESSION</li>
|
||||
</ul>
|
||||
<div style="display: none;" id="vars-post">
|
||||
<?php echo isset($_POST) ? Kohana::debug($_POST) : Kohana::debug(array()) ?>
|
||||
</div>
|
||||
<div style="display: none;" id="vars-get">
|
||||
<?php echo isset($_GET) ? Kohana::debug($_GET) : Kohana::debug(array()) ?>
|
||||
</div>
|
||||
<div style="display: none;" id="vars-server">
|
||||
<?php echo isset($_SERVER) ? Kohana::debug($_SERVER) : Kohana::debug(array()) ?>
|
||||
</div>
|
||||
<div style="display: none;" id="vars-cookie">
|
||||
<?php echo isset($_COOKIE) ? Kohana::debug($_COOKIE) : Kohana::debug(array()) ?>
|
||||
</div>
|
||||
<div style="display: none;" id="vars-session">
|
||||
<?php echo isset($_SESSION) ? Kohana::debug($_SESSION) : Kohana::debug(array()) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Ajax Requests -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.ajax')): ?>
|
||||
<div id="debug-ajax" class="top" style="display:none;">
|
||||
<h1>Ajax</h1>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr align="left">
|
||||
<th width="1%">#</th>
|
||||
<th width="150">source</th>
|
||||
<th width="150">status</th>
|
||||
<th>request</th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Included Files -->
|
||||
<?php if (Kohana::config('debug_toolbar.panels.files')): ?>
|
||||
<div id="debug-files" class="top" style="display: none;">
|
||||
<h1>Files</h1>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr align="left">
|
||||
<th>#</th>
|
||||
<th>file</th>
|
||||
<th>size</th>
|
||||
<th>lines</th>
|
||||
</tr>
|
||||
<?php $total_size = $total_lines = 0 ?>
|
||||
<?php foreach ((array)$files as $id => $file): ?>
|
||||
<?php
|
||||
$size = filesize($file);
|
||||
$lines = count(file($file));
|
||||
?>
|
||||
<tr class="<?php echo text::alternate('odd','even')?>">
|
||||
<td><?php echo $id + 1 ?></td>
|
||||
<td><?php echo $file ?></td>
|
||||
<td><?php echo $size ?></td>
|
||||
<td><?php echo $lines ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$total_size += $size;
|
||||
$total_lines += $lines;
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
<tr align="left">
|
||||
<th colspan="2">total</th>
|
||||
<th><?php echo text::bytes($total_size) ?></th>
|
||||
<th><?php echo number_format($total_lines) ?></th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (Kohana::config('debug_toolbar.panels.modules')):
|
||||
$mod_counter = 0; ?>
|
||||
<div id="debug-modules" class="top" style="display: none;">
|
||||
<h1>Modules</h1>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr align="left">
|
||||
<th>#</th>
|
||||
<th>name</th>
|
||||
<th>rel_path</th>
|
||||
<th>abs_path</th>
|
||||
</tr>
|
||||
<?php foreach($modules as $name => $path): ?>
|
||||
<tr class="<?php echo text::alternate('odd','even')?>">
|
||||
<td><?php echo ++$mod_counter ?></td>
|
||||
<td><?php echo $name ?></td>
|
||||
<td><?php echo $path ?></td>
|
||||
<td><?php echo realpath($path) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</div>
|
Loading…
Reference in a new issue