app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/panel.phtml
<?php
/** @var Ecocode_Profiler_Block_Collector_Mysql_Panel $this */
/** @var Ecocode_Profiler_Model_Collector_MysqlDataCollector $collector */
$collector = $this->getCollector();
$identicalQueries = $this->getIdenticalQueries();
$identicalQueriesCount = count($identicalQueries);
$queriesByContext = $this->getByContext();
$contextHelper = Mage::helper('ecocode_profiler/context');
$queryTableRenderer = $this->getQueryTableRenderer();
/** @var Ecocode_Profiler_Helper_Renderer $rendererHelper */
$rendererHelper = Mage::helper('ecocode_profiler/renderer');
?>
<div style="float:left; width: 50%">
<h2>Query metrics</h2>
<div class="metrics">
<div class="metric">
<span class="value"><?php echo $collector->getQueryCount() ?></span>
<span class="label">Database queries</span>
</div>
<div class="metric">
<span class="value"><?php echo $identicalQueriesCount ?></span>
<span class="label">Identical queries</span>
</div>
<div class="metric">
<span class="value"><?php echo sprintf('%0.2f', $collector->getTotalTime() * 1000) ?> ms</span>
<span class="label">Query time</span>
</div>
</div>
</div>
<?php $connections = $collector->getConnectionData(); ?>
<?php if (count($connections) > 1): ?>
<div style="float:left; width: 50%">
<h2>Queries by connection</h2>
<div class="metrics">
<?php foreach ($connections as $name => $queryCount): ?>
<div class="metric">
<span class="value"><?php echo $queryCount ?></span>
<span class="label"><?php echo $name ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div style="clear: both;"></div>
<div class="sf-tabs">
<div class="tab">
<h3 class="tab-title">
Queries
<span class="badge"><?php echo $collector->getQueryCount() ?></span>
</h3>
<div id="all-queries" class="tab-content">
<?php if ($this->getQueryCountByType()): ?>
<div style="float:left; width: 50%">
<strong>Type: </strong>
<?php foreach ($this->getQueryCountByType() as $type => $count): ?>
<span data-toggle="query-type" data-type="<?php echo $type ?>" class="label">
<strong><?php echo strtoupper($type) ?></strong>
<span class="count">
(<span><?php echo $count ?></span>)
</span>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (count($connections) > 1): ?>
<div style="float:left; width: 50%">
<strong>Connection: </strong>
<?php foreach ($connections as $connection => $count): ?>
<span data-toggle="query-connection" data-connection="<?php echo $connection ?>" class="label">
<strong><?php echo $connection ?></strong>
<span class="count">
(<span><?php echo $count ?></span>)
</span>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div style="clear: both;"></div>
<?php echo $this->renderQueryTable('all', $this->getQueries()); ?>
</div>
</div>
<div class="tab">
<h3 class="tab-title">
Queries by context
<span class="badge"><?php echo count($queriesByContext) ?></span>
</h3>
<div class="tab-content">
<table class="sortable-table">
<thead>
<tr>
<th>#</th>
<th>Context</th>
<th data-sort="int">Queries</th>
<th data-sort="float">Total Time</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($queriesByContext as $index => $contextData): ?>
<tr>
<td><?php echo $index + 1 ?> </td>
<td>
<?php echo $contextHelper->render('context', $contextData['name']); ?>
</td>
<td><?php echo $contextData['count'] ?></td>
<td><?php echo sprintf('%0.2f', $contextData['total_time'] * 1000) ?> ms</td>
<td class="text-right">
<a href="#" class="sf-toggle link-inverse"
data-toggle-selector="#context-queries-<?php echo $index ?>"
data-toggle-alt-content="Hide queries">View queries</a>
</td>
</tr>
<tr class="hidden" id="context-queries-<?php echo $index ?>">
<td colspan="5">
Queries:<br>
<?php echo $this->renderQueryTable('context-' . $index, $contextData['queries']); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="tab">
<h3 class="tab-title">
Identical queries
<span class="badge"><?php echo $identicalQueriesCount ?></span>
</h3>
<div class="tab-content">
<?php $prefix = 'identical-'; ?>
<table class="alt queries-table">
<thead>
<tr>
<th class="nowrap">#</th>
<th class="nowrap" data-sort="int">Queries</th>
<th class="nowrap" data-sort="float">Total time<span></span></th>
<th style="width: 100%;">Info</th>
</tr>
</thead>
<tbody>
<?php foreach ($identicalQueries as $index => $query): ?>
<?php $queryData = $query['query']; ?>
<tr>
<td class="nowrap"><?php echo $index + 1 ?> </td>
<td class="nowrap"><?php echo $query['count'] ?> </td>
<td class="nowrap"><?php echo sprintf('%0.2f', $query['total_time'] * 1000) ?> ms</td>
<td>
<?php echo $queryData['sql_highlighted'] ?>
<div>
<strong class="font-normal text-small">Parameters</strong>:
<?php echo $queryTableRenderer->dumpParameters($queryData['params']) ?>
</div>
<div>
<?php echo $contextHelper->render('identical', $queryData['context']); ?>
</div>
<div class="text-small font-normal">
<?php if (isset($query['traces'])): ?>
<a href="#" class="sf-toggle link-inverse"
data-toggle-selector="#stack-<?php echo $prefix . $index ?>"
data-toggle-alt-content="Hide stack trace">Show trace</a>
<?php endif; ?>
<a href="#" class="sf-toggle link-inverse"
data-toggle-selector="#formatted-query-<?php echo $prefix . $index ?>"
data-toggle-alt-content="Hide formatted query">View formatted query</a>
<a href="#" class="sf-toggle link-inverse"
data-toggle-selector="#original-query-<?php echo $prefix . $index ?>"
data-toggle-alt-content="Hide runnable query">View runnable query</a>
</div>
<div id="formatted-query-<?php echo $prefix . $index ?>" class="sql-runnable hidden">
<?php echo $queryData['sql_formatted']; ?>
</div>
<div id="original-query-<?php echo $prefix . $index ?>" class="sql-runnable hidden">
<?php echo $queryData['sql_runnable']; ?>
</div>
<?php if (isset($query['traces'])): ?>
<div id="stack-<?php echo $prefix . $index ?>" class="hidden">
<strong class="font-normal text-small">Traces</strong>:
<table class="">
<tbody>
<?php foreach ($query['traces'] as $j => $trace): ?>
<tr>
<td class="nowrap">#<?php echo $j + 1 ?></td>
<td>
<?php echo $rendererHelper->renderCallStack($j + 1, $trace, false) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<script>
$(function () {
var allQueries = $('#all-queries'),
queryTypes = allQueries.find('span[data-toggle="query-type"]'),
connections = allQueries.find('span[data-toggle="query-connection"]');
queryTypes.click(function () {
var $this = $(this),
type = $this.data('type'),
makeActive = !$this.hasClass('status-success');
queryTypes.removeClass('status-success');
allQueries.removeAttr('data-type');
if (makeActive) {
$this.addClass('status-success');
allQueries.attr('data-type', type);
}
});
connections.click(function () {
var $this = $(this),
connection = $this.data('connection'),
makeActive = !$this.hasClass('status-success');
connections.removeClass('status-success');
allQueries.removeAttr('data-connection');
if (makeActive) {
$this.addClass('status-success');
allQueries.attr('data-connection', connection);
}
});
});
</script>
<style>
<?php foreach ($connections as $name => $queryCount): ?>
#all-queries[data-connection="<?php echo $name ?>"] tbody > tr:not([data-connection="<?php echo $name ?>"]) {
display: none;
}
<?php endforeach; ?>
<?php foreach ($this->getQueryCountByType() as $name => $queryCount): ?>
#all-queries[data-type="<?php echo $name ?>"] tbody > tr:not([data-type="<?php echo $name ?>"]) {
display: none;
}
<?php endforeach; ?>
#all-queries span[data-toggle="query-type"],
#all-queries span[data-toggle="query-connection"] {
cursor: pointer;
}
tr.sf-toggle-content.sf-toggle-visible {
display: table-row !important;
}
td > .context > strong {
display: none;
}
.hidden {
display: none;
}
.queries-table td, .queries-table th {
vertical-align: top;
}
.queries-table td > div {
margin-bottom: 6px;
}
.highlight pre {
margin: 0;
white-space: pre-wrap;
}
.highlight .keyword {
color: #8959A8;
font-weight: bold;
}
.highlight .word {
color: #222222;
}
.highlight .variable {
color: #916319;
}
.highlight .symbol {
color: #222222;
}
.highlight .comment {
color: #999999;
}
.highlight .backtick {
color: #718C00;
}
.highlight .string {
color: #718C00;
}
.highlight .number {
color: #F5871F;
font-weight: bold;
}
.highlight .error {
color: #C82829;
}
</style>