node/test/fixtures/wpt/user-timing/mark-l3.any.js
legendecas 062f8e3730
perf_hooks: web performance timeline compliance
All API introduced in this PR are compliant with web
[performance-timeline](https://w3c.github.io/performance-timeline)
spec. "performance-timeline" is listed as supported web spec in the doc
https://nodejs.org/docs/latest/api/perf_hooks.html#perf_hooks_performance_measurement_apis.

Changes summary:
1. Add new supported wpt test subsets: user-timing and
  performance-timeline.
2. Add support for `Performance.getEntries`,
  `Performance.getEntriesByName` and `Performance.getEntriesByType`
  to synchronously fetch buffered performance entries. This means
  the user should invoke `Performance.clearMarks` and
  `Performance.clearMeasures` to clear buffered entries to prevent from
  those entries been kept alive forever.
3. Add support (again after https://github.com/nodejs/node/pull/37136)
  for `buffered` flags for `PerformanceObserver`.
3. Fixes `PerformanceMark` and `PerformanceMeasure` wpt compliance
  issues.
4. Only user-created performance entries will be buffered globally. This
  behavior should be compliant with
  https://w3c.github.io/timing-entrytypes-registry/#registry.

With the new ability to fetch user-created performance entries
synchronously, the issues raised in
https://github.com/nodejs/diagnostics/issues/464#issuecomment-861920116
could also be fixed.

PR-URL: https://github.com/nodejs/node/pull/39297
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-07-25 23:43:31 +08:00

39 lines
2 KiB
JavaScript

// META: script=resources/user-timing-helper.js
async_test(function (t) {
let mark_entries = [];
const expected_entries =
[{ entryType: "mark", name: "mark1", detail: null},
{ entryType: "mark", name: "mark2", detail: null},
{ entryType: "mark", name: "mark3", detail: null},
{ entryType: "mark", name: "mark4", detail: null},
{ entryType: "mark", name: "mark5", detail: null},
{ entryType: "mark", name: "mark6", detail: {}},
{ entryType: "mark", name: "mark7", detail: {info: 'abc'}},
{ entryType: "mark", name: "mark8", detail: null, startTime: 234.56},
{ entryType: "mark", name: "mark9", detail: {count: 3}, startTime: 345.67}];
const observer = new PerformanceObserver(
t.step_func(function (entryList, obs) {
mark_entries =
mark_entries.concat(entryList.getEntries());
if (mark_entries.length >= expected_entries.length) {
checkEntries(mark_entries, expected_entries);
observer.disconnect();
t.done();
}
})
);
self.performance.clearMarks();
observer.observe({entryTypes: ["mark"]});
const returned_entries = [];
returned_entries.push(self.performance.mark("mark1"));
returned_entries.push(self.performance.mark("mark2", undefined));
returned_entries.push(self.performance.mark("mark3", null));
returned_entries.push(self.performance.mark("mark4", {}));
returned_entries.push(self.performance.mark("mark5", {detail: null}));
returned_entries.push(self.performance.mark("mark6", {detail: {}}));
returned_entries.push(self.performance.mark("mark7", {detail: {info: 'abc'}}));
returned_entries.push(self.performance.mark("mark8", {startTime: 234.56}));
returned_entries.push(self.performance.mark("mark9", {detail: {count: 3}, startTime: 345.67}));
checkEntries(returned_entries, expected_entries);
}, "mark entries' detail and startTime are customizable.");