Merge pull request #31 from staabm/runtime-info

added server-side runtime information (memory, rendertime) into the cons...
master
Jordi Boggiano 11 years ago
commit 676780c743
  1. 19
      index.php
  2. 13
      php-console.js
  3. 7
      styles.css

@ -70,11 +70,25 @@ if (isset($_POST['code'])) {
}
ob_start();
$start = microtime(true);
$memBefore = memory_get_usage(true);
eval($code);
$debugOutput = ob_get_clean();
// compare with peak, because regular memory could be free'd already
$memAfter = memory_get_peak_usage(true);
$end = microtime(true);
$debugOutput .= ob_get_clean();
if (isset($_GET['js'])) {
header('Content-Type: text/plain');
$memory = sprintf('%.3f', ($memAfter - $memBefore) / 1024.0 / 1024.0); // in MB
$rendertime = sprintf('%.3f', (($end - $start) * 1000)); // in ms
header('X-Memory-Usage: '. $memory);
header('X-Rendertime: '. $rendertime);
echo $debugOutput;
die('#end-php-console-output#');
}
@ -127,6 +141,7 @@ if (isset($_POST['code'])) {
</object>
</span>
<a href="" class="reset">Reset</a>
<span class="runtime-info"></span>
</div>
</div>
<input type="submit" name="subm" value="Try this!" />

@ -104,8 +104,17 @@
};
// eval server-side
$.post('?js=1', { code: editor.getSession().getValue() }, function (res) {
if (res.match(/#end-php-console-output#$/)) {
$.post('?js=1', { code: editor.getSession().getValue() }, function (res, status, jqXHR) {
var mem = jqXHR.getResponseHeader("X-Memory-Usage") || "",
rendertime = jqXHR.getResponseHeader("X-Rendertime") || "";
if (mem || rendertime) {
$('.statusbar .runtime-info').text('Memory usage: '+ mem + ' MB, Rendertime: ' + rendertime + 'ms');
} else {
$('.statusbar .runtime-info').text('');
}
if (res.match(/#end-php-console-output#$/)) {
var result = res.substring(0, res.length - 24);
$.each(controlChars, function (identifier, regex) {
result = result.replace(regex, '<span class="control-char">' + identifier + '</span>');

@ -104,4 +104,11 @@ a {
-webkit-border-radius: 3px;
border-radius: 3px;
padding: 1px 2px;
}
.statusbar .runtime-info {
text-align: right;
float: right;
clear: right;
width: 350px;
}
Loading…
Cancel
Save