Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanhoekelen committed Mar 1, 2018
2 parents 504652a + e3faa9d commit 912fd76
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [v2.3.5](https://github.com/bvanhoekelen/performance/tree/v2.3.5) - 2018-03-01
### Add
- SQL query log for web presenter
### Change
- Max screen width to 140
### Fix
- Wrong time rounding by SQL query log

## [v2.3.4](https://github.com/bvanhoekelen/performance/tree/v2.3.4) - 2018-02-08
### Remove
- Remove default time zone UTC. This has to be set by the user in php.ini
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ See the [function overview](https://github.com/bvanhoekelen/performance/wiki/Doc

See [how to use query logging](https://github.com/bvanhoekelen/performance/wiki/Config-query-log).

## Web console
<p align="center"><img src="/assets/raw/php-performance-tool-full-data-review.png" alt="PHP performance tool with full date review" /></p>

See [how to use query logging](https://github.com/bvanhoekelen/performance/wiki/Config-query-log).

See [how to export data](https://github.com/bvanhoekelen/performance/wiki/Export-handler).

See [more info over data review](https://github.com/bvanhoekelen/performance/wiki/Config-presenter).

## Functions
Set measuring point with or without label
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bvanhoekelen/terminal-style": "^1.0"
},
"require-dev": {
"larapack/dd": "1.*",
"phpunit/phpunit": "^5.7",
"illuminate/database": "^5.4",
"illuminate/events": "^5.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/07_config_query_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct()
public function taskA()
{
// Set point Task A
Performance::point(__FUNCTION__);
Performance::point('Run database query\'s');

// Create user
$user = new User();
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Handlers/PerformanceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PerformanceHandler
/*
* Version
*/
const VERSION = '2.3.4';
const VERSION = '2.3.5';

/*
* Store current point
Expand Down
34 changes: 34 additions & 0 deletions src/Lib/Holders/QueryLineHolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php namespace Performance\Lib\Holders;

class QueryLineHolder{
private $line;
private $time;

/**
* @return string
*/
public function getLine() {
return $this->line;
}

/**
* @param mixed $line
*/
public function setLine($line) {
$this->line = $line;
}

/**
* @return string
*/
public function getTime() {
return $this->time;
}

/**
* @param mixed $time
*/
public function setTime($time) {
$this->time = number_format((float)$time, 2, '.', '');
}
}
46 changes: 6 additions & 40 deletions src/Lib/Presenters/ConsolePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function finishPointTrigger(Point $point)
. '|' . str_pad( $this->formatter->memoryToHuman( $point->getMemoryPeak() ) . ' ', $this->cellWightResult, " ", STR_PAD_LEFT) . PHP_EOL);

// Print query log resume
$this->printPointQueryLogAsNewLineMessage($point);
foreach ($this->formatter->createPointQueryLogLineList($point) as $queryLineHolder)
{
$this->printMessage($queryLineHolder->getLine(), $queryLineHolder->getTime() . ' ms ');
}

// Print point new line message
$this->printPointNewLineMessage($point);
Expand Down Expand Up @@ -131,8 +134,8 @@ private function setCommandSize()

if($this->commandLineWidth < 60)
$this->commandLineWidth = 60;
if ($this->commandLineWidth > 100)
$this->commandLineWidth = 100;
if ($this->commandLineWidth > 140)
$this->commandLineWidth = 140;

/*
* |<------------------------------- ( Terminal wight ) ---------------------------------->|
Expand Down Expand Up @@ -174,41 +177,4 @@ public function printMessage($message = null, $time = '-- ', $memory = '-- ', $p
. '|' . str_pad($memory, $this->cellWightResult, ' ', STR_PAD_LEFT)
. '|' . str_pad($peak, $this->cellWightResult, ' ', STR_PAD_LEFT) , 'dark-gray'). PHP_EOL );
}

private function printPointQueryLogAsNewLineMessage(Point $point)
{
// View type resume
if($this->config->getQueryLogView() == 'resume')
{
$infoArray = [];

foreach ($point->getQueryLog() as $queryLogHolder) {
$type = $queryLogHolder->queryType;

if (isset($infoArray[$type])) {
$infoArray[$type]['count']++;
$infoArray[$type]['time'] = $infoArray[$type]['time'] + $queryLogHolder->time;
} else {
$infoArray[$type]['count'] = 1;
$infoArray[$type]['time'] = $queryLogHolder->time;
}
}

ksort($infoArray);

foreach ($infoArray as $key => $item) {
$this->printMessage('Database query ' . $key . ' ' . $item['count'] . 'x', $item['time'] . ' ms ');

}
}

// View type full
if($this->config->getQueryLogView() == 'full')
{
foreach ($point->getQueryLog() as $queryLogHolder) {
$this->printMessage('Database query ' . $queryLogHolder->query, $queryLogHolder->time . ' ms ');

}
}
}
}
61 changes: 60 additions & 1 deletion src/Lib/Presenters/Formatter.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?php namespace Performance\Lib\Presenters;

use Performance\Lib\Handlers\ConfigHandler;
use Performance\Lib\Holders\QueryLineHolder;
use Performance\Lib\Point;

class Formatter {

public function __construct(){}
private $config;
public function __construct(ConfigHandler $config){
$this->config = $config;
}

public function timeToHuman($microTime, $unit = 'auto', $decimals = 2)
{
Expand Down Expand Up @@ -88,4 +95,56 @@ public function stringPad($input, $pad_length, $pad_string = ' ')

return str_repeat($pad_string, $space) . $input;
}

public function createPointQueryLogLineList(Point $point)
{
$lineArray = [];
if(!$point->getQueryLog())
{
return $lineArray;
}

if($this->config->getQueryLogView() == 'resume')
{
$buildLineList = [];
foreach ($point->getQueryLog() as $queryLogHolder) {
$type = $queryLogHolder->queryType;
if (isset($buildLineList[$type]))
{
$buildLineList[$type]['count']++;
$buildLineList[$type]['time'] = $buildLineList[$type]['time'] + $queryLogHolder->time;
}
else
{
$buildLineList[$type]['count'] = 1;
$buildLineList[$type]['time'] = $queryLogHolder->time;
}
}
ksort($buildLineList);
foreach ($buildLineList as $key => $item) {
$queryLineHolder = new QueryLineHolder();
$queryLineHolder->setLine('Database query ' . $key . ' ' . $item['count'] . 'x');
$queryLineHolder->setTime($item['time']);
$lineArray[] = $queryLineHolder;
}
}

// View type full
if($this->config->getQueryLogView() == 'full')
{
foreach ($point->getQueryLog() as $queryLogHolder) {
$queryLineHolder = new QueryLineHolder();
$queryLineHolder->setLine($queryLogHolder->query);
$queryLineHolder->setTime($queryLogHolder->time);
$lineArray[] = $queryLineHolder;
}
}

return $lineArray;
}

public function formatStringWidth($string, $width)
{
return ((strlen($string) > $width) ? substr($string,0, $width - 3).'...' : $string);
}
}
2 changes: 1 addition & 1 deletion src/Lib/Presenters/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class Presenter {
public function __construct(ConfigHandler $config)
{
$this->config = $config;
$this->formatter = new Formatter();
$this->formatter = new Formatter($config);
$this->calculate = new Calculate();
$this->information = new InformationHolder($config);

Expand Down
20 changes: 9 additions & 11 deletions src/Lib/Presenters/WebPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private function displayForWebAsHtml()
echo '<div id="performance-tool">';
echo '<a id="performance-btn-close" href="#" onclick="performanceDisplayToggle(null)">&#9660;</a>';
echo '<div id="hiddenContent">';
if(count($this->pointStack) > 2)
{
if(count($this->pointStack) > 2) {
$textExecutionTime = (ini_get('max_execution_time') > 1) ? ini_get('max_execution_time') . ' sec' : 'unlimited';
$calculateTotalHolder = $this->calculate->totalTimeAndMemory($this->pointStack);

Expand All @@ -69,7 +68,8 @@ private function displayForWebAsHtml()
<th width="17%">Time</th>
</tr>';

foreach (array_slice($this->pointStack, 1) as $point) {
foreach (array_slice($this->pointStack, 1) as $point)
{

// For real calibrate results fake printing
if( $point->getLabel() === Point::POINT_PRELOAD or $point->getLabel() === Point::POINT_MULTIPLE_PRELOAD)
Expand All @@ -83,14 +83,12 @@ private function displayForWebAsHtml()
. '<td>' . $this->formatter->timeToHuman($point->getDifferenceTime()) . '</td>'
. '</tr>';

foreach ($point->getQueryLog() as $queryLogHolder)
{
echo '<tr>';
echo'<td class="new-line-message" colspan="4"> - ' . ((strlen($queryLogHolder->query) > 70) ? substr($queryLogHolder->query,0,67).'...' : $queryLogHolder->query) . '</td>';
echo'<td class="new-line-message" style="text-align: right;" colspan="1">' . $queryLogHolder->time . ' ms</td>';
echo '</tr>';
}

foreach($this->formatter->createPointQueryLogLineList($point) as $queryLineHolder){
echo '<tr>';
echo '<td class="new-line-message" colspan="3"> - ' . $this->formatter->formatStringWidth($queryLineHolder->getLine(), 70) . '</td>';
echo '<td class="new-line-message" style="text-align: right;" colspan="2">' . $queryLineHolder->getTime() . ' ms</td>';
echo '</tr>';
}
foreach ($point->getNewLineMessage() as $message)
{
echo '<tr><td class="new-line-message" colspan="5">' . $message . '</td></tr>';
Expand Down

0 comments on commit 912fd76

Please sign in to comment.