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..a97dcce11 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 admin + Messages.admin_performanceProfilingHint = "Measure the running time of various server tasks by type"; // XXX admin + Messages.admin_performanceProfilingTitle = "Performance"; // XXX admin + + Messages.admin_performanceKeyHeading = 'KEY'; // XXX admin + Messages.admin_performanceTimeHeading = 'Time (seconds)'; // XXX admin + Messages.admin_performancePercentHeading = '%'; // XXX admin + + 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), + h('th', Messages.admin_performanceTimeHeading), + h('th', Messages.admin_performancePercentHeading), + ]), + 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(); };