Skip to content

Commit

Permalink
Finish the migration to the new MeasurementData encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 16, 2024
1 parent 86858c7 commit 6a841b0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 27 deletions.
36 changes: 12 additions & 24 deletions src/backend/compare/db-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function collateMeasurements(
const runSettings = new Map<string, RunSettings>();
const criteria = new Map<string, CriterionData>();

let lastInvocation = 0;
let lastTrialId = -1;
let lastMeasurements: Measurements | null = null;

// the data here needs to be sorted by
// runId, expId, trialId, criterion, invocation, iteration
Expand Down Expand Up @@ -81,7 +81,7 @@ export function collateMeasurements(

if (
lastMeasurements === null ||
!isSameInvocation(row, lastMeasurements, lastInvocation, lastTrialId)
!isSameTrial(row, lastMeasurements, lastTrialId)
) {
const benchResult = findOrConstructProcessedResult(forSuiteByBench, row);

Expand All @@ -93,21 +93,18 @@ export function collateMeasurements(
forSuiteByBench
);

// We don't store the invocation number anymore
// I think this is fine, we don't really need it.
// We just need to distinguish iterations, but their ordering
// doesn't have any particular meaning.
// If we should need it for statistical analysis of inter-invocation
// effects, we may need to re-introduce it.
lastValues = [];
m.values.push(lastValues);
lastInvocation = row.invocation;
lastMeasurements = m;
lastTrialId = row.trialid;
}

// adjusted to be zero-based
lastValues[row.iteration - 1] = row.value;
// We don't store the invocation number anymore, since we combine
// data from different experiments and trials.
// I think this is fine, we don't really need it.
// We just need to distinguish iterations, but their ordering
// doesn't have any particular meaning.
// If we should need it for statistical analysis of inter-invocation
// effects, we may need to re-introduce it.
lastMeasurements.values.push(row.values);
}

return sortResultsAlphabetically(byExeSuiteBench);
Expand Down Expand Up @@ -215,15 +212,6 @@ function isSameMeasurements(row: MeasurementData, m: Measurements) {
);
}

function isSameInvocation(
row: MeasurementData,
m: Measurements,
invocation: number,
trialId: number
) {
return (
invocation == row.invocation &&
trialId == row.trialid &&
isSameMeasurements(row, m)
);
function isSameTrial(row: MeasurementData, m: Measurements, trialId: number) {
return trialId == row.trialid && isSameMeasurements(row, m);
}
2 changes: 1 addition & 1 deletion src/backend/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const siteConfig = {
process.env.GITHUB_PK || 'rebenchdb.2020-08-11.private-key.pem',

canShowWarmup: (data: ValuesPossiblyMissing[]): boolean => {
return data.some((ms) => ms.length >= 5);
return data.some((ms) => ms != null && ms.length >= 5);
},
inlinePlotCriterion: 'total'
};
Expand Down
4 changes: 2 additions & 2 deletions tests/backend/compare/db-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('collateMeasurements()', () => {
});
});

describe('Needs to combine data from different trials but same runId', () => {
describe('needs to combine data from different trials but same runId', () => {
function createMeasure(
runid: number,
trialid: number,
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('collateMeasurements()', () => {
);
});

describe('Needs to combine data from different expIds but same runId', () => {
describe('needs to combine data from different expIds but same runId', () => {
function createMeasure(
expid: number,
runid: number,
Expand Down
99 changes: 99 additions & 0 deletions tests/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { convertToCurrentApi } from '../src/backend/common/api-v1.js';
import { robustPath } from '../src/backend/util.js';

import type { BenchmarkData } from '../src/shared/api.js';
import type { MeasurementData } from '../src/backend/db/types.js';
import { assert } from '../src/backend/logging.js';

export function loadLargePayload(): BenchmarkData {
const testData = JSON.parse(
Expand All @@ -17,3 +19,100 @@ export function loadLargePayloadApiV1(): any {
readFileSync(robustPath('../tests/data/large-payload.json')).toString()
);
}

export interface MeasurementDataOld {
expid: number;
runid: number;
trialid: number;
commitid: string;
bench: string;
exe: string;
suite: string;
cmdline: string;
varvalue: string | null;
cores: string | null;
inputsize: string | null;
extraargs: string | null;
invocation: number;
iteration: number;
warmup: number | null;
criterion: string;
unit: string;
value: number;
envid: number;
}

function convertMeasurementDataToCurrentApi(
oldMs: MeasurementDataOld[]
): MeasurementData[] {
const result: MeasurementData[] = [];

let lastMD: MeasurementData | null = null;
let lastExpId = -1;
let lastRunId = -1;
let lastTrialId = -1;
let lastCriterion = '';
let lastInvocation = -1;

for (const oldM of oldMs) {
if (
oldM.expid !== lastExpId ||
oldM.runid !== lastRunId ||
oldM.trialid !== lastTrialId ||
oldM.criterion !== lastCriterion ||
oldM.invocation !== lastInvocation
) {
lastMD = {
expid: oldM.expid,
runid: oldM.runid,
trialid: oldM.trialid,
commitid: oldM.commitid,
bench: oldM.bench,
exe: oldM.exe,
suite: oldM.suite,
cmdline: oldM.cmdline,
varvalue: oldM.varvalue,
cores: oldM.cores,
inputsize: oldM.inputsize,
extraargs: oldM.extraargs,
invocation: oldM.invocation,
warmup: oldM.warmup,
criterion: oldM.criterion,
unit: oldM.unit,
values: [],
envid: oldM.envid
};

result.push(lastMD);
lastExpId = oldM.expid;
lastRunId = oldM.runid;
lastTrialId = oldM.trialid;
lastCriterion = oldM.criterion;
lastInvocation = oldM.invocation;
}
assert(lastMD!.values[oldM.iteration - 1] == null, 'iteration already set');
lastMD!.values[oldM.iteration - 1] = oldM.value;
}

return result;
}

export function loadCompareViewJsSomPayload(): MeasurementData[] {
const testData = JSON.parse(
readFileSync(
robustPath('../tests/data/compare-view-data-jssom.json')
).toString()
).results;

return convertMeasurementDataToCurrentApi(testData);
}

export function loadCompareViewTSomPayload(): MeasurementData[] {
const testData = JSON.parse(
readFileSync(
robustPath('../tests/data/compare-view-data-trufflesom.json')
).toString()
).results;

return convertMeasurementDataToCurrentApi(testData);
}

0 comments on commit 6a841b0

Please sign in to comment.