File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ added: v8.5.0
4343An object that can be used to collect performance metrics from the current
4444Node.js instance. It is similar to [ ` window.performance ` ] [ ] in browsers.
4545
46+ ### ` performance.toJSON() `
47+ <!-- YAML
48+ added: REPLACEME
49+ -->
50+
51+ An object which is JSON representation of the ` performance ` object. It
52+ is similar to [ ` window.performance.toJSON ` ] [ ] in browsers.
53+
4654### ` performance.clearMarks([name]) `
4755<!-- YAML
4856added: v8.5.0
@@ -1026,3 +1034,4 @@ require('some-module');
10261034[ `process.hrtime()` ] : process.md#process_process_hrtime_time
10271035[ `timeOrigin` ] : https://w3c.github.io/hr-time/#dom-performance-timeorigin
10281036[ `window.performance` ] : https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
1037+ [ `window.performance.toJSON` ] : https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ class Performance extends EventTarget {
5959 timeOrigin : this . timeOrigin ,
6060 } , opts ) } `;
6161 }
62+
63+ toJSON ( ) {
64+ return {
65+ nodeTiming : this . nodeTiming . toJSON ( ) ,
66+ timeOrigin : this . timeOrigin ,
67+ eventLoopUtilization : this . eventLoopUtilization ( )
68+ } ;
69+ }
6270}
6371
6472class InternalPerformance extends EventTarget { }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ require ( '../common' ) ;
4+ const assert = require ( 'assert' ) ;
5+ const { performance } = require ( 'perf_hooks' ) ;
6+
7+ // Test toJSON for performance object
8+ {
9+ assert . strictEqual ( typeof performance . toJSON , 'function' ) ;
10+ const jsonObject = performance . toJSON ( ) ;
11+ assert . strictEqual ( typeof jsonObject , 'object' ) ;
12+ assert . strictEqual ( jsonObject . timeOrigin , performance . timeOrigin ) ;
13+ assert . strictEqual ( typeof jsonObject . nodeTiming , 'object' ) ;
14+ }
You can’t perform that action at this time.
0 commit comments