1 | declare module "perf_hooks" {
|
2 | import { AsyncResource } from "async_hooks";
|
3 |
|
4 | interface PerformanceEntry {
|
5 | /**
|
6 | * The total number of milliseconds elapsed for this entry.
|
7 | * This value will not be meaningful for all Performance Entry types.
|
8 | */
|
9 | readonly duration: number;
|
10 |
|
11 | /**
|
12 | * The name of the performance entry.
|
13 | */
|
14 | readonly name: string;
|
15 |
|
16 | /**
|
17 | * The high resolution millisecond timestamp marking the starting time of the Performance Entry.
|
18 | */
|
19 | readonly startTime: number;
|
20 |
|
21 | /**
|
22 | * The type of the performance entry.
|
23 | * Currently it may be one of: 'node', 'mark', 'measure', 'gc', or 'function'.
|
24 | */
|
25 | readonly entryType: string;
|
26 |
|
27 | /**
|
28 | * When performanceEntry.entryType is equal to 'gc', the performance.kind property identifies
|
29 | * the type of garbage collection operation that occurred.
|
30 | * The value may be one of perf_hooks.constants.
|
31 | */
|
32 | readonly kind?: number;
|
33 | }
|
34 |
|
35 | interface PerformanceNodeTiming extends PerformanceEntry {
|
36 | /**
|
37 | * The high resolution millisecond timestamp at which the Node.js process completed bootstrap.
|
38 | */
|
39 | readonly bootstrapComplete: number;
|
40 |
|
41 | /**
|
42 | * The high resolution millisecond timestamp at which cluster processing ended.
|
43 | */
|
44 | readonly clusterSetupEnd: number;
|
45 |
|
46 | /**
|
47 | * The high resolution millisecond timestamp at which cluster processing started.
|
48 | */
|
49 | readonly clusterSetupStart: number;
|
50 |
|
51 | /**
|
52 | * The high resolution millisecond timestamp at which the Node.js event loop exited.
|
53 | */
|
54 | readonly loopExit: number;
|
55 |
|
56 | /**
|
57 | * The high resolution millisecond timestamp at which the Node.js event loop started.
|
58 | */
|
59 | readonly loopStart: number;
|
60 |
|
61 | /**
|
62 | * The high resolution millisecond timestamp at which main module load ended.
|
63 | */
|
64 | readonly moduleLoadEnd: number;
|
65 |
|
66 | /**
|
67 | * The high resolution millisecond timestamp at which main module load started.
|
68 | */
|
69 | readonly moduleLoadStart: number;
|
70 |
|
71 | /**
|
72 | * The high resolution millisecond timestamp at which the Node.js process was initialized.
|
73 | */
|
74 | readonly nodeStart: number;
|
75 |
|
76 | /**
|
77 | * The high resolution millisecond timestamp at which preload module load ended.
|
78 | */
|
79 | readonly preloadModuleLoadEnd: number;
|
80 |
|
81 | /**
|
82 | * The high resolution millisecond timestamp at which preload module load started.
|
83 | */
|
84 | readonly preloadModuleLoadStart: number;
|
85 |
|
86 | /**
|
87 | * The high resolution millisecond timestamp at which third_party_main processing ended.
|
88 | */
|
89 | readonly thirdPartyMainEnd: number;
|
90 |
|
91 | /**
|
92 | * The high resolution millisecond timestamp at which third_party_main processing started.
|
93 | */
|
94 | readonly thirdPartyMainStart: number;
|
95 |
|
96 | /**
|
97 | * The high resolution millisecond timestamp at which the V8 platform was initialized.
|
98 | */
|
99 | readonly v8Start: number;
|
100 | }
|
101 |
|
102 | interface Performance {
|
103 | /**
|
104 | * If name is not provided, removes all PerformanceFunction objects from the Performance Timeline.
|
105 | * If name is provided, removes entries with name.
|
106 | * @param name
|
107 | */
|
108 | clearFunctions(name?: string): void;
|
109 |
|
110 | /**
|
111 | * If name is not provided, removes all PerformanceMark objects from the Performance Timeline.
|
112 | * If name is provided, removes only the named mark.
|
113 | * @param name
|
114 | */
|
115 | clearMarks(name?: string): void;
|
116 |
|
117 | /**
|
118 | * If name is not provided, removes all PerformanceMeasure objects from the Performance Timeline.
|
119 | * If name is provided, removes only objects whose performanceEntry.name matches name.
|
120 | */
|
121 | clearMeasures(name?: string): void;
|
122 |
|
123 | /**
|
124 | * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime.
|
125 | * @return list of all PerformanceEntry objects
|
126 | */
|
127 | getEntries(): PerformanceEntry[];
|
128 |
|
129 | /**
|
130 | * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
|
131 | * whose performanceEntry.name is equal to name, and optionally, whose performanceEntry.entryType is equal to type.
|
132 | * @param name
|
133 | * @param type
|
134 | * @return list of all PerformanceEntry objects
|
135 | */
|
136 | getEntriesByName(name: string, type?: string): PerformanceEntry[];
|
137 |
|
138 | /**
|
139 | * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
|
140 | * whose performanceEntry.entryType is equal to type.
|
141 | * @param type
|
142 | * @return list of all PerformanceEntry objects
|
143 | */
|
144 | getEntriesByType(type: string): PerformanceEntry[];
|
145 |
|
146 | /**
|
147 | * Creates a new PerformanceMark entry in the Performance Timeline.
|
148 | * A PerformanceMark is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'mark',
|
149 | * and whose performanceEntry.duration is always 0.
|
150 | * Performance marks are used to mark specific significant moments in the Performance Timeline.
|
151 | * @param name
|
152 | */
|
153 | mark(name?: string): void;
|
154 |
|
155 | /**
|
156 | * Creates a new PerformanceMeasure entry in the Performance Timeline.
|
157 | * A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
|
158 | * and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
|
159 | *
|
160 | * The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify
|
161 | * any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist,
|
162 | * then startMark is set to timeOrigin by default.
|
163 | *
|
164 | * The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp
|
165 | * properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
|
166 | * @param name
|
167 | * @param startMark
|
168 | * @param endMark
|
169 | */
|
170 | measure(name: string, startMark: string, endMark: string): void;
|
171 |
|
172 | /**
|
173 | * An instance of the PerformanceNodeTiming class that provides performance metrics for specific Node.js operational milestones.
|
174 | */
|
175 | readonly nodeTiming: PerformanceNodeTiming;
|
176 |
|
177 | /**
|
178 | * @return the current high resolution millisecond timestamp
|
179 | */
|
180 | now(): number;
|
181 |
|
182 | /**
|
183 | * The timeOrigin specifies the high resolution millisecond timestamp from which all performance metric durations are measured.
|
184 | */
|
185 | readonly timeOrigin: number;
|
186 |
|
187 | /**
|
188 | * Wraps a function within a new function that measures the running time of the wrapped function.
|
189 | * A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.
|
190 | * @param fn
|
191 | */
|
192 | timerify<T extends (...optionalParams: any[]) => any>(fn: T): T;
|
193 | }
|
194 |
|
195 | interface PerformanceObserverEntryList {
|
196 | /**
|
197 | * @return a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime.
|
198 | */
|
199 | getEntries(): PerformanceEntry[];
|
200 |
|
201 | /**
|
202 | * @return a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
|
203 | * whose performanceEntry.name is equal to name, and optionally, whose performanceEntry.entryType is equal to type.
|
204 | */
|
205 | getEntriesByName(name: string, type?: string): PerformanceEntry[];
|
206 |
|
207 | /**
|
208 | * @return Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
|
209 | * whose performanceEntry.entryType is equal to type.
|
210 | */
|
211 | getEntriesByType(type: string): PerformanceEntry[];
|
212 | }
|
213 |
|
214 | type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void;
|
215 |
|
216 | class PerformanceObserver extends AsyncResource {
|
217 | constructor(callback: PerformanceObserverCallback);
|
218 |
|
219 | /**
|
220 | * Disconnects the PerformanceObserver instance from all notifications.
|
221 | */
|
222 | disconnect(): void;
|
223 |
|
224 | /**
|
225 | * Subscribes the PerformanceObserver instance to notifications of new PerformanceEntry instances identified by options.entryTypes.
|
226 | * When options.buffered is false, the callback will be invoked once for every PerformanceEntry instance.
|
227 | * Property buffered defaults to false.
|
228 | * @param options
|
229 | */
|
230 | observe(options: { entryTypes: string[], buffered?: boolean }): void;
|
231 | }
|
232 |
|
233 | namespace constants {
|
234 | const NODE_PERFORMANCE_GC_MAJOR: number;
|
235 | const NODE_PERFORMANCE_GC_MINOR: number;
|
236 | const NODE_PERFORMANCE_GC_INCREMENTAL: number;
|
237 | const NODE_PERFORMANCE_GC_WEAKCB: number;
|
238 | }
|
239 |
|
240 | const performance: Performance;
|
241 |
|
242 | interface EventLoopMonitorOptions {
|
243 | /**
|
244 | * The sampling rate in milliseconds.
|
245 | * Must be greater than zero.
|
246 | * @default 10
|
247 | */
|
248 | resolution?: number;
|
249 | }
|
250 |
|
251 | interface EventLoopDelayMonitor {
|
252 | /**
|
253 | * Enables the event loop delay sample timer. Returns `true` if the timer was started, `false` if it was already started.
|
254 | */
|
255 | enable(): boolean;
|
256 | /**
|
257 | * Disables the event loop delay sample timer. Returns `true` if the timer was stopped, `false` if it was already stopped.
|
258 | */
|
259 | disable(): boolean;
|
260 |
|
261 | /**
|
262 | * Resets the collected histogram data.
|
263 | */
|
264 | reset(): void;
|
265 |
|
266 | /**
|
267 | * Returns the value at the given percentile.
|
268 | * @param percentile A percentile value between 1 and 100.
|
269 | */
|
270 | percentile(percentile: number): number;
|
271 |
|
272 | /**
|
273 | * A `Map` object detailing the accumulated percentile distribution.
|
274 | */
|
275 | readonly percentiles: Map<number, number>;
|
276 |
|
277 | /**
|
278 | * The number of times the event loop delay exceeded the maximum 1 hour eventloop delay threshold.
|
279 | */
|
280 | readonly exceeds: number;
|
281 |
|
282 | /**
|
283 | * The minimum recorded event loop delay.
|
284 | */
|
285 | readonly min: number;
|
286 |
|
287 | /**
|
288 | * The maximum recorded event loop delay.
|
289 | */
|
290 | readonly max: number;
|
291 |
|
292 | /**
|
293 | * The mean of the recorded event loop delays.
|
294 | */
|
295 | readonly mean: number;
|
296 |
|
297 | /**
|
298 | * The standard deviation of the recorded event loop delays.
|
299 | */
|
300 | readonly stddev: number;
|
301 | }
|
302 |
|
303 | function monitorEventLoopDelay(options?: EventLoopMonitorOptions): EventLoopDelayMonitor;
|
304 | }
|