Skip to content

Commit

Permalink
v1.1.0 Continuous improve and modernize.
Browse files Browse the repository at this point in the history
PHP version is now required v 5.4.

Rundiz/number is no more required but suggested.

PHP section now showing extensions and ini settings.

Logs section currently have summaries for each log type.

Time Load section can use `matchKey` to check self cost and have 1 morer
column. It is self time.

Memory Usage section can also use `matchKey` and have 1 more column. It
is self memory.

Database section is now always using self time and self memory. Any devs
must add memory_get_usage() while calling to profiling the database
otherwise the PHP will trigger the errors.

Due to the `memory` array key in the Database section will be removed in
the future so devs have to remove it and use `memory_start` and
`memory_end` instead.

Change how display.php template works. Now it is a lot looks easier.

You can check between `matchKey` in each section for beginning and end
value by click on the matchKey name.
  • Loading branch information
ve3 committed May 29, 2017
1 parent 12dc98c commit b47d9ce
Show file tree
Hide file tree
Showing 17 changed files with 657 additions and 209 deletions.
9 changes: 7 additions & 2 deletions Rundiz/Profiler/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function __construct(\Rundiz\Profiler\Profiler $profiler) {
*
* @param string $data SQL query statement. for example: SELECT id FROM people;.
* @param double $time_start `microtime(true)` at before start the query.
* @param integer $memory_start `memory_get_usage()` at before start the query. If this was not set then it will be showing current running memory usage not total memory usage for this process.
* @param integer $memory_start `memory_get_usage()` at before start the query. If this was not set then it will not be showing the real memory start. (Required).
* @todo [rundizprofiler] the "memory" in array key for Database will be remove in future version.
*/
public function database($data, $time_start, $memory_start = null)
{
Expand All @@ -60,8 +61,12 @@ public function database($data, $time_start, $memory_start = null)
$time_start = $this->Profiler->getMicrotime();
}

if ($memory_start === null) {
// is dev still not using memory start? trigger error.
trigger_error('You did not enter $memory_start argument for \Rundiz\Profiler\Console->database() method. Please set the $memory_start to memory_get_usage() in your code.', E_USER_NOTICE);
}
if (!is_int($memory_start)) {
$memory_start = null;
$memory_start = memory_get_usage();
}

$backtrace = debug_backtrace();
Expand Down
4 changes: 3 additions & 1 deletion Rundiz/Profiler/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public function display($dbh = '', $display_db_function = '')
// return display views.
ob_start();
require __DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'display.php';
$this->reset();
$output = ob_get_contents();
ob_end_clean();

return $output;
}// display

