Skip to content

Commit

Permalink
Rename class name, add display toggle for web interface (store displa…
Browse files Browse the repository at this point in the history
…y preference in local web store).
  • Loading branch information
bvanhoekelen committed Jul 17, 2017
1 parent 4d1495d commit 420648b
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 77 deletions.
47 changes: 31 additions & 16 deletions src/Lib/Presenters/DisplayHtml.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.performance *{
#performance-tool *{
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: Times;
}

.performance{
#performance-tool{
display: block;
position: fixed;
border: solid #ccc 1px;
Expand All @@ -25,7 +25,7 @@
body{
margin-bottom: 350px;
}
.performance {
#performance-tool {
bottom: 0px;
left: 0;
right: 0;
Expand All @@ -34,68 +34,83 @@
}
}

.performance .overflow{
#performance-tool .overflow{
overflow: auto;
height: 77%;
border-top: solid #bababa 1px;
}

.performance .table-title{
#performance-tool .table-title{
width: 100%;
background-color: #fff;
}
.performance .table-title td{
#performance-tool .table-title td{
text-align: center;
padding: 8px;
font-size: 28px;
}
.performance .table-point .t-l{
#performance-tool .table-point .t-l{
text-align: left;
}
.performance .table-point .new-line-message{
#performance-tool .table-point .new-line-message{
color: #333;
text-align: left;
padding-left: 14px;
}

.performance .table-title td span{
#performance-tool .table-title td span{
font-size: 12px;
}

.performance .table-point {
#performance-tool .table-point {
width: 100%;
}

.performance .table-point th{
#performance-tool .table-point th{
background-color: #e2e2e2;

}

.performance .table-point tr:nth-child(odd) {
#performance-tool .table-point tr:nth-child(odd) {
background-color: #f2f2f2;
}
.performance .table-point tr:hover{
#performance-tool .table-point tr:hover{
background-color: #e2e2e2;

}

.performance .table-point td{
#performance-tool .table-point td{
padding: 4px;
text-align: right;
}

.performance .table-more-info{
#performance-tool .table-more-info{
border-top: solid #ccc 2px;
color: #555;
padding: 14px 10px;
text-align: center;
}

.performance code {
#performance-tool code {
background-color: #2b542c;
margin: 20px;
padding: 20px;
display: block;
background:#F8F8FF;
border:black dashed 1px;
}

#performance-btn-close{
position: absolute;
right: 0;
top: 0;
margin: 0px;
padding: 10px;
color: #ccc;
text-decoration: none;
border-radius: 100%;
}

#performance-btn-close:hover{
color: #e09a0f;
}
37 changes: 37 additions & 0 deletions src/Lib/Presenters/DisplayScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Set web store
if (typeof(Storage) !== "undefined")
{
if( ! localStorage.performanceToolDisplay)
localStorage.performanceToolDisplay = 'show';

if(localStorage.performanceToolDisplay == 'hide')
performanceDisplayToggle(false);
}


function performanceDisplayToggle(show)
{
x = document.getElementById('hiddenContent');
y = document.getElementById('performance-tool');
z = document.getElementById('performance-btn-close');
status = null;
if( x.style.display == 'none' || show == true)
{
x.style.display = 'block';
y.style.height = 300;
y.style.maxWidth = 500;
z.innerHTML = '▼';
status = 'show';
}
else
{
x.style.display = 'none';
y.style.height = 40;
y.style.maxWidth = 36;
z.innerHTML = '▲';
status = 'hide';
}

if(typeof(Storage) !== "undefined" && show == null)
localStorage.performanceToolDisplay = status;
}
130 changes: 69 additions & 61 deletions src/Lib/Presenters/WebPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,73 +43,81 @@ private function displayForWebAsHtml()
include_once 'DisplayHtml.css';
echo '</style>';

echo '<div class="performance">';
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);

echo'<table class="table-title">
<tr>
<td width="50%">' . $this->formatter->memoryToHuman($calculateTotalHolder->totalMemory) . '<br><span>Max memory ' . ini_get("memory_limit") . '</span></td>
<td width="50%">' . $this->formatter->timeToHuman($calculateTotalHolder->totalTime) . '<br><span>Max time ' . $textExecutionTime . ' on PHP ' . phpversion() . '</span></td>
</tr>
</table>
<div class="overflow">
<table class="table-point">
<tr>
<th>Label</th>
<th width="5%">%</th>
<th width="17%">Memory</th>
<th width="5%">%</th>
<th width="17%">Time</th>
</tr>';

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

