From eb903752e625988e9edade6d5259947a367a00d9 Mon Sep 17 00:00:00 2001 From: Sandra Date: Mon, 31 Jan 2022 05:15:14 +0100 Subject: [PATCH] Fix cpu history not being relative to the previous entry --- .../report/history/ReportHistoryProcStat.vue | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/report/history/ReportHistoryProcStat.vue b/frontend/src/components/report/history/ReportHistoryProcStat.vue index f8ccf1f..2e1c261 100644 --- a/frontend/src/components/report/history/ReportHistoryProcStat.vue +++ b/frontend/src/components/report/history/ReportHistoryProcStat.vue @@ -47,7 +47,7 @@ export default { type: Object } }, - data: function() { + data: function () { const metrics = ['cpu/user', 'cpu/nice', 'cpu/system', 'cpu/idle', 'cpu/iowait', 'cpu/irq', 'cpu/softirq', 'cpu/steal', 'cpu/guest', 'cpu/guest_nice']; const header = this.report.header; @@ -59,11 +59,18 @@ export default { .map(row => row.reduce((a, b) => a + b, 0)) const series = metrics.map(metric => { - const index = header.indexOf(metric); - return { - name: metric.replace('cpu/', ''), - data: data.map((entry, i) => [new Date(entry[timeIndex] * 1000), (entry[index] / cpuDataSums[i] * 100)]) - } + const headerIndex = header.indexOf(metric); + const name = metric.replace('cpu/', ''); + const mData = data.map((entry, rowIndex) => { + let share = rowIndex > 0 + ? (entry[headerIndex] - data[rowIndex - 1][headerIndex]) / (cpuDataSums[rowIndex] - cpuDataSums[rowIndex - 1]) + : entry[headerIndex] / cpuDataSums[rowIndex]; + return [ + new Date(entry[timeIndex] * 1000), + share * 100 + ]; + }); + return {name, data: mData} }); return {