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