Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Issue #25 : Profiling database not possible when using PDO
Browse files Browse the repository at this point in the history
  • Loading branch information
JCSama committed Feb 11, 2018
1 parent 4d507d1 commit d90ad1e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.2 (2017-01-18)

Fix:

- Profiling database not possible when using PDO

## 1.1 (2017-01-18)

Fix:

- Profiler link not visible on ajax pannel (JS Error)

## 1.0 (2017-03-21)

Changes:
Expand Down
22 changes: 17 additions & 5 deletions third_party/DevelBar/hooks/Develbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Develbar
/**
* DevelBar version
*/
const VERSION = '1.1';
const VERSION = '1.2';

/**
* Supported CI version
Expand Down Expand Up @@ -365,12 +365,26 @@ protected function database_section($return_view = true)
if ($cobject instanceof CI_DB) {
$controller = &get_instance();
if ($controller instanceof CI_Controller) {
$dbs[get_class($this->CI) . ':$' . $name] = $cobject;
$database = array(
'database' => $cobject->database,
'hostname' => $cobject->hostname,
'queries' => $cobject->queries,
'query_times' => $cobject->query_times,
'query_count' => $cobject->query_count,
);
$dbs[get_class($this->CI) . ':$' . $name] = $database;
}
} elseif ($cobject instanceof CI_Model) {
foreach (get_object_vars($cobject) as $mname => $mobject) {
if ($mobject instanceof CI_DB) {
$dbs[get_class($cobject) . ':$' . $mname] = $mobject;
$database = array(
'database' => $mobject->database,
'hostname' => $mobject->hostname,
'queries' => $mobject->queries,
'query_times' => $mobject->query_times,
'query_count' => $mobject->query_count,
);
$dbs[get_class($cobject) . ':$' . $mname] = $database;
}
}
}
Expand Down Expand Up @@ -403,7 +417,6 @@ protected function hooks_section()
if (!isset($_hooks[0])) {
$_hooks = array($_hooks);
}

foreach ($_hooks as $hook) {
if (!array_key_exists('class', $hook)) {
$hooks[$hook_point][] = $hook;
Expand All @@ -414,7 +427,6 @@ protected function hooks_section()
$total_hooks++;
}
}

}

$data = array(
Expand Down
10 changes: 5 additions & 5 deletions third_party/DevelBar/views/develbar/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<?php
$global_execution_time = 0;
foreach ($dbs as $name => $db):
if (count($db->queries)) {
echo '-' . $db->hostname . '#' . lang('database') . ' : ' . $db->database . '<br/>';
if (count($db['queries'])) {
echo '-' . $db['hostname'] . '#' . lang('database') . ' : ' . $db['database'] . '<br/>';
$total_execution_time = 0;
echo '<div class="scrolls">';
foreach ($db->queries as $key => $query) {
$time = number_format($db->query_times[$key], 4);
foreach ($db['queries'] as $key => $query) {
$time = number_format($db['query_times'][$key], 4);
$highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT&nbsp;JOIN', 'ORDER&nbsp;BY', 'GROUP&nbsp;BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR&nbsp;', 'HAVING', 'OFFSET', 'NOT&nbsp;IN', 'IN', 'LIKE', 'NOT&nbsp;LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
//$query = highlight_code($query);
foreach ($highlight as $bold) {
Expand All @@ -23,7 +23,7 @@
<span class="right-col">' . $time . ' ' .lang('sec') .'</span>
</p>';
}
$total_execution_time = array_sum($db->query_times);
$total_execution_time = array_sum($db['query_times']);
$global_execution_time += $total_execution_time;
echo '
</div>
Expand Down
29 changes: 19 additions & 10 deletions third_party/DevelBar/views/develbar/profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
.ci-toolbar-tabs li a{ color:#90949f; display:block; padding:14px 40px; text-decoration:none; border-right:4px solid transparent }
.ci-toolbar-tabs li a.ajax{ background:url("<?php echo $profiler['ajax_requests']['icon'] ?>") no-repeat 10px center }
.ci-toolbar-tabs li a.database{ background:url("<?php echo $profiler['database']['icon'] ?>") no-repeat 10px center }
.ci-toolbar-tabs li a.database{ background:url("<?php echo isset($profiler['database']) ? $profiler['database']['icon'] : '' ?>") no-repeat 10px center }
.ci-toolbar-tabs li a.models{ background:url("<?php echo $profiler['models']['icon'] ?>") no-repeat 10px center }
.ci-toolbar-tabs li a.helpers{ background:url("<?php echo $profiler['helpers']['icon'] ?>") no-repeat 10px center }
.ci-toolbar-tabs li a.libraries{ background:url("<?php echo $profiler['libraries']['icon'] ?>") no-repeat 10px center }
Expand All @@ -42,7 +42,9 @@
<div class="ci-toolbar-tabs">
<ul>
<li class="active"><a href="#" class="ajax"><?php echo lang('ajax_requests') ?></a></li>
<li class=""><a href="#" class="database"><?php echo lang('database') ?></a></li>
<?php if(isset($profiler['database'])) : ?>
<li><a href="#" class="database"><?php echo lang('database') . ' <span id="count_db_queries"></span>' ?></a></li>
<?php endif; ?>
<li><a href="#" class="models"><?php echo lang('models') . ' ('.count($profiler['models']['models']).')' ?></a></li>
<li><a href="#" class="helpers"><?php echo lang('helpers') . ' ('.count($profiler['helpers']['helpers']).')' ?></a></li>
<li><a href="#" class="libraries"><?php echo lang('libraries') . ' ('.count($profiler['libraries']['loaded_libraries']).')' ?></a></li>
Expand Down Expand Up @@ -84,38 +86,43 @@
</tr>
</thead>
<tbody>
<?php if(isset($profiler['database'])): ?>
<?php $dbs = $profiler['database']['dbs']; ?>
<?php if(count($dbs)): ?>
<?php
$global_execution_time = 0;
$count_queries = 0;
foreach ($dbs as $name => $db):?>
<tr>
<?php if (count($db->queries)): ?>
<?php if (count($db['queries'])): ?>
<?php
$total_execution_time = 0;
foreach ($db->queries as $key => $query) {
$time = number_format($db->query_times[$key], 4);
foreach ($db['queries'] as $key => $query) {
$time = number_format($db['query_times'][$key], 4);
$highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT&nbsp;JOIN', 'ORDER&nbsp;BY', 'GROUP&nbsp;BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR&nbsp;', 'HAVING', 'OFFSET', 'NOT&nbsp;IN', 'IN', 'LIKE', 'NOT&nbsp;LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
foreach ($highlight as $bold) {
$query = str_replace($bold, '<strong style="color:#e0e0e0">'.$bold.'</strong>', $query);
}
echo '
<td>'.$db->hostname.'</td>
<td>'.$db->database.'</td>
<td>'.$db['hostname'].'</td>
<td>'.$db['database'].'</td>
<td>'.$query.'</td>
<td style="text-align:right">' . $time . '</td>';
$total_execution_time = array_sum($db->query_times);
$total_execution_time = array_sum($db['query_times']);
$global_execution_time += $total_execution_time;
++$count_queries;
}
?>
<?php else: ?>
<td><?php echo $db->hostname ?></td>
<td><?php echo $db->database ?></td>
<td><?php echo $db['hostname'] ?></td>
<td><?php echo $db['database'] ?></td>
<td><?php echo lang('no_queries') ?></td>
<td style="text-align:right"></td>
<?php endif ?>
</tr>
<?php endforeach ?>
<span style="display: none;" id="count_queries"><?php echo $count_queries ?></span>
<?php endif; ?>
</tbody>
<?php if ($global_execution_time > 0): ?>
<tfoot>
Expand Down Expand Up @@ -212,6 +219,8 @@
this.parentNode.className = 'active';
}, false);
}
var dbQueries = document.getElementById('count_queries').textContent;
document.getElementById('count_db_queries').textContent = ' ('+ dbQueries + ')';
</script>
<?php endif; ?>
</body>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "Codeigniter-DeveloperToolbar",
"version": "1.1"
"version": "1.2"
}

0 comments on commit d90ad1e

Please sign in to comment.