lib: add runId, fileRunId, entryFile, namePath to node:bench · nodejs/node@b32b09f · GitHub
Skip to content

Commit b32b09f

Browse files
jasnelladuh95
authored andcommitted
lib: add runId, fileRunId, entryFile, namePath to node:bench
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: #65631 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 67a7831 commit b32b09f

15 files changed

Lines changed: 440 additions & 37 deletions

‎doc/api/bench.md‎

Lines changed: 36 additions & 9 deletions

‎lib/internal/bench_runner/benchmark.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const { structuredClone } = require('internal/worker/js_transferable');
4848
const { bigint: hrtime } = process.hrtime;
4949
const kDefaultSamples = 30;
5050
const kDefaultWarmup = 0;
51+
const kEmptyNamePath = ObjectFreeze([]);
5152
const kEmptyParams = ObjectFreeze({ __proto__: null });
5253
const kEmptyTags = ObjectFreeze([]);
5354

@@ -163,10 +164,19 @@ class Suite extends AsyncResource {
163164
this.name = name;
164165
this.fn = fn;
165166
this.loc = createLocation(loc, harness.entryFile);
167+
this.isRoot = isRoot;
168+
this.fileScope = isRoot ? null :
169+
(parent.isRoot ? harness.getFileScope() : parent.fileScope);
170+
this.namePath = isRoot ? kEmptyNamePath :
171+
ObjectFreeze(getNamePath(parent, name));
172+
this.suiteId = isRoot ? null : JSONStringify([
173+
this.loc.file,
174+
this.namePath,
175+
]);
176+
this.parentId = isRoot || parent.isRoot ? null : parent.suiteId;
166177
this.only = validated.only;
167178
this.skip = validated.skip;
168179
this.tags = validated.tags;
169-
this.isRoot = isRoot;
170180
this.children = [];
171181
this.hooks = {
172182
__proto__: null,
@@ -214,17 +224,15 @@ class Bench extends AsyncResource {
214224
this.warmup = warmup;
215225
this.timeout = timeout;
216226
this.outerSignal = signal;
217-
this.namePath = getNamePath(parent, name);
227+
this.fileScope = parent.isRoot ? harness.getFileScope() : parent.fileScope;
228+
this.namePath = ObjectFreeze(getNamePath(parent, name));
218229
this.fullName = ArrayPrototypeJoin(this.namePath, ' ');
219230
this.benchId = JSONStringify([
220231
this.loc.file,
221232
this.namePath,
222233
this.params,
223234
]);
224-
this.parentId = parent.isRoot ? null : JSONStringify([
225-
this.loc.file,
226-
getNamePath(parent.parent, parent.name),
227-
]);
235+
this.parentId = parent.suiteId;
228236
this.finished = false;
229237
this.result = null;
230238
this.completion = PromiseWithResolvers();

‎lib/internal/bench_runner/cli.js‎

Lines changed: 84 additions & 6 deletions

0 commit comments

Comments
 (0)