reuse cp-charts to visualize server task running time as bar charts

pull/1/head
ansuz 3 years ago
parent bfdcf4ec0c
commit eafe27ffb4

@ -1,12 +1,14 @@
@import (reference) '../../customize/src/less2/include/framework.less'; @import (reference) '../../customize/src/less2/include/framework.less';
@import (reference) '../../customize/src/less2/include/sidebar-layout.less'; @import (reference) '../../customize/src/less2/include/sidebar-layout.less';
@import (reference) '../../customize/src/less2/include/support.less'; @import (reference) '../../customize/src/less2/include/support.less';
@import (reference) '../../customize/src/less2/include/charts.less';
&.cp-app-admin { &.cp-app-admin {
.framework_min_main(); .framework_min_main();
.sidebar-layout_main(); .sidebar-layout_main();
.support_main(); .support_main();
.charts_main();
.cp-hidden { .cp-hidden {
display: none !important; display: none !important;
@ -294,5 +296,27 @@
} }
} }
} }
span.cp-bar.profiling-percentage {
text-align: center;
padding: 5px;
}
span.profiling-label {
position: absolute;
z-index: 1;
width: 100%;
text-align: center;
padding: 5px;
}
#profiling-chart {
.cp-bar-container {
max-width: 400px;
}
}
.width-constrained {
max-width: 800px;
}
.cp-charts-row.heading {
font-weight: bold;
}
} }

@ -1673,34 +1673,51 @@ define([
var $div = makeBlock('performance-profiling'); // Msg.admin_performanceProfilingHint, .admin_performanceProfilingTitle var $div = makeBlock('performance-profiling'); // Msg.admin_performanceProfilingHint, .admin_performanceProfilingTitle
var onRefresh = function () { var onRefresh = function () {
var body = h('tbody'); var createBody = function () {
return h('div#profiling-chart.cp-charts.cp-bar-table', [
h('span.cp-charts-row.heading', [
h('span', Messages.admin_performanceKeyHeading),
h('span', Messages.admin_performanceTimeHeading),
h('span', Messages.admin_performancePercentHeading),
//h('span', ''), //Messages.admin_performancePercentHeading),
]),
]);
};
var table = h('table#cp-performance-table', [ var body = createBody();
h('thead', [ var appendRow = function (key, time, percent, scaled) {
h('th', Messages.admin_performanceKeyHeading), //console.log("[%s] %ss running time (%s%)", key, time, percent);
h('th', Messages.admin_performanceTimeHeading), body.appendChild(h('span.cp-charts-row', [
h('th', Messages.admin_performancePercentHeading), h('span', key),
]), h('span', time),
body, //h('span', percent),
]); h('span.cp-bar-container', [
var appendRow = function (key, time, percent) { h('span.cp-bar.profiling-percentage', {
console.log("[%s] %ss running time (%s%)", key, time, percent); style: 'width: ' + scaled + '%',
body.appendChild(h('tr', [ key, time, percent ].map(function (x) { }, ' ' ),
return h('td', x); h('span.profiling-label', percent + '%'),
}))); ]),
]));
}; };
var process = function (_o) { var process = function (_o) {
$('#profiling-chart').remove();
body = createBody();
var o = _o[0]; var o = _o[0];
var sorted = Object.keys(o).sort(function (a, b) { var sorted = Object.keys(o).sort(function (a, b) {
if (o[b] - o[a] <= 0) { return -1; } if (o[b] - o[a] <= 0) { return -1; }
return 1; return 1;
}); });
var values = sorted.map(function (k) { return o[k]; });
var total = 0; var total = 0;
sorted.forEach(function (k) { total += o[k]; }); values.forEach(function (value) { total += value; });
var max = Math.max.apply(null, values);
sorted.forEach(function (k) { sorted.forEach(function (k) {
var percent = Math.floor((o[k] / total) * 1000) / 10; var percent = Math.floor((o[k] / total) * 1000) / 10;
appendRow(k, o[k], percent); appendRow(k, o[k], percent, (o[k] / max) * 100);
}); });
$div.append(h('div.width-constrained', body));
}; };
sFrameChan.query('Q_ADMIN_RPC', { sFrameChan.query('Q_ADMIN_RPC', {
@ -1710,10 +1727,7 @@ define([
UI.warn(Messages.error); UI.warn(Messages.error);
return void console.error(e, data); return void console.error(e, data);
} }
//console.info(data);
$div.find("table").remove();
process(data); process(data);
$div.append(table);
}); });
}; };

Loading…
Cancel
Save