diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index ab109c3c04bce6..dfbbcbaf36c538 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -136,6 +136,16 @@ class PerformanceMeasure extends PerformanceEntry { validateInternalField(this, kDetail, 'PerformanceMeasure'); return this[kDetail]; } + + toJSON() { + return { + name: this.name, + entryType: this.entryType, + startTime: this.startTime, + duration: this.duration, + detail: this[kDetail], + }; + } } ObjectDefineProperties(PerformanceMeasure.prototype, { detail: kEnumerableProperty, diff --git a/test/parallel/test-performance-measure-detail.js b/test/parallel/test-performance-measure-detail.js new file mode 100644 index 00000000000000..1bfcda661f43d4 --- /dev/null +++ b/test/parallel/test-performance-measure-detail.js @@ -0,0 +1,20 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const util = require('util'); +const { performance, PerformanceObserver } = require('perf_hooks'); + +const perfObserver = new PerformanceObserver(common.mustCall((items) => { + const entries = items.getEntries(); + assert.ok(entries.length === 1); + for (const entry of entries) { + assert.ok(util.inspect(entry).includes('this is detail')); + } +})); + +perfObserver.observe({ entryTypes: ['measure'] }); + +performance.measure('sample', { + detail: 'this is detail', +});