// For real calibrate results fake printing
if( $point->getLabel() === Point::POINT_CALIBRATE )
continue;

echo '<tr>'
. '<td class="t-l">' . $point->getLabel() . '</td>'
. '<td>' . $this->calculate->calculatePercentage($point->getDifferenceMemory(), $calculateTotalHolder->totalMemory) . '</td>'
. '<td>' . $this->formatter->memoryToHuman($point->getDifferenceMemory()) . '</td>'
. '<td>' . $this->calculate->calculatePercentage($point->getDifferenceTime(), $calculateTotalHolder->totalTime) . '</td>'
. '<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>';
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)
{
$textExecutionTime = (ini_get('max_execution_time') > 1) ? ini_get('max_execution_time') . ' sec' : 'unlimited';
$calculateTotalHolder = $this->calculate->totalTimeAndMemory($this->pointStack);

echo'<table class="table-title">
<tr>
<td width="50%">' . $this->formatter->memoryToHuman($calculateTotalHolder->totalMemory) . '<br><span>Max memory ' . ini_get("memory_limit") . '</span></td>
<td width="50%">' . $this->formatter->timeToHuman($calculateTotalHolder->totalTime) . '<br><span>Max time ' . $textExecutionTime . ' on PHP ' . phpversion() . '</span></td>
</tr>
</table>
<div class="overflow">
<table class="table-point">
<tr>
<th>Label</th>
<th width="5%">%</th>
<th width="17%">Memory</th>
<th width="5%">%</th>
<th width="17%">Time</th>
</tr>';

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

// For real calibrate results fake printing
if( $point->getLabel() === Point::POINT_CALIBRATE )
continue;

echo '<tr>'
. '<td class="t-l">' . $point->getLabel() . '</td>'
. '<td>' . $this->calculate->calculatePercentage($point->getDifferenceMemory(), $calculateTotalHolder->totalMemory) . '</td>'
. '<td>' . $this->formatter->memoryToHuman($point->getDifferenceMemory()) . '</td>'
. '<td>' . $this->calculate->calculatePercentage($point->getDifferenceTime(), $calculateTotalHolder->totalTime) . '</td>'
. '<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 ($point->getNewLineMessage() as $message)
{
echo '<tr><td class="new-line-message" colspan="5">' . $message . '</td></tr>';
}
}
echo '</table>';

foreach ($point->getNewLineMessage() as $message)
{
echo '<tr><td class="new-line-message" colspan="5">' . $message . '</td></tr>';
}
}
echo '</table>';

$calibratePoint = $this->pointStack[1];
$calibratePoint = $this->pointStack[1];

echo '<div class="table-more-info">Performance v' . PerformanceHandler::VERSION
. ' PHP v' . phpversion() . ' on ' . date('Y-m-d H:i:s')
. '<br>Calibrate point: ' . $this->formatter->timeToHuman($calibratePoint->getDifferenceTime());
echo '<div class="table-more-info">Performance v' . PerformanceHandler::VERSION
. ' PHP v' . phpversion() . ' on ' . date('Y-m-d H:i:s')
. '<br>Calibrate point: ' . $this->formatter->timeToHuman($calibratePoint->getDifferenceTime());

if($this->config->isRunInformation())
echo "<br> Run by user " . $this->information->getCurrentUser() . " on process id " . $this->information->getCurrentProcessId();
if($this->config->isRunInformation())
echo "<br> Run by user " . $this->information->getCurrentUser() . " on process id " . $this->information->getCurrentProcessId();

echo '</div>';
echo '</div>';
echo '</div>';
}
else
echo '<div class="table-more-info"> <h2>There are not point set</h2>Set your first point with <var>point</var> command:<br><code>Performance::point()</code>Final you can view the results with the <var>results</var> command:<br><code>Performance::results()</code></div>';
}
else
echo '<div class="table-more-info"> <h2>There are not point set</h2>Set your first point with <var>point</var> command:<br><code>Performance::point()</code>Final you can view the results with the <var>results</var> command:<br><code>Performance::results()</code></div>';
echo '</div>';

echo '<script>';
include_once 'DisplayScript.js';
echo '</script>';

echo '</div>';
}
}

0 comments on commit 420648b

Please sign in to comment.