perf_hooks: use arrays to store EntryBuffers

Also order entries by startTime when calling getEntriesByType.

Fix: https://github.com/nodejs/node/issues/42004
Fix: https://github.com/nodejs/node/issues/42024

PR-URL: https://github.com/nodejs/node/pull/42032
Fixes: https://github.com/nodejs/node/issues/42004
Fixes: https://github.com/nodejs/node/issues/42024
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Xuguang Mei authored and GitHub committed 2022-02-20 22:57:31 +00:00
1 parent 30eb6784ba
commit 6abd71e2d9
3 files changed
+59 -74

No files matched your search

@@ -0,0 +1,35 @@
// This file may needs to be updated to wpt:
// https://github.com/web-platform-tests/wpt
import '../common/index.mjs';
import assert from 'assert';
import { performance } from 'perf_hooks';
import { setTimeout } from 'timers/promises';
// Order by startTime
performance.mark('one');
await setTimeout(50);
performance.mark('two');
await setTimeout(50);
performance.mark('three');
await setTimeout(50);
performance.measure('three', 'three');
await setTimeout(50);
performance.measure('two', 'two');
await setTimeout(50);
performance.measure('one', 'one');
const entries = performance.getEntriesByType('measure');
assert.deepStrictEqual(entries.map((x) => x.name), ['one', 'two', 'three']);
const allEntries = performance.getEntries();
assert.deepStrictEqual(allEntries.map((x) => x.name), ['one', 'one', 'two', 'two', 'three', 'three']);
performance.mark('a');
await setTimeout(50);
performance.measure('a', 'a');
await setTimeout(50);
performance.mark('a');
await setTimeout(50);
performance.measure('a', 'one');
const entriesByName = performance.getEntriesByName('a');
assert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']);