Skip to content

Commit a0ec399

Browse files
committed
feat(autobench): make metrics more regular; run more benchmarks
1 parent 4f60df1 commit a0ec399

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

packages/swingset-runner/autobench

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/sh
2-
set -e
3-
for suite in exchangeBenchmark; do
2+
for suite in exchangeBenchmark pingPongBenchmark swapBenchmark; do
43
echo "Autobenching suite $suite ..."
54
test ! -f demo/$suite/prepareContracts.js || node -r esm demo/$suite/prepareContracts.js
5+
echo '{}' > benchstats.json || continue
66
node --expose-gc -r esm bin/runner --init --benchmark 100 --statsfile benchstats.json --config demo/$suite/swingset.json run -- --quiet --prime
77
node -r esm src/push-metrics.js $suite benchstats.json
88
done

packages/swingset-runner/src/push-metrics.js

+56-50
Original file line numberDiff line numberDiff line change
@@ -81,84 +81,90 @@ function generateCommonMetrics(obj, phaseLabels) {
8181
return metrics;
8282
}
8383

84+
function makePropMetrics(metricName, headerSpecs) {
85+
return Object.fromEntries(
86+
headerSpecs.map(([prop, ...args]) => [
87+
prop,
88+
promHeader(metricName[prop], ...args),
89+
]),
90+
);
91+
}
92+
8493
function generateMetricsFromPrimeData(data, labels = undefined) {
85-
let metrics = '';
94+
const metricName = {
95+
up: 'stat_up',
96+
down: 'stat_down',
97+
max: 'stat_max',
98+
value: 'stat_value',
99+
perCrank: 'stat_per_crank',
100+
};
101+
const propMetrics = makePropMetrics(metricName, [
102+
['up', 'counter', `Number of increments`],
103+
['down', 'counter', `Number of decrements`],
104+
['max', 'gauge', `Maximum value`],
105+
['value', 'gauge', 'Latest value'],
106+
['perCrank', 'gauge', `Autobench value per crank`],
107+
]);
108+
86109
const todo = new Set(Object.keys(data));
87-
for (const { metricType, key, name, description } of KERNEL_STATS_METRICS) {
110+
for (const { key, name } of KERNEL_STATS_METRICS) {
88111
if (!(key in data)) {
89112
// eslint-disable-next-line no-continue
90113
continue;
91114
}
92115
todo.delete(key);
93-
if ('value' in data[key]) {
94-
metrics += promHeader(name, metricType, description);
95-
metrics += promValue(name, data[key].value, labels);
96-
}
97-
if ('up' in data[key]) {
98-
const nm = `${name}_up`;
99-
metrics += promHeader(
100-
nm,
101-
'counter',
102-
`${description} (number of increments)`,
103-
);
104-
metrics += promValue(nm, data[key].up, labels);
105-
}
106-
if ('down' in data[key]) {
107-
const nm = `${name}_down`;
108-
metrics += promHeader(
109-
nm,
110-
'counter',
111-
`${description} (number of decrements)`,
112-
);
113-
metrics += promValue(nm, data[key].down, labels);
114-
}
115-
if ('max' in data[key]) {
116-
const nm = `${name}_max`;
117-
metrics += promHeader(nm, 'gauge', `${description} (maximum value)`);
118-
metrics += promValue(nm, data[key].max, labels);
119-
}
120-
if ('perCrank' in data[key]) {
121-
const nm = `${name}_per_crank`;
122-
metrics += promHeader(nm, 'gauge', `${description} (value per crank)`);
123-
metrics += promValue(nm, data[key].perCrank, labels);
116+
const statLabels = [...labels, ['stat', name]];
117+
118+
for (const prop of Object.keys(propMetrics)) {
119+
if (prop in data[key]) {
120+
propMetrics[prop] += promValue(
121+
metricName[prop],
122+
data[key][prop],
123+
statLabels,
124+
);
125+
}
124126
}
125127
}
126128

127129
for (const key of todo.keys()) {
128130
console.warn(`Unrecognized prime data property ${key}`);
129131
}
130-
return metrics;
132+
return Object.values(propMetrics).join('');
131133
}
132134

133135
function generateMetricsFromBenchmarkData(data, labels = undefined) {
134-
let metrics = '';
136+
const metricName = {
137+
delta: 'stat_delta',
138+
deltaPerRound: 'stat_delta_per_round',
139+
};
140+
const propMetrics = makePropMetrics(metricName, [
141+
['delta', 'gauge', `Autobench benchmark delta`],
142+
['deltaPerRound', 'gauge', `Autobench benchmark delta per round`],
143+
]);
144+
135145
const todo = new Set(Object.keys(data));
136-
for (const { key, name, description } of KERNEL_STATS_METRICS) {
146+
for (const { key, name } of KERNEL_STATS_METRICS) {
137147
if (!(key in data)) {
138148
// eslint-disable-next-line no-continue
139149
continue;
140150
}
141151
todo.delete(key);
142-
if ('delta' in data[key]) {
143-
const nm = `${name}_delta`;
144-
metrics += promHeader(nm, 'gauge', `${description} benchmark delta`);
145-
metrics += promValue(nm, data[key].delta, labels);
146-
}
147-
if ('deltaPerRound' in data[key]) {
148-
const nm = `${name}_delta_per_round`;
149-
metrics += promHeader(
150-
nm,
151-
'gauge',
152-
`${description} benchmark delta per round`,
153-
);
154-
metrics += promValue(nm, data[key].deltaPerRound, labels);
152+
const statLabels = [...labels, ['stat', name]];
153+
for (const prop of Object.keys(propMetrics)) {
154+
if (prop in data[key]) {
155+
propMetrics[prop] += promValue(
156+
metricName[prop],
157+
data[key][prop],
158+
statLabels,
159+
);
160+
}
155161
}
156162
}
157163

158164
for (const key of todo.keys()) {
159165
console.warn(`Unrecognized benchmark data property ${key}`);
160166
}
161-
return metrics;
167+
return Object.values(propMetrics).join('');
162168
}
163169

164170
function generateMetricsFromBenchStats(benchStats, labels = []) {

0 commit comments

Comments
 (0)