diff --git a/index.php b/index.php index b17dbb9..d233d46 100644 --- a/index.php +++ b/index.php @@ -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'])) { Reset + diff --git a/php-console.js b/php-console.js index 0d7561c..80e7be5 100644 --- a/php-console.js +++ b/php-console.js @@ -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, '' + identifier + ''); diff --git a/styles.css b/styles.css index b1663c7..6381955 100644 --- a/styles.css +++ b/styles.css @@ -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; } \ No newline at end of file