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 | * 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 event loop exited.
|
44 | * If the event loop has not yet exited, the property has the value of -1.
|
45 | * It can only have a value of not -1 in a handler of the 'exit' event.
|
46 | */
|
47 | readonly loopExit: number;
|
48 |
|
49 | /**
|
50 | * The high resolution millisecond timestamp at which the Node.js event loop started.
|
51 | * 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.
|
52 | */
|
53 | readonly loopStart: number;
|
54 |
|
55 | /**
|
56 | * The high resolution millisecond timestamp at which the Node.js process was initialized.
|
57 | */
|
58 | readonly nodeStart: number;
|
59 |
|
60 | /**
|
61 | * The high resolution millisecond timestamp at which the V8 platform was initialized.
|
62 | */
|
63 | readonly v8Start: number;
|
64 | }
|
65 |
|
66 | interface Performance {
|
67 | /**
|
68 | * If name is not provided, removes all PerformanceMark objects from the Performance Timeline.
|
69 | * If name is provided, removes only the named mark.
|
70 | * @param name
|
71 | */
|
72 | clearMarks(name?: string): void;
|
73 |
|
74 | /**
|
75 | * Creates a new PerformanceMark entry in the Performance Timeline.
|
76 | * A PerformanceMark is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'mark',
|
77 | * and whose performanceEntry.duration is always 0.
|
78 | * Performance marks are used to mark specific significant moments in the Performance Timeline.
|
79 | * @param name
|
80 | */
|
81 | mark(name?: string): void;
|
82 |
|
83 | /**
|
84 | * Creates a new PerformanceMeasure entry in the Performance Timeline.
|
85 | * A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
|
86 | * and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
|
87 | *
|
88 | * The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify
|
89 | * any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist,
|
90 | * then startMark is set to timeOrigin by default.
|
91 | *
|
92 | * The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp
|
93 | * properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
|
94 | * @param name
|
95 | * @param startMark
|
96 | * @param endMark
|
97 | */
|
98 | measure(name: string, startMark: string, endMark: string): void;
|
99 |
|
100 | /**
|
101 | * An instance of the PerformanceNodeTiming class that provides performance metrics for specific Node.js operational milestones.
|
102 | */
|
103 | readonly nodeTiming: PerformanceNodeTiming;
|
104 |
|
105 | /**
|
106 | * @return the current high resolution millisecond timestamp
|
107 | */
|
108 | now(): number;
|
109 |
|
110 | /**
|
111 | * The timeOrigin specifies the high resolution millisecond timestamp from which all performance metric durations are measured.
|
112 | */
|
113 | readonly timeOrigin: number;
|
114 |
|
115 | /**
|
116 | * Wraps a function within a new function that measures the running time of the wrapped function.
|
117 | * A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.
|
118 | * @param fn
|
119 | */
|
120 | timerify<T extends (...optionalParams: any[]) => any>(fn: T): T;
|
121 | }
|
122 |
|
123 | interface PerformanceObserverEntryList {
|
124 | /**
|
125 | * @return a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime.
|
126 | */
|
127 | getEntries(): PerformanceEntry[];
|
128 |
|
129 | /**
|
130 | * @return a list of 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 | */
|
133 | getEntriesByName(name: string, type?: string): PerformanceEntry[];
|
134 |
|
135 | /**
|
136 | * @return Returns a list of PerformanceEntry objects in chronological order with respect to performanceEntry.startTime
|
137 | * whose performanceEntry.entryType is equal to type.
|
138 | */
|
139 | getEntriesByType(type: string): PerformanceEntry[];
|
140 | }
|
141 |
|
142 | type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void;
|
143 |
|
144 | class PerformanceObserver extends AsyncResource {
|
145 | constructor(callback: PerformanceObserverCallback);
|
146 |
|
147 | /**
|
148 | * Disconnects the PerformanceObserver instance from all notifications.
|
149 | */
|
150 | disconnect(): void;
|
151 |
|
152 | /**
|
153 | * Subscribes the PerformanceObserver instance to notifications of new PerformanceEntry instances identified by options.entryTypes.
|
154 | * When options.buffered is false, the callback will be invoked once for every PerformanceEntry instance.
|
155 | * Property buffered defaults to false.
|
156 | * @param options
|
157 | */
|
158 | observe(options: { entryTypes: ReadonlyArray<string>, buffered?: boolean }): void;
|
159 | }
|
160 |
|
161 | namespace constants {
|
162 | const NODE_PERFORMANCE_GC_MAJOR: number;
|
163 | const NODE_PERFORMANCE_GC_MINOR: number;
|
164 | const NODE_PERFORMANCE_GC_INCREMENTAL: number;
|
165 | const NODE_PERFORMANCE_GC_WEAKCB: number;
|
166 | }
|
167 |
|
168 | const performance: Performance;
|
169 | }
|