Skip to content

Commit c071bd5

Browse files
committedFeb 22, 2022
doc: add missing api entries on performance
PR-URL: nodejs#42018 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent 0ab4a1c commit c071bd5

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
 

‎doc/api/perf_hooks.md

+81
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ added: v8.5.0
5555
If `name` is not provided, removes all `PerformanceMark` objects from the
5656
Performance Timeline. If `name` is provided, removes only the named mark.
5757

58+
### `performance.clearMeasures([name])`
59+
60+
<!-- YAML
61+
added: v16.7.0
62+
-->
63+
64+
* `name` {string}
65+
66+
If `name` is not provided, removes all `PerformanceMeasure` objects from the
67+
Performance Timeline. If `name` is provided, removes only the named mark.
68+
5869
### `performance.eventLoopUtilization([utilization1[, utilization2]])`
5970

6071
<!-- YAML
@@ -118,6 +129,47 @@ Passing in a user-defined object instead of the result of a previous call to
118129
`eventLoopUtilization()` will lead to undefined behavior. The return values
119130
are not guaranteed to reflect any correct state of the event loop.
120131

132+
### `performance.getEntries()`
133+
134+
<!-- YAML
135+
added: v16.7.0
136+
-->
137+
138+
* Returns: {PerformanceEntry\[]}
139+
140+
Returns a list of `PerformanceEntry` objects in chronological order with
141+
respect to `performanceEntry.startTime`. If you are only interested in
142+
performance entries of certain types or that have certain names, see
143+
`performance.getEntriesByType()` and `performance.getEntriesByName()`.
144+
145+
### `performance.getEntriesByName(name[, type])`
146+
147+
<!-- YAML
148+
added: v16.7.0
149+
-->
150+
151+
* `name` {string}
152+
* `type` {string}
153+
* Returns: {PerformanceEntry\[]}
154+
155+
Returns a list of `PerformanceEntry` objects in chronological order
156+
with respect to `performanceEntry.startTime` whose `performanceEntry.name` is
157+
equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to
158+
`type`.
159+
160+
### `performance.getEntriesByType(type)`
161+
162+
<!-- YAML
163+
added: v16.7.0
164+
-->
165+
166+
* `type` {string}
167+
* Returns: {PerformanceEntry\[]}
168+
169+
Returns a list of `PerformanceEntry` objects in chronological order
170+
with respect to `performanceEntry.startTime` whose `performanceEntry.entryType`
171+
is equal to `type`.
172+
121173
### `performance.mark([name[, options]])`
122174

123175
<!-- YAML
@@ -140,6 +192,12 @@ Creates a new `PerformanceMark` entry in the Performance Timeline. A
140192
`performanceEntry.duration` is always `0`. Performance marks are used
141193
to mark specific significant moments in the Performance Timeline.
142194

195+
The created `PerformanceMark` entry is put in the global Performance Timeline
196+
and can be queried with `performance.getEntries`,
197+
`performance.getEntriesByName`, and `performance.getEntriesByType`. When the
198+
observation is performed, the entries should be cleared from the global
199+
Performance Timeline manually with `performance.clearMarks`.
200+
143201
### `performance.measure(name[, startMarkOrOptions[, endMark]])`
144202

145203
<!-- YAML
@@ -183,6 +241,12 @@ in the Performance Timeline or any of the timestamp properties provided by the
183241
if no parameter is passed, otherwise if the named `endMark` does not exist, an
184242
error will be thrown.
185243

244+
The created `PerformanceMeasure` entry is put in the global Performance Timeline
245+
and can be queried with `performance.getEntries`,
246+
`performance.getEntriesByName`, and `performance.getEntriesByType`. When the
247+
observation is performed, the entries should be cleared from the global
248+
Performance Timeline manually with `performance.clearMeasures`.
249+
186250
### `performance.nodeTiming`
187251

188252
<!-- YAML
@@ -258,6 +322,9 @@ const wrapped = performance.timerify(someFunction);
258322

259323
const obs = new PerformanceObserver((list) => {
260324
console.log(list.getEntries()[0].duration);
325+
326+
performance.clearMarks();
327+
performance.clearMeasures();
261328
obs.disconnect();
262329
});
263330
obs.observe({ entryTypes: ['function'] });
@@ -591,6 +658,9 @@ const {
591658

592659
const obs = new PerformanceObserver((list, observer) => {
593660
console.log(list.getEntries());
661+
662+
performance.clearMarks();
663+
performance.clearMeasures();
594664
observer.disconnect();
595665
});
596666
obs.observe({ entryTypes: ['mark'], buffered: true });
@@ -706,6 +776,9 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
706776
* }
707777
* ]
708778
*/
779+
780+
performance.clearMarks();
781+
performance.clearMeasures();
709782
observer.disconnect();
710783
});
711784
obs.observe({ type: 'mark' });
@@ -761,6 +834,9 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
761834
* ]
762835
*/
763836
console.log(perfObserverList.getEntriesByName('test', 'measure')); // []
837+
838+
performance.clearMarks();
839+
performance.clearMeasures();
764840
observer.disconnect();
765841
});
766842
obs.observe({ entryTypes: ['mark', 'measure'] });
@@ -806,6 +882,8 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
806882
* }
807883
* ]
808884
*/
885+
performance.clearMarks();
886+
performance.clearMeasures();
809887
observer.disconnect();
810888
});
811889
obs.observe({ type: 'mark' });
@@ -1155,6 +1233,7 @@ hook.enable();
11551233
const obs = new PerformanceObserver((list, observer) => {
11561234
console.log(list.getEntries()[0]);
11571235
performance.clearMarks();
1236+
performance.clearMeasures();
11581237
observer.disconnect();
11591238
});
11601239
obs.observe({ entryTypes: ['measure'], buffered: true });
@@ -1188,6 +1267,8 @@ const obs = new PerformanceObserver((list) => {
11881267
entries.forEach((entry) => {
11891268
console.log(`require('${entry[0]}')`, entry.duration);
11901269
});
1270+
performance.clearMarks();
1271+
performance.clearMeasures();
11911272
obs.disconnect();
11921273
});
11931274
obs.observe({ entryTypes: ['function'], buffered: true });

0 commit comments

Comments
 (0)
Please sign in to comment.