Projekt

Obecné

Profil

Stáhnout (11.8 KB) Statistiky
| Větev: | Revize:
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;
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;
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 cluster processing ended.
52
         */
53
        readonly clusterSetupEnd: number;
54

    
55
        /**
56
         * The high resolution millisecond timestamp at which cluster processing started.
57
         */
58
        readonly clusterSetupStart: number;
59

    
60
        /**
61
         * The high resolution millisecond timestamp at which the Node.js event loop exited.
62
         */
63
        readonly loopExit: number;
64

    
65
        /**
66
         * The high resolution millisecond timestamp at which the Node.js event loop started.
67
         */
68
        readonly loopStart: number;
69

    
70
        /**
71
         * The high resolution millisecond timestamp at which main module load ended.
72
         */
73
        readonly moduleLoadEnd: number;
74

    
75
        /**
76
         * The high resolution millisecond timestamp at which main module load started.
77
         */
78
        readonly moduleLoadStart: number;
79

    
80
        /**
81
         * The high resolution millisecond timestamp at which the Node.js process was initialized.
82
         */
83
        readonly nodeStart: number;
84

    
85
        /**
86
         * The high resolution millisecond timestamp at which preload module load ended.
87
         */
88
        readonly preloadModuleLoadEnd: number;
89

    
90
        /**
91
         * The high resolution millisecond timestamp at which preload module load started.
92
         */
93
        readonly preloadModuleLoadStart: number;
94

    
95
        /**
96
         * The high resolution millisecond timestamp at which third_party_main processing ended.
97
         */
98
        readonly thirdPartyMainEnd: number;
99

    
100
        /**
101
         * The high resolution millisecond timestamp at which third_party_main processing started.
102
         */
103
        readonly thirdPartyMainStart: number;
104

    
105
        /**
106
         * The high resolution millisecond timestamp at which the V8 platform was initialized.
107
         */
108
        readonly v8Start: number;
109
    }
110

    
111
    interface Performance {
112
        /**
113
         * If name is not provided, removes all PerformanceFunction objects from the Performance Timeline.
114
         * If name is provided, removes entries with name.
115
         * @param name
116
         */
117
        clearFunctions(name?: string): void;
118

    
119
        /**
120
         * If name is not provided, removes all PerformanceMark objects from the Performance Timeline.
121
         * If name is provided, removes only the named mark.
122
         * @param name
123
         */
124
        clearMarks(name?: string): void;
125

    
126
        /**
127
         * If name is not provided, removes all PerformanceMeasure objects from the Performance Timeline.
128
         * If name is provided, removes only objects whose performanceEntry.name matches name.
129
         */
130
        clearMeasures(name?: string): void;
131

    
132
        /**
133
         * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime.
134
         * @return list of all PerformanceEntry objects
135
         */
136
        getEntries(): PerformanceEntry[];
137

    
138
        /**
139
         * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
140
         * whose performanceEntry.name is equal to name, and optionally, whose performanceEntry.entryType is equal to type.
141
         * @param name
142
         * @param type
143
         * @return list of all PerformanceEntry objects
144
         */
145
        getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
146

    
147
        /**
148
         * Returns a list of all PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
149
         * whose performanceEntry.entryType is equal to type.
150
         * @param type
151
         * @return list of all PerformanceEntry objects
152
         */
153
        getEntriesByType(type: EntryType): PerformanceEntry[];
154

    
155
        /**
156
         * Creates a new PerformanceMark entry in the Performance Timeline.
157
         * A PerformanceMark is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'mark',
158
         * and whose performanceEntry.duration is always 0.
159
         * Performance marks are used to mark specific significant moments in the Performance Timeline.
160
         * @param name
161
         */
162
        mark(name?: string): void;
163

    
164
        /**
165
         * Creates a new PerformanceMeasure entry in the Performance Timeline.
166
         * A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
167
         * and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
168
         *
169
         * The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify
170
         * any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist,
171
         * then startMark is set to timeOrigin by default.
172
         *
173
         * The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp
174
         * properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
175
         * @param name
176
         * @param startMark
177
         * @param endMark
178
         */
179
        measure(name: string, startMark: string, endMark: string): void;
180

    
181
        /**
182
         * An instance of the PerformanceNodeTiming class that provides performance metrics for specific Node.js operational milestones.
183
         */
184
        readonly nodeTiming: PerformanceNodeTiming;
185

    
186
        /**
187
         * @return the current high resolution millisecond timestamp
188
         */
189
        now(): number;
190

    
191
        /**
192
         * The timeOrigin specifies the high resolution millisecond timestamp from which all performance metric durations are measured.
193
         */
194
        readonly timeOrigin: number;
195

    
196
        /**
197
         * Wraps a function within a new function that measures the running time of the wrapped function.
198
         * A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.
199
         * @param fn
200
         */
201
        timerify<T extends (...optionalParams: any[]) => any>(fn: T): T;
202
    }
