Skip to content

Commit

Permalink
chore: fix the lint
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 2, 2021
1 parent 3efc212 commit a29782e
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions packages/swingset-runner/src/push-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function promValue(name, value, labels = []) {
let sep = '{';
let labelstr = '';

for (const [key, value] of labels) {
labelstr += `${sep}${key}=${JSON.stringify(value)}`;
for (const [key, lbl] of labels) {
labelstr += `${sep}${key}=${JSON.stringify(lbl)}`;
sep = ',';
}

Expand All @@ -71,32 +71,19 @@ function generateCommonMetrics(obj, phaseLabels) {
// Only write the header once.
metrics += hdr;
hdr = '';
metrics += promValue(cranks, obj[phase][key], phaseLabels[phase]);
metrics += promValue(name, obj[phase][key], phaseLabels[phase]);
}
}
}
return metrics;
}

function generateMetricsFromBenchStats(benchStats) {
const obj = JSON.parse(benchStats);
const mainLabels = [['phase', 'prime']];
const benchmarkLabels = [['phase', 'bench']];
let metrics = generateCommonMetrics(benchStats, { main: mainLabels, benchmark: benchmarkLabels });
if (obj.main) {
metrics += generateMetricsFromPrimeData(obj.main.data, mainLabels);
}
if (obj.benchmark) {
metrics += generateMetricsFromBenchmarkData(obj.benchmark.data, benchmarkLabels);
}
return metrics;
}

function generateMetricsFromPrimeData(data, labels = undefined) {
let metrics = '';
const todo = new Set(Object.keys(data));
for (const { metricType, key, name, description } of KERNEL_STATS_METRICS) {
if (!(key in data)) {
// eslint-disable-next-line no-continue
continue;
}
todo.delete(key);
Expand All @@ -106,12 +93,20 @@ function generateMetricsFromPrimeData(data, labels = undefined) {
}
if ('up' in data[key]) {
const nm = `${name}_up`;
metrics += promHeader(nm, 'counter', `${description} (number of increments)`);
metrics += promHeader(
nm,
'counter',
`${description} (number of increments)`,
);
metrics += promValue(nm, data[key].up, labels);
}
if ('down' in data[key]) {
const nm = `${name}_down`;
metrics += promHeader(nm, 'counter', `${description} (number of decrements)`);
metrics += promHeader(
nm,
'counter',
`${description} (number of decrements)`,
);
metrics += promValue(nm, data[key].down, labels);
}
if ('max' in data[key]) {
Expand All @@ -137,6 +132,7 @@ function generateMetricsFromBenchmarkData(data, labels = undefined) {
const todo = new Set(Object.keys(data));
for (const { key, name, description } of KERNEL_STATS_METRICS) {
if (!(key in data)) {
// eslint-disable-next-line no-continue
continue;
}
todo.delete(key);
Expand All @@ -147,7 +143,11 @@ function generateMetricsFromBenchmarkData(data, labels = undefined) {
}
if ('deltaPerRound' in data[key]) {
const nm = `${name}_delta_per_round`;
metrics += promHeader(nm, 'gauge', `${description} benchmark delta per round`);
metrics += promHeader(
nm,
'gauge',
`${description} benchmark delta per round`,
);
metrics += promValue(nm, data[key].deltaPerRound, labels);
}
}
Expand All @@ -158,6 +158,25 @@ function generateMetricsFromBenchmarkData(data, labels = undefined) {
return metrics;
}

function generateMetricsFromBenchStats(benchStats) {
const obj = JSON.parse(benchStats);
const mainLabels = [['phase', 'prime']];
const benchmarkLabels = [['phase', 'bench']];
let metrics = generateCommonMetrics(benchStats, {
main: mainLabels,
benchmark: benchmarkLabels,
});
if (obj.main) {
metrics += generateMetricsFromPrimeData(obj.main.data, mainLabels);
}
if (obj.benchmark) {
metrics += generateMetricsFromBenchmarkData(
obj.benchmark.data,
benchmarkLabels,
);
}
return metrics;
}
const benchStats = fs.readFileSync(benchStatsFile, 'utf-8');
const metrics = generateMetricsFromBenchStats(benchStats);

Expand All @@ -176,11 +195,16 @@ const gitCp = spawnSync('git', ['rev-parse', 'HEAD'], {
});
const revision = gitCp.stdout.trimRight();

const labels = [['revision', revision], ['suite', suite]];
const labels = [
['revision', revision],
['suite', suite],
];

// This setting of metricsGroup ensures the history is kept for other git
// commits, but reset for previous uploads of this same gitCommit or suite.
const metricsGroup = '/' + labels.flatMap((kv) => kv.map(encodeURIComponent)).join('/');
const metricsGroup = `/${labels
.flatMap(kv => kv.map(encodeURIComponent))
.join('/')}`;

const curlCp = spawnSync(
'curl',
Expand Down

0 comments on commit a29782e

Please sign in to comment.