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