From 52c3ac278f1d580180ffed4e7025bc9c6661480c Mon Sep 17 00:00:00 2001 From: Ninette Adhikari <13760198+ninetteadhikari@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:41:18 +0100 Subject: [PATCH] feat: Add date as x-axis for charts --- .../html/measurement_chart_d3billboard.html | 61 ++++++++++++++++--- scripts/lib/build_perf/report.py | 6 +- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/scripts/lib/build_perf/html/measurement_chart_d3billboard.html b/scripts/lib/build_perf/html/measurement_chart_d3billboard.html index d04abe3af1d..dbbc971cd82 100644 --- a/scripts/lib/build_perf/html/measurement_chart_d3billboard.html +++ b/scripts/lib/build_perf/html/measurement_chart_d3billboard.html @@ -2,7 +2,7 @@ // Get data const rawData = [ {% for sample in measurement.samples %} - [{{ sample.commit_num }}, {{ sample.mean.gv_value() }}], + [{{ sample.commit_num }}, {{ sample.mean.gv_value() }}, {{ sample.start_time }}], {% endfor %} ]; @@ -10,24 +10,69 @@ return time[0]*60 + time[1] + time[2]/60 + time[3]/3600; } - // Assuming the array quantities are durations in the format [hours, minutes, seconds, milliseconds] - const dataX = rawData.map(([commit, quantity]) => { + const dataX = rawData.map(([commit, value, time]) => { + // Time 0 means no date information is available and commit number is used instead + if (time > 0) { + // The Date object takes value in milliseconds rather than seconds. So to use a Unix timestamp we multiply it by 1000. + const date = new Date(time * 1000) + return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() // Adding an extra 1 for month as January starts from 0 + } return commit }); - dataX.unshift('commit'); + dataX.unshift('dateOrCommit'); - const dataY = rawData.map(([commit, quantity]) => { - return Array.isArray(quantity) ? convertToMinute(quantity) : quantity + // Assuming the array values are durations in the format [hours, minutes, seconds, milliseconds] + const dataY = rawData.map(([commit, value]) => { + return Array.isArray(value) ? convertToMinute(value) : value }); - dataY.unshift('quantity'); + dataY.unshift('value'); + + let axisFormat + // Date is saved as string in the data + if (typeof dataX[1] === 'string') { + axisFormat = { + x: { + label: { + text: "Date", + position: "outer-center" + }, + type: "timeseries", + tick: { + format: "%Y-%m-%d" + } + }, + y: { + label: { + text: "Duration (minutes)", + position: "outer-middle" + } + } + } + } else { + axisFormat = { + x: { + label: { + text: "Commit number", + position: "outer-center" + } + }, + y: { + label: { + text: "Disk size (MB)", + position: "outer-middle" + } + } + } + } // Example: https://naver.github.io/billboard.js/demo/#Chart.SimpleXYLineChart const chart = bb.generate({ data: { - x: "commit", + x: "dateOrCommit", columns: [dataX, dataY], type: "line", }, + axis: axisFormat, zoom: { enabled: true, }, diff --git a/scripts/lib/build_perf/report.py b/scripts/lib/build_perf/report.py index ab77424cc74..a4080a65c2e 100644 --- a/scripts/lib/build_perf/report.py +++ b/scripts/lib/build_perf/report.py @@ -304,15 +304,18 @@ def measurement_stats(meas, prefix=''): prefix + 'min': MeasurementVal('nan'), prefix + 'max': MeasurementVal('nan'), prefix + 'minus': MeasurementVal('nan'), - prefix + 'plus': MeasurementVal('nan')} + prefix + 'plus': MeasurementVal('nan'), + prefix + 'start_time': MeasurementVal('nan')} stats = {'name': meas['name']} if meas['type'] == 'sysres': val_cls = TimeVal values = meas['values']['elapsed_time'] + start_time = meas['values']['start_time'][0] elif meas['type'] == 'diskusage': val_cls = SizeVal values = meas['values']['size'] + start_time = 0 # No time data is available else: raise Exception("Unknown measurement type '{}'".format(meas['type'])) stats['val_cls'] = val_cls @@ -334,6 +337,7 @@ def measurement_stats(meas, prefix=''): stats[prefix + 'max'] = max_val stats[prefix + 'minus'] = val_cls(mean_val - min_val) stats[prefix + 'plus'] = val_cls(max_val - mean_val) + stats[prefix + 'start_time'] = start_time return stats