203

    
204
    interface PerformanceObserverEntryList {
205
        /**
206
         * @return a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime.
207
         */
208
        getEntries(): PerformanceEntry[];
209

    
210
        /**
211
         * @return a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
212
         * whose performanceEntry.name is equal to name, and optionally, whose performanceEntry.entryType is equal to type.
213
         */
214
        getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
215

    
216
        /**
217
         * @return Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
218
         * whose performanceEntry.entryType is equal to type.
219
         */
220
        getEntriesByType(type: EntryType): PerformanceEntry[];
221
    }
222

    
223
    type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void;
224

    
225
    class PerformanceObserver extends AsyncResource {
226
        constructor(callback: PerformanceObserverCallback);
227

    
228
        /**
229
         * Disconnects the PerformanceObserver instance from all notifications.
230
         */
231
        disconnect(): void;
232

    
233
        /**
234
         * Subscribes the PerformanceObserver instance to notifications of new PerformanceEntry instances identified by options.entryTypes.
235
         * When options.buffered is false, the callback will be invoked once for every PerformanceEntry instance.
236
         * Property buffered defaults to false.
237
         * @param options
238
         */
239
        observe(options: { entryTypes: EntryType[]; buffered?: boolean }): void;
240
    }
241

    
242
    namespace constants {
243
        const NODE_PERFORMANCE_GC_MAJOR: number;
244
        const NODE_PERFORMANCE_GC_MINOR: number;
245
        const NODE_PERFORMANCE_GC_INCREMENTAL: number;
246
        const NODE_PERFORMANCE_GC_WEAKCB: number;
247

    
248
        const NODE_PERFORMANCE_GC_FLAGS_NO: number;
249
        const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: number;
250
        const NODE_PERFORMANCE_GC_FLAGS_FORCED: number;
251
        const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: number;
252
        const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: number;
253
        const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: number;
254
        const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: number;
255
    }
256

    
257
    const performance: Performance;
258

    
259
    interface EventLoopMonitorOptions {
260
        /**
261
         * The sampling rate in milliseconds.
262
         * Must be greater than zero.
263
         * @default 10
264
         */
265
        resolution?: number;
266
    }
267

    
268
    interface EventLoopDelayMonitor {
269
        /**
270
         * Enables the event loop delay sample timer. Returns `true` if the timer was started, `false` if it was already started.
271
         */
272
        enable(): boolean;
273
        /**
274
         * Disables the event loop delay sample timer. Returns `true` if the timer was stopped, `false` if it was already stopped.
275
         */
276
        disable(): boolean;
277

    
278
        /**
279
         * Resets the collected histogram data.
280
         */
281
        reset(): void;
282

    
283
        /**
284
         * Returns the value at the given percentile.
285
         * @param percentile A percentile value between 1 and 100.
286
         */
287
        percentile(percentile: number): number;
288

    
289
        /**
290
         * A `Map` object detailing the accumulated percentile distribution.
291
         */
292
        readonly percentiles: Map<number, number>;
293

    
294
        /**
295
         * The number of times the event loop delay exceeded the maximum 1 hour eventloop delay threshold.
296
         */
297
        readonly exceeds: number;
298

    
299
        /**
300
         * The minimum recorded event loop delay.
301
         */
302
        readonly min: number;
303

    
304
        /**
305
         * The maximum recorded event loop delay.
306
         */
307
        readonly max: number;
308

    
309
        /**
310
         * The mean of the recorded event loop delays.
311
         */
312
        readonly mean: number;
313

    
314
        /**
315
         * The standard deviation of the recorded event loop delays.
316
         */
317
        readonly stddev: number;
318
    }
319

    
320
    function monitorEventLoopDelay(options?: EventLoopMonitorOptions): EventLoopDelayMonitor;
321
}
(28-28/45)