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
43
43
An object that can be used to collect performance metrics from the current
44
44
Node.js instance. It is similar to [ ` window.performance ` ] [ ] in browsers.
45
45
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
+
46
54
### ` performance.clearMarks([name]) `
47
55
<!-- YAML
48
56
added: v8.5.0
@@ -1026,3 +1034,4 @@ require('some-module');
1026
1034
[ `process.hrtime()` ] : process.md#process_process_hrtime_time
1027
1035
[ `timeOrigin` ] : https://w3c.github.io/hr-time/#dom-performance-timeorigin
1028
1036
[ `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 {
59
59
timeOrigin : this . timeOrigin ,
60
60
} , opts ) } `;
61
61
}
62
+
63
+ toJSON ( ) {
64
+ return {
65
+ nodeTiming : this . nodeTiming . toJSON ( ) ,
66
+ timeOrigin : this . timeOrigin ,
67
+ eventLoopUtilization : this . eventLoopUtilization ( )
68
+ } ;
69
+ }
62
70
}
63
71
64
72
class 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