Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

perf_hooks.d.ts 11KB

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