Skip to content

Commit 70696d4

Browse files
authored
Add JetStreamParams (#171)
For displaying a warning about non-default params we need a way to keep track of what the default values are. We can reuse the existing code from Speedometer which does exactly that. - Copy params.js from Speedometer - Implement more uniform params parsing for browser (URLSearchParams) and cli (Map from parsed arguments) - Acces params/settings via global JetStreamParams - Expose both JetStreamParams and DefaultJetStreamParams making it east to see if we're running with non-default params
1 parent 358d6b4 commit 70696d4

File tree

5 files changed

+299
-133
lines changed

5 files changed

+299
-133
lines changed

JetStreamDriver.js

Lines changed: 31 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,7 @@ const measureTotalTimeAsSubtest = false; // Once we move to preloading all resou
3030
const defaultIterationCount = 120;
3131
const defaultWorstCaseCount = 4;
3232

33-
globalThis.performance ??= Date;
34-
globalThis.RAMification ??= false;
35-
globalThis.testIterationCount ??= undefined;
36-
globalThis.testIterationCountMap ??= new Map();
37-
globalThis.testWorstCaseCount ??= undefined;
38-
globalThis.testWorstCaseCountMap ??= new Map();
39-
globalThis.dumpJSONResults ??= false;
40-
globalThis.testList ??= undefined;
41-
globalThis.startDelay ??= undefined;
42-
globalThis.shouldReport ??= false;
43-
globalThis.prefetchResources ??= true;
44-
45-
function getIntParam(urlParams, key) {
46-
const rawValue = urlParams.get(key);
47-
const value = parseInt(rawValue);
48-
if (value <= 0)
49-
throw new Error(`Expected positive value for ${key}, but got ${rawValue}`);
50-
return value;
51-
}
52-
53-
function getBoolParam(urlParams, key) {
54-
const rawValue = urlParams.get(key).toLowerCase()
55-
return !(rawValue === "false" || rawValue === "0")
56-
}
57-
58-
function getTestListParam(urlParams, key) {
59-
if (globalThis.testList?.length)
60-
throw new Error(`Overriding previous testList=${globalThis.testList.join()} with ${key} url-parameter.`);
61-
return urlParams.getAll(key);
62-
}
63-
64-
if (typeof(URLSearchParams) !== "undefined") {
65-
const urlParameters = new URLSearchParams(window.location.search);
66-
if (urlParameters.has("report"))
67-
globalThis.shouldReport = urlParameters.get("report").toLowerCase() == "true";
68-
if (urlParameters.has("startDelay"))
69-
globalThis.startDelay = getIntParam(urlParameters, "startDelay");
70-
if (globalThis.shouldReport && !globalThis.startDelay)
71-
globalThis.startDelay = 4000;
72-
if (urlParameters.has("tag"))
73-
globalThis.testList = getTestListParam(urlParameters, "tag");
74-
if (urlParameters.has("test"))
75-
globalThis.testList = getTestListParam(urlParameters, "test");
76-
if (urlParameters.has("iterationCount"))
77-
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
78-
if (urlParameters.has("worstCaseCount"))
79-
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
80-
if (urlParameters.has("prefetchResources"))
81-
globalThis.prefetchResources = getBoolParam(urlParameters, "prefetchResources");
82-
}
83-
84-
if (!globalThis.prefetchResources)
33+
if (!JetStreamParams.prefetchResources)
8534
console.warn("Disabling resource prefetching!");
8635

8736
// Used for the promise representing the current benchmark run.
@@ -110,20 +59,20 @@ function displayCategoryScores() {
11059
}
11160

11261
function getIterationCount(plan) {
113-
if (testIterationCountMap.has(plan.name))
114-
return testIterationCountMap.get(plan.name);
115-
if (globalThis.testIterationCount)
116-
return globalThis.testIterationCount;
62+
if (JetStreamParams.testIterationCountMap.has(plan.name))
63+
return JetStreamParams.testIterationCountMap.get(plan.name);
64+
if (JetStreamParams.testIterationCount)
65+
return JetStreamParams.testIterationCount;
11766
if (plan.iterations)
11867
return plan.iterations;
11968
return defaultIterationCount;
12069
}
12170

12271
function getWorstCaseCount(plan) {
123-
if (testWorstCaseCountMap.has(plan.name))
124-
return testWorstCaseCountMap.get(plan.name);
125-
if (globalThis.testWorstCaseCount)
126-
return globalThis.testWorstCaseCount;
72+
if (JetStreamParams.testWorstCaseCountMap.has(plan.name))
73+
return JetStreamParams.testWorstCaseCountMap.get(plan.name);
74+
if (JetStreamParams.testWorstCaseCount)
75+
return JetStreamParams.testWorstCaseCount;
12776
if (plan.worstCaseCount)
12877
return plan.worstCaseCount;
12978
return defaultWorstCaseCount;
@@ -201,7 +150,7 @@ class ShellFileLoader {
201150
// share common code.
202151
load(url) {
203152
console.assert(!isInBrowser);
204-
if (!globalThis.prefetchResources)
153+
if (!JetStreamParams.prefetchResources)
205154
return `load("${url}");`
206155

207156
if (this.requests.has(url)) {
@@ -240,7 +189,7 @@ class Driver {
240189
if (isInBrowser) {
241190
statusElement = document.getElementById("status");
242191
statusElement.innerHTML = `<label>Running...</label>`;
243-
} else if (!dumpJSONResults)
192+
} else if (!JetStreamParams.dumpJSONResults)
244193
console.log("Starting JetStream3");
245194

246195
performance.mark("update-ui-start");
@@ -260,7 +209,7 @@ class Driver {
260209
performance.mark("update-ui");
261210
benchmark.updateUIAfterRun();
262211

263-
if (isInBrowser && globalThis.prefetchResources) {
212+
if (isInBrowser && JetStreamParams.prefetchResources) {
264213
const cache = JetStream.blobDataCache;
265214
for (const file of benchmark.files) {
266215
const blobData = cache[file];
@@ -276,7 +225,7 @@ class Driver {
276225
if (measureTotalTimeAsSubtest) {
277226
if (isInBrowser)
278227
document.getElementById("benchmark-total-time-score").innerHTML = uiFriendlyNumber(totalTime);
279-
else if (!dumpJSONResults)
228+
else if (!JetStreamParams.dumpJSONResults)
280229
console.log("Total time:", uiFriendlyNumber(totalTime));
281230
allScores.push(totalTime);
282231
}
@@ -314,7 +263,7 @@ class Driver {
314263
if (showScoreDetails)
315264
displayCategoryScores();
316265
statusElement.innerHTML = "";
317-
} else if (!dumpJSONResults) {
266+
} else if (!JetStreamParams.dumpJSONResults) {
318267
console.log("\n");
319268
for (let [category, scores] of categoryScores)
320269
console.log(`${category}: ${uiFriendlyScore(geomeanScore(scores))}`);
@@ -404,8 +353,8 @@ class Driver {
404353
this.isReady = true;
405354
if (isInBrowser) {
406355
globalThis.dispatchEvent(new Event("JetStreamReady"));
407-
if (typeof(globalThis.startDelay) !== "undefined") {
408-
setTimeout(() => this.start(), globalThis.startDelay);
356+
if (typeof(JetStreamParams.startDelay) !== "undefined") {
357+
setTimeout(() => this.start(), JetStreamParams.startDelay);
409358
}
410359
}
411360
}
@@ -510,7 +459,7 @@ class Driver {
510459

511460
dumpJSONResultsIfNeeded()
512461
{
513-
if (dumpJSONResults) {
462+
if (JetStreamParams.dumpJSONResults) {
514463
console.log("\n");
515464
console.log(this.resultsJSON());
516465
console.log("\n");
@@ -529,7 +478,7 @@ class Driver {
529478
if (!isInBrowser)
530479
return;
531480

532-
if (!globalThis.shouldReport)
481+
if (!JetStreamParams.shouldReport)
533482
return;
534483

535484
const content = this.resultsJSON();
@@ -799,17 +748,17 @@ class Benchmark {
799748
if (this.plan.deterministicRandom)
800749
code += `Math.random.__resetSeed();`;
801750

802-
if (globalThis.customPreIterationCode)
803-
code += customPreIterationCode;
751+
if (JetStreamParams.customPreIterationCode)
752+
code += JetStreamParams.customPreIterationCode;
804753

805754
return code;
806755
}
807756

808757
get postIterationCode() {
809758
let code = "";
810759

811-
if (globalThis.customPostIterationCode)
812-
code += customPostIterationCode;
760+
if (JetStreamParams.customPostIterationCode)
761+
code += JetStreamParams.customPostIterationCode;
813762

814763
return code;
815764
}
@@ -843,7 +792,7 @@ class Benchmark {
843792
} else {
844793
const cache = JetStream.blobDataCache;
845794
for (const file of this.plan.files) {
846-
scripts.addWithURL(globalThis.prefetchResources ? cache[file].blobURL : file);
795+
scripts.addWithURL(JetStreamParams.prefetchResources ? cache[file].blobURL : file);
847796
}
848797
}
849798

@@ -857,7 +806,7 @@ class Benchmark {
857806
performance.mark(this.name);
858807
this.startTime = performance.now();
859808

860-
if (RAMification)
809+
if (JetStreamParams.RAMification)
861810
resetMemoryPeak();
862811

863812
let magicFrame;
@@ -877,7 +826,7 @@ class Benchmark {
877826
this.endTime = performance.now();
878827
performance.measure(this.name, this.name);
879828

880-
if (RAMification) {
829+
if (JetStreamParams.RAMification) {
881830
const memoryFootprint = MemoryFootprint();
882831
this.currentFootprint = memoryFootprint.current;
883832
this.peakFootprint = memoryFootprint.peak;
@@ -894,7 +843,7 @@ class Benchmark {
894843

895844
async doLoadBlob(resource) {
896845
const blobData = JetStream.blobDataCache[resource];
897-
if (!globalThis.prefetchResources) {
846+
if (!JetStreamParams.prefetchResources) {
898847
blobData.blobURL = resource;
899848
return blobData;
900849
}
@@ -1062,7 +1011,7 @@ class Benchmark {
10621011
}
10631012

10641013
updateUIBeforeRun() {
1065-
if (!dumpJSONResults)
1014+
if (!JetStreamParams.dumpJSONResults)
10661015
console.log(`Running ${this.name}:`);
10671016
if (isInBrowser)
10681017
this.updateUIBeforeRunInBrowser();
@@ -1081,7 +1030,7 @@ class Benchmark {
10811030
const scoreEntries = Object.entries(this.allScores());
10821031
if (isInBrowser)
10831032
this.updateUIAfterRunInBrowser(scoreEntries);
1084-
if (dumpJSONResults)
1033+
if (JetStreamParams.dumpJSONResults)
10851034
return;
10861035
this.updateConsoleAfterRun(scoreEntries);
10871036
}
@@ -1129,7 +1078,7 @@ class Benchmark {
11291078
for (let [name, value] of scoreEntries) {
11301079
console.log(` ${name}:`, uiFriendlyScore(value));
11311080
}
1132-
if (RAMification) {
1081+
if (JetStreamParams.RAMification) {
11331082
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
11341083
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
11351084
}
@@ -2803,8 +2752,8 @@ const defaultDisabledTags = [];
28032752
if (!isInBrowser)
28042753
defaultDisabledTags.push("WorkerTests");
28052754

2806-
if (globalThis.testList?.length) {
2807-
benchmarks = processTestList(globalThis.testList);
2755+
if (JetStreamParams.testList.length) {
2756+
benchmarks = processTestList(JetStreamParams.testList);
28082757
} else {
28092758
benchmarks = findBenchmarksByTag("Default", defaultDisabledTags)
28102759
}

0 commit comments

Comments
 (0)