mirror of https://github.com/nodejs/node.git
lib: add toJSON to PerformanceMeasure
PR-URL: https://github.com/nodejs/node/pull/53603 Refs: https://github.com/nodejs/node/issues/53570 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>pull/53636/head
parent
d65b17082b
commit
77710251e1
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
});
|
Loading…
Reference in New Issue