Skip to content

Commit 8bdb530

Browse files
committed
cleanup
1 parent 9e17ddd commit 8bdb530

File tree

3 files changed

+109
-34
lines changed

3 files changed

+109
-34
lines changed

JetStream.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ a.button {
312312
background-image: none;
313313
}
314314

315+
315316
.benchmark-done h3, .benchmark-done h4, .benchmark-done .result, .benchmark-done label {
316317
background-color: transparent;
317318
background-image: none;
@@ -322,6 +323,16 @@ a.button {
322323
user-select: text;
323324
}
324325

326+
.benchmark-error h4, .benchmark-error .result, .benchmark-error label {
327+
color: #ff8686;
328+
background-color: #ff8686;
329+
background-image: none;
330+
}
331+
332+
.benchmark-error h3 {
333+
color: #ff8686;
334+
}
335+
325336
.benchmark h3 {
326337
font-weight: 400;
327338
font-size: 1.6rem;

JetStreamDriver.js

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class Driver {
240240
constructor() {
241241
this.isReady = false;
242242
this.isDone = false;
243-
this.incrementalResults = [];
243+
this.errors = [];
244244
this.benchmarks = [];
245245
this.blobDataCache = { };
246246
this.loadCache = { };
@@ -276,21 +276,14 @@ class Driver {
276276
try {
277277
await benchmark.run();
278278
} catch(e) {
279-
JetStream.reportError(benchmark);
279+
this.reportError(benchmark, e);
280280
throw e;
281281
}
282282

283283
benchmark.updateUIAfterRun();
284284
console.log(benchmark.name)
285285

286286
if (isInBrowser) {
287-
this.incrementalResults.push({
288-
name: benchmark.name,
289-
results: {
290-
Score: benchmark.score,
291-
...benchmark.subScores(),
292-
}
293-
});
294287
const cache = JetStream.blobDataCache;
295288
for (const file of benchmark.plan.files) {
296289
const blobData = cache[file];
@@ -345,19 +338,14 @@ class Driver {
345338
this.reportScoreToRunBenchmarkRunner();
346339
this.dumpJSONResultsIfNeeded();
347340
this.isDone = true;
341+
348342
if (isInBrowser) {
349343
globalThis.dispatchEvent(new CustomEvent("JetStreamDone", {
350-
detail: this.resultsObject()
344+
detail: this.resultsObjectNew()
351345
}));
352346
}
353347
}
354348

355-
drainIncrementalResults() {
356-
const currentIncrementalResults = this.incrementalResults;
357-
this.incrementalResults = [];
358-
return currentIncrementalResults
359-
}
360-
361349
runCode(string)
362350
{
363351
if (!isInBrowser) {
@@ -455,16 +443,31 @@ class Driver {
455443
});
456444
}
457445

458-
reportError(benchmark)
446+
reportError(benchmark, error)
459447
{
448+
this.pushError(benchmark.name, error);
449+
460450
if (!isInBrowser)
461451
return;
462452

463-
for (const id of benchmark.scoreIdentifiers())
453+
for (const id of benchmark.scoreIdentifiers()) {
464454
document.getElementById(id).innerHTML = "error";
455+
const benchmarkResultsUI = document.getElementById(`benchmark-${benchmark.name}`);
456+
benchmarkResultsUI.classList.remove("benchmark-running");
457+
benchmarkResultsUI.classList.add("benchmark-error");
458+
}
459+
}
460+
461+
pushError(name, error) {
462+
this.errors.push({
463+
benchmark: name,
464+
error: error.toString(),
465+
stack: error.stack
466+
});
465467
}
466468

467469
async initialize() {
470+
window.addEventListener("error", (e) => this.pushError(benchmark, e.error));
468471
await this.prefetchResourcesForBrowser();
469472
await this.fetchResources();
470473
this.prepareToRun();
@@ -525,16 +528,43 @@ class Driver {
525528
}
526529
}
527530

528-
resultsObject()
531+
resultsObject(newStyle = false) {
532+
if (newStyle)
533+
return this.resultsObjectNew();
534+
return this.resultsObjectOld();
535+
}
536+
537+
resultsObjectNew() {
538+
const results = {__proto__: null};
539+
for (const benchmark of this.benchmarks) {
540+
if (!benchmark.isDone)
541+
continue;
542+
results[benchmark.name] = {
543+
Score: benchmark.score,
544+
...benchmark.subScores(),
545+
546+
};
547+
}
548+
return results;
549+
}
550+
551+
552+
resultsObjectOld()
529553
{
530-
let results = {};
554+
let testResults = {};
531555
for (const benchmark of this.benchmarks) {
532556
const subResults = {}
533557
const subScores = benchmark.subScores();
534558
for (const name in subScores) {
535-
subResults[name] = {"metrics": {"Time": {"current": [toTimeValue(subScores[name])]}}};
559+
subResults[name] = {
560+
"metrics": {
561+
"Time": {
562+
"current": [toTimeValue(subScores[name])]
563+
}
564+
}
565+
};
536566
}
537-
results[benchmark.name] = {
567+
testResults[benchmark.name] = {
538568
"metrics" : {
539569
"Score" : {"current" : [benchmark.score]},
540570
"Time": ["Geometric"],
@@ -543,9 +573,15 @@ class Driver {
543573
};
544574
}
545575

546-
results = {"JetStream3.0": {"metrics" : {"Score" : ["Geometric"]}, "tests" : results}};
576+
const results = {
577+
"JetStream3.0": {
578+
"metrics" : {
579+
"Score" : ["Geometric"]
580+
},
581+
"tests" : testResults
582+
}
583+
};
547584
return results;
548-
549585
}
550586

551587
resultsJSON()
@@ -595,10 +631,13 @@ class Benchmark {
595631
this.scripts = null;
596632

597633
this._resourcesPromise = null;
634+
this._isDone = false;
598635
}
599636

600637
get name() { return this.plan.name; }
601638

639+
get isDone() { return this._isDone; }
640+
602641
get runnerCode() {
603642
return `
604643
let __benchmark = new Benchmark(${this.iterations});
@@ -660,6 +699,8 @@ class Benchmark {
660699
}
661700

662701
async run() {
702+
if (this.isDone)
703+
throw new Error(`Cannot run Benchmark ${this.name} twice`);
663704
let code;
664705
if (isInBrowser)
665706
code = "";
@@ -777,6 +818,7 @@ class Benchmark {
777818
const results = await promise;
778819

779820
this.endTime = performance.now();
821+
this._isDone = true;
780822

781823
if (RAMification) {
782824
const memoryFootprint = MemoryFootprint();

tests/run.mjs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ async function testEnd2End() {
9898
console.error(e);
9999
throw e;
100100
} finally {
101+
driver.close();
101102
driver.quit();
102103
server.close();
103104
}
@@ -110,32 +111,53 @@ async function benchmarkResults(driver) {
110111
globalThis.JetStream.start();
111112
callback();
112113
});
113-
await new Promise(resolve => pollIncrementalResults(driver, resolve));
114-
const resultString = await driver.executeScript(() => {
115-
return JSON.stringify(globalThis.JetStream.resultsObject());
114+
115+
await new Promise((resolve, reject) => pollResultsUntilDone(driver, resolve, reject));
116+
const resultsJSON = await driver.executeScript(() => {
117+
return globalThis.JetStream.resultsJSON();
116118
});
117-
return JSON.parse(resultString);
119+
return JSON.parse(resultsJSON);
120+
}
121+
122+
class JetStreamTestError extends Error {
123+
constructor(errors) {
124+
super(`Tests failed: ${errors.map(e => e.name).join(", ")}`)
125+
this.errors = errors
126+
}
127+
118128
}
119129

120130
const UPDATE_INTERVAL = 250;
121-
async function pollIncrementalResults(driver, resolve) {
131+
async function pollResultsUntilDone(driver, resolve, reject) {
132+
const previousResults = new Set();
122133
const intervalId = setInterval(async function logResult() {
123-
const {done, results} = await driver.executeScript(() => {
134+
const {done, errors, resultsJSON} = await driver.executeScript(() => {
124135
return {
125136
done: globalThis.JetStream.isDone,
126-
results: JSON.stringify(globalThis.JetStream.drainIncrementalResults()),
137+
errors: globalThis.JetStream.errors,
138+
resultsJSON: JSON.stringify(globalThis.JetStream.resultsObjectNew()),
127139
};
128140
});
129-
JSON.parse(results).forEach(logIncrementalResult);
141+
if (errors.length) {
142+
clearInterval(intervalId);
143+
reject(new JetStreamTestError(errors));
144+
}
145+
logIncrementalResult(previousResults, JSON.parse(resultsJSON))
130146
if (done) {
131147
clearInterval(intervalId);
132148
resolve()
133149
}
134150
}, UPDATE_INTERVAL)
135151
}
136152

137-
function logIncrementalResult(benchmarkResult) {
138-
console.log(benchmarkResult.name, benchmarkResult.results)
153+
function logIncrementalResult(previousResults, benchmarkResults) {
154+
console.log(benchmarkResults)
155+
for (const [testName, testResults] of Object.entries(benchmarkResults)) {
156+
if (previousResults.has(testName))
157+
continue;
158+
console.log(testName, testResults);
159+
previousResults.add(testName);
160+
}
139161
}
140162

141163
setImmediate(testEnd2End);

0 commit comments

Comments
 (0)