From edd46ebdb22b9cade2e6fa206bf9c52b4cf2183a Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 29 Jan 2021 11:51:40 +0530 Subject: [PATCH] add some admin UI for profiling the server's workers --- docs/profile.md | 22 --------------- www/admin/app-admin.less | 7 +++++ www/admin/inner.js | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 22 deletions(-) delete mode 100644 docs/profile.md diff --git a/docs/profile.md b/docs/profile.md deleted file mode 100644 index 469617cb5..000000000 --- a/docs/profile.md +++ /dev/null @@ -1,22 +0,0 @@ -```javascript -CryptPad_AsyncStore.rpc.send('ADMIN', - ['GET_WORKER_PROFILES'], - (e, _o) => { - var o = _o[0]; - // console.log(o[0]) - var sorted = Object.keys(o).sort(function (a, b) { - if (o[b] - o[a] <= 0) { return -1; } - return 1; - }); - var x = {}; - //console.log(sorted); - var total = 0; - sorted.forEach(function (k) { total += o[k]; }); - sorted.forEach(function (k) { - console.log("[%s] %ss running time (%s%)", k, o[k], Math.floor((o[k] / total) * 100)); - }); - } -) -``` - - diff --git a/www/admin/app-admin.less b/www/admin/app-admin.less index d19e6b4d7..940d6d712 100644 --- a/www/admin/app-admin.less +++ b/www/admin/app-admin.less @@ -167,6 +167,13 @@ } } + table#cp-performance-table { + td, th { + padding: 5px; + border: 1px solid #222; + } + } + input.cp-admin-inval { border-color: red !important; } diff --git a/www/admin/inner.js b/www/admin/inner.js index 597f8a7f3..ec86f816f 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -62,6 +62,9 @@ define([ 'support': [ 'cp-admin-support-list', 'cp-admin-support-init' + ], + 'performance': [ + 'cp-admin-performance-profiling', ] }; @@ -852,6 +855,63 @@ define([ return; }; + Messages.admin_cat_performance = "PERFORMANCE"; // XXX + Messages.admin_performanceProfilingHint = "Measure the running time of various server tasks by type"; // XXX + Messages.admin_performanceProfilingTitle = "Performance"; // XXX + + Messages.admin_performanceKeyHeading = 'KEY'; // XXX + Messages.admin_performanceTimeHeading = 'Time (seconds)'; // XXX + Messages.admin_performancePercentHeading = '%'; // XXX + + create['performance-profiling'] = function () { + var $div = makeBlock('performance-profiling'); + + var body = h('tbody'); + + var table = h('table#cp-performance-table', [ + h('thead', [ + h('th', Messages.admin_performanceKeyHeading), // XXX + h('th', Messages.admin_performanceTimeHeading), // XXX + h('th', Messages.admin_performancePercentHeading), // XXX + ]), + body, + ]); + + $div.append(table); + + var appendRow = function (key, time, percent) { + console.log("[%s] %ss running time (%s%)", key, time, percent); + body.appendChild(h('tr', [ key, time, percent ].map(function (x) { + return h('td', x); + }))); + }; + + var process = function (_o) { + var o = _o[0]; + var sorted = Object.keys(o).sort(function (a, b) { + if (o[b] - o[a] <= 0) { return -1; } + return 1; + }); + var x = {}; + var total = 0; + sorted.forEach(function (k) { total += o[k]; }); + sorted.forEach(function (k) { + var percent = Math.floor((o[k] / total) * 1000) / 10; + appendRow(k, o[k], percent) + }); + }; + + sFrameChan.query('Q_ADMIN_RPC', { + cmd: 'GET_WORKER_PROFILES', + }, function (e, data) { + if (e) { return void console.error(e); } + //console.info(data); + process(data); + }); + + return $div; + }; + var hideCategories = function () { APP.$rightside.find('> div').hide(); };