Expand Down Expand Up @@ -243,7 +245,7 @@ private function gatherInputSession()
*/
public function getReadableFileSize($size, $retstring = null) {
// adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
$sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

if ($retstring === null) {
$retstring = '%01.2f %s';
Expand Down
12 changes: 12 additions & 0 deletions Rundiz/Profiler/ProfilerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ abstract class ProfilerBase
protected $end_time;


/**
* Reset everything to cleanup.
*/
protected function reset()
{
$this->log_sections = [];
$this->max_memory_usage = null;
$this->start_time = null;
$this->end_time = null;
}// reset


}
46 changes: 46 additions & 0 deletions Rundiz/Profiler/views/display-Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is included by display.php
// Set document for helper in IDE.
/* @var $this \Rundiz\Profiler\Profiler */

$summary = count($data_array);

echo "\n";
?>
<li id="Section<?php echo $section_to_id; ?>" class="rdprofiler-see-details">
<a class="see-details" title="<?php echo $summary; ?>"><strong><?php echo $section; ?></strong> <?php echo $summary; ?></a>
<ul>
<li class="rdprofiler-log-summary-row">
<div class="rdprofiler-log-data">SQL statement</div>
<div class="rdprofiler-log-db-timetake">Self Time</div>
<div class="rdprofiler-log-memory">Self Memory</div>
</li><!--.rdprofiler-log-summary-row-->
<?php
if (is_array($data_array) && !empty($data_array)) {
foreach ($data_array as $data_key => $data_values) {
if (is_numeric($data_key) && is_array($data_values) && array_key_exists('data', $data_values)) {
// if contain data then display, otherwise just skip it.
?>
<li>
<?php
echo "\n";
echo rdProfilerIndent(6).'<pre class="rdprofiler-log-data">'."\n".htmlspecialchars(trim(print_r($data_values['data'], true)), ENT_QUOTES)."\n".rdProfilerIndent(6).'</pre>'."\n";

if ($section == 'Database') {
call_user_func($display_db_function, $this, $dbh, $data_values);
}
?>
</li>
<?php
}
}// endforeach; $data_array
// endforeach of loop display each section's log detail.
unset($data_key, $data_values);
} else {
?>
<li><pre class="rdprofiler-log-data">There is no data to display.</pre></li>
<?php } ?>
</ul>
</li><!--#SectionXXXX-->
<?php
unset($summary);
79 changes: 79 additions & 0 deletions Rundiz/Profiler/views/display-Files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
// This file is included by display.php
// Set document for helper in IDE.
/* @var $this \Rundiz\Profiler\Profiler */

$summary = (count($data_array)-2);

echo "\n";
?>
<li id="Section<?php echo $section_to_id; ?>" class="rdprofiler-see-details">
<a class="see-details" title="<?php echo $summary; ?>"><strong><?php echo $section; ?></strong> <?php echo $summary; ?></a>
<ul>
<li class="rdprofiler-log-summary-row">
<div class="rdprofiler-log-file-totalsize">File</div>
<div class="rdprofiler-log-file-totalsize-value">Size</div>
</li><!--.rdprofiler-log-summary-row-->
<?php if (isset($data_array['total_size'])) { ?>
<li class="rdprofiler-log-summary-row">
<div class="rdprofiler-log-file-totalsize">Total size</div>
<div class="rdprofiler-log-file-totalsize-value"><?php
echo "\n";
if (isset($number)) {
echo rdProfilerIndent(7).$number->fromBytes($data_array['total_size']);
} else {
echo rdProfilerIndent(7).$this->getReadableFileSize($data_array['total_size']);
}
?>
</div>
</li><!--.rdprofiler-log-summary-row-->
<?php }// endif; total size ?>
<?php if (isset($data_array['largest_size'])) { ?>
<li class="rdprofiler-log-summary-row">
<div class="rdprofiler-log-file-largestsize">Largest size</div>
<div class="rdprofiler-log-file-largestsize-value"><?php
echo "\n";
if (isset($number)) {
echo rdProfilerIndent(7).$number->fromBytes($data_array['largest_size']);
} else {
echo rdProfilerIndent(7).$this->getReadableFileSize($data_array['largest_size']);
}
?>
</div>
</li><!--.rdprofiler-log-summary-row-->
<?php }// endif; largest size ?>
<?php
if (is_array($data_array) && !empty($data_array)) {
foreach ($data_array as $data_key => $data_values) {
if (is_numeric($data_key) && is_array($data_values) && array_key_exists('data', $data_values)) {
// if contain data then display, otherwise just skip it.
?>
<li>
<?php
echo "\n";
echo rdProfilerIndent(6).'<pre class="rdprofiler-log-data">'."\n".htmlspecialchars(trim(print_r($data_values['data'], true)), ENT_QUOTES)."\n".rdProfilerIndent(6).'</pre>'."\n";

if (isset($data_values['size'])) {
echo rdProfilerIndent(6).'<div class="rdprofiler-log-filesize">';
if (isset($number)) {
echo $number->fromBytes($data_values['size']);
} else {
echo $this->getReadableFileSize($data_values['size']);
}
echo '</div>'."\n";
}
?>
</li>
<?php
}
}// endforeach; $data_array
// endforeach of loop display each section's log detail.
unset($data_key, $data_values);
} else {
?>
<li><pre class="rdprofiler-log-data">There is no data to display.</pre></li>
<?php } ?>
</ul>
</li><!--#SectionXXXX-->
<?php
unset($summary);
71 changes: 71 additions & 0 deletions Rundiz/Profiler/views/display-Logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
// This file is included by display.php
// Set document for helper in IDE.
/* @var $this \Rundiz\Profiler\Profiler */

$summary = count($data_array);

echo "\n";
?>
<li id="Section<?php echo $section_to_id; ?>" class="rdprofiler-see-details">
<a class="see-details" title="<?php echo $summary; ?>"><strong><?php echo $section; ?></strong> <?php echo $summary; ?></a>
<ul>
<li class="rdprofiler-log-summary-row">
<table class="rdprofiler-log-logtypes">
<tr>
<td class="rdprofiler-log-logtype debug">Debug (<?php echo $this->countTotalLogType('debug'); ?>)</td>
<td class="rdprofiler-log-logtype info">Info (<?php echo $this->countTotalLogType('info'); ?>)</td>
<td class="rdprofiler-log-logtype notice">Notice (<?php echo $this->countTotalLogType('notice'); ?>)</td>
<td class="rdprofiler-log-logtype warning">Warning (<?php echo $this->countTotalLogType('warning'); ?>)</td>
<td class="rdprofiler-log-logtype error">Error (<?php echo $this->countTotalLogType('error'); ?>)</td>
<td class="rdprofiler-log-logtype critical">Critical (<?php echo $this->countTotalLogType('critical'); ?>)</td>
<td class="rdprofiler-log-logtype alert">Alert (<?php echo $this->countTotalLogType('alert'); ?>)</td>
<td class="rdprofiler-log-logtype emergency">Emergency (<?php echo $this->countTotalLogType('emergency'); ?>)</td>
</tr>
</table>
</li><!--.rdprofiler-log-summary-row-->
<?php
if (is_array($data_array) && !empty($data_array)) {
foreach ($data_array as $data_key => $data_values) {
if (is_numeric($data_key) && is_array($data_values) && array_key_exists('data', $data_values)) {
// if contain data then display, otherwise just skip it.
?>
<li>
<?php
echo "\n";
if (isset($data_values['logtype'])) {
// if log type exists. this is only for Logs section.
echo rdProfilerIndent(6).'<div class="rdprofiler-log-logtype '.strip_tags($data_values['logtype']).'">'.strip_tags(ucfirst($data_values['logtype'])).'</div>'."\n";
}

echo rdProfilerIndent(6).'<pre class="rdprofiler-log-data">'."\n".htmlspecialchars(trim(print_r($data_values['data'], true)), ENT_QUOTES)."\n".rdProfilerIndent(6).'</pre>'."\n";

if ((isset($data_values['file']) && $data_values['file'] != null) || (isset($data_values['line']) && $data_values['line'] != null)) {
// if contain file and line data then display it. this appears in these sections: Logs, Time Load, Memory Usage.
echo rdProfilerIndent(6).'<div class="rdprofiler-log-fileline">';
if (isset($data_values['file']) && $data_values['file'] != null) {
echo htmlspecialchars($data_values['file'], ENT_QUOTES);
}
if ((isset($data_values['file']) && $data_values['file'] != null) && (isset($data_values['line']) && $data_values['line'] != null)) {
echo ', line ';
}
if (isset($data_values['line']) && $data_values['line'] != null) {
echo strip_tags($data_values['line']);
}
echo '</div>'."\n";
}
?>
</li>
<?php
}
}// endforeach; $data_array
// endforeach of loop display each section's log detail.
unset($data_key, $data_values);
} else {
?>
<li><pre class="rdprofiler-log-data">There is no data to display.</pre></li>
<?php } ?>
</ul>
</li><!--#SectionXXXX-->
<?php
unset($summary);
Loading

0 comments on commit b47d9ce

Please sign in to comment.