Skip to content

Commit

Permalink
lib: add toJSON to PerformanceMeasure
Browse files Browse the repository at this point in the history
PR-URL: #53603
Refs: #53570
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
theanarkh authored Jun 29, 2024
1 parent d65b170 commit 7771025
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/internal/perf/usertiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-performance-measure-detail.js
Original file line number Diff line number Diff line change
@@ -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',
});

0 comments on commit 7771025

Please sign in to comment.