diff --git a/core/client.js b/core/client.js index 30472fc6..71ea3f3a 100644 --- a/core/client.js +++ b/core/client.js @@ -8,6 +8,8 @@ var gFiles = {}; var gApp = {files: {}}; var gEditor; var gSplit; +var gStats = {}; +var gGraph; var kErrorColor = "#dc322f"; var kStatusColor = "#fff"; @@ -77,6 +79,7 @@ function edit() { return; } + closeStats(); gSplit = Split(['#editPane', '#viewPane'], {minSize: 0}); ensureLoaded([ @@ -152,6 +155,15 @@ function trace() { request.send(); } +function stats() { + closeEditor(); + gSplit = Split(['#statsPane', '#viewPane'], {minSize: 0}); + document.getElementById("statsPane").style.display = 'flex'; + gGraph = new SmoothieChart({ grid: { strokeStyle: 'rgb(125, 0, 0)', fillStyle: 'rgb(60, 0, 0)', lineWidth: 1, millisPerLine: 10000, verticalSections: 6 } }); + gStats = {}; + gGraph.streamTo(document.getElementById('graph'), 10000); +} + function guessMode(name) { return name.endsWith(".js") ? "javascript" : name.endsWith(".html") ? "htmlmixed" : @@ -252,10 +264,20 @@ function load() { request.send(); } +function closeStats() { + document.getElementById("statsPane").style.display = 'none'; + if (gSplit) { + gSplit.destroy(); + gSplit = undefined; + } +} + function closeEditor() { document.getElementById("editPane").style.display = 'none'; - gSplit.destroy(); - gSplit = undefined; + if (gSplit) { + gSplit.destroy(); + gSplit = undefined; + } } function explodePath() { @@ -422,12 +444,25 @@ function receive(message) { } else if (message && message.action == "ping") { gSocket.send(JSON.stringify({action: "pong"})); } else if (message && message.action == "error") { - if (typeof(message.error) == 'string') { - setStatusMessage(message.error, '#f00', false); - } else { - setStatusMessage(message.error.message + '\n' + message.error.stack, '#f00', false); + if (message.error) { + if (typeof(message.error) == 'string') { + setStatusMessage(message.error, '#f00', false); + } else { + setStatusMessage(message.error.message + '\n' + message.error.stack, '#f00', false); + } + } + console.log('error', message); + } else if (message && message.action == "stats") { + if (gGraph) { + var now = new Date().getTime(); + for (var key of Object.keys(message.stats)) { + if (!gStats[key]) { + gStats[key] = new TimeSeries(); + gGraph.addTimeSeries(gStats[key]); + } + gStats[key].append(now, message.stats[key]); + } } - console.log(message.error); } } @@ -440,7 +475,6 @@ function keyEvent(event) { charCode: event.charCode, character: String.fromCharCode(event.keyCode || event.which), altKey: event.altKey, - }); } diff --git a/core/core.js b/core/core.js index 1091b300..f90bf6c2 100644 --- a/core/core.js +++ b/core/core.js @@ -293,6 +293,7 @@ var kStaticFiles = [ {uri: '/split.min.js'}, {uri: '/split.min.js.map'}, + {uri: '/smoothie.js'}, {uri: '/codemirror/codemirror.min.js'}, {uri: '/codemirror/base16-dark.min.css'}, {uri: '/codemirror/matchesonscrollbar.min.css'}, @@ -562,6 +563,16 @@ async function loadSettings() { } } +function sendStats() { + for (var process of Object.values(gProcesses)) { + if (process.app) { + process.app.send({action: 'stats', stats: getStats()}); + } + } + setTimeout(sendStats, 1000); +} +setTimeout(sendStats, 1000); + loadSettings().then(function() { var auth = require("auth"); var httpd = require("httpd"); diff --git a/core/index.html b/core/index.html index 3b76c79b..5f7eaf89 100644 --- a/core/index.html +++ b/core/index.html @@ -14,6 +14,7 @@ home edit trace + stats @@ -42,11 +43,18 @@ +