Skip to content

Commit

Permalink
feat: Add date as x-axis for charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetteadhikari committed Feb 26, 2024
1 parent 7202b6a commit 52c3ac2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
61 changes: 53 additions & 8 deletions scripts/lib/build_perf/html/measurement_chart_d3billboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,77 @@
// 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 %}
];

const convertToMinute = (time) => {
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,
},
Expand Down
6 changes: 5 additions & 1 deletion scripts/lib/build_perf/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 52c3ac2

Please sign in to comment.