Skip to content

Commit c45d91f

Browse files
author
John Doe
committed
refactor: docs
1 parent 6b2d6cd commit c45d91f

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

packages/utils/src/perf-hooks.d.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,191 @@ import type { DetailPayloadWithDevtools } from './lib/user-timing-extensibility-
22

33
export {};
44

5+
/**
6+
* Type definitions extending Node.js perf_hooks module to enable Chrome DevTools UserTiming Extensibility API.
7+
*
8+
* The `detail` property allows custom payloads to be attached to performance marks and measures,
9+
* which are then accessible in Chrome DevTools and visualized in as custom tracks right under UserTiming.
10+
* This enables richer performance instrumentation with structured data that DevTools can display.
11+
*/
512
declare module 'node:perf_hooks' {
13+
/**
14+
* Extends the base PerformanceEntry interface with optional custom detail payload.
15+
*
16+
* The detail property enables Chrome DevTools UserTiming Extensibility API by allowing
17+
* structured data to be attached to performance entries for enhanced debugging visualization.
18+
* This augmentation only ensures the payload is preserved and visible to DevTools.
19+
*
20+
* @example
21+
* ```typescript
22+
* // Preserved entries with entry.detail
23+
* const entry = performance.getEntriesByType('mark').at(0);
24+
* ```
25+
*/
626
interface PerformanceEntry {
27+
/** Custom payload accessible in Chrome DevTools for enhanced performance analysis. */
728
readonly detail?: DetailPayloadWithDevtools;
829
}
930

31+
/**
32+
* Represents a performance mark entry with custom detail support for DevTools extensibility.
33+
*
34+
* Mark entries with detail payloads enable Chrome DevTools to display additional context
35+
* and structured data alongside the mark in the Performance tab. Markers create vertical
36+
* lines that span all tracks and appear at the top of the timeline.
37+
*
38+
* @example
39+
* ```typescript
40+
* // Preserved mark entries with entry.detail
41+
* const entry = performance.getEntriesByType('mark').at(0);
42+
* ```
43+
*/
1044
interface MarkEntry extends PerformanceMark {
1145
readonly entryType: 'mark';
46+
/** Custom payload displayed in Chrome DevTools for enhanced mark visualization. */
1247
readonly detail?: DetailPayloadWithDevtools;
1348
}
1449

50+
/**
51+
* Represents a performance measure entry with custom detail support for DevTools extensibility.
52+
*
53+
* Measure entries with detail payloads allow Chrome DevTools to show additional metadata
54+
* and context information alongside the measured performance duration. Track entries appear
55+
* in custom tracks below the main UserTiming track.
56+
*
57+
* @example
58+
* ```typescript
59+
* // Preserved measure entries with entry.detail
60+
* const entry = performance.getEntriesByType('measure').at(0);
61+
* ```
62+
*/
1563
interface MeasureEntry extends PerformanceMeasure {
1664
readonly entryType: 'measure';
65+
/** Custom payload displayed in Chrome DevTools for enhanced measure visualization. */
1766
readonly detail?: DetailPayloadWithDevtools;
1867
}
1968

69+
/**
70+
* Extends Node.js PerformanceMark to include the custom detail payload support.
71+
*
72+
* This interface ensures that performance marks created through the extended API
73+
* have access to the `detail` property for Chrome DevTools UserTiming Extensibility.
74+
*/
2075
interface PerformanceMark extends PerformanceEntry {}
76+
77+
/**
78+
* Extends Node.js PerformanceMeasure to include the custom detail payload support.
79+
*
80+
* This interface ensures that performance measures created through the extended API
81+
* have access to the `detail` property for Chrome DevTools UserTiming Extensibility.
82+
*/
2183
interface PerformanceMeasure extends PerformanceEntry {}
2284

85+
/**
86+
* Options for creating performance marks with custom detail payload for DevTools integration.
87+
*
88+
* The detail property enables attaching structured data that Chrome DevTools can display
89+
* alongside the mark, providing richer debugging context.
90+
*
91+
* @example
92+
* ```typescript
93+
* // Options include detail property
94+
* const options: PerformanceMarkOptions = { detail: { devtools: {} } };
95+
* ```
96+
*/
2397
export interface PerformanceMarkOptions {
98+
/** Custom payload that will be accessible in Chrome DevTools UserTiming visualization. */
2499
detail?: DetailPayloadWithDevtools;
25100
startTime?: DOMHighResTimeStamp;
26101
}
27102

103+
/**
104+
* Options for creating performance measures with custom detail payload for DevTools integration.
105+
*
106+
* The detail property allows attaching metadata that Chrome DevTools will display
107+
* with the measure, enabling better performance analysis and debugging.
108+
*
109+
* @example
110+
* ```typescript
111+
* // Options include detail property
112+
* const options: PerformanceMeasureOptions = { detail: { devtools: {} } };
113+
* ```
114+
*/
28115
export interface PerformanceMeasureOptions {
116+
/** Custom payload that will be accessible in Chrome DevTools UserTiming visualization. */
29117
detail?: DetailPayloadWithDevtools;
30118
start?: string | number;
31119
end?: string | number;
32120
duration?: number;
33121
}
34122

123+
/**
124+
* Extended performance observer entry list with typed entry retrieval.
125+
*/
35126
export interface PerformanceObserverEntryList {
36127
getEntriesByType: (type: EntryType) => PerformanceEntry[];
37128
}
38129

130+
/**
131+
* Extended performance object with Chrome DevTools UserTiming Extensibility API support.
132+
*
133+
* Enables creating performance marks and measures with custom detail payloads that are
134+
* displayed in Chrome DevTools, providing enhanced debugging and performance analysis capabilities.
135+
*/
39136
const performance: {
137+
/**
138+
* Creates a performance mark with optional custom detail payload for DevTools visualization.
139+
*
140+
* The detail payload will be accessible in Chrome DevTools Performance tab,
141+
* enabling richer debugging context for the mark.
142+
*
143+
* @example
144+
* ```typescript
145+
* // Accepts detail options
146+
* performance.mark('checkpoint', { detail: { devtools: {} } });
147+
* ```
148+
*
149+
* @param name - The name of the mark displayed in DevTools
150+
* @param options - Optional configuration including detail payload for DevTools
151+
* @returns The created performance mark with DevTools-compatible detail
152+
*/
40153
mark: (name: string, options?: PerformanceMarkOptions) => PerformanceMark;
41154

155+
/**
156+
* Creates a performance measure with optional custom detail payload for DevTools visualization.
157+
*
158+
* The detail payload enables Chrome DevTools to display additional metadata
159+
* alongside the measured performance duration for enhanced analysis.
160+
*
161+
* @example
162+
* ```typescript
163+
* // Accepts detail options
164+
* performance.measure('task', { detail: { devtools: {} } });
165+
* ```
166+
*
167+
* @param name - The name of the measure displayed in DevTools
168+
* @param startOrOptions - Start mark name/number or full options object with DevTools detail
169+
* @param end - End mark name/number (when startOrOptions is not options object)
170+
* @returns The created performance measure with DevTools-compatible detail
171+
*/
42172
measure: (
43173
name: string,
44174
startOrOptions?: string | number | PerformanceMeasureOptions,
45175
end?: string | number,
46176
) => PerformanceMeasure;
47177

178+
/**
179+
* Retrieves performance entries of the specified type, including DevTools detail payloads.
180+
*
181+
* @example
182+
* ```typescript
183+
* // Returns entries with preserved entry.detail
184+
* const entry = performance.getEntriesByType('mark').at(0);
185+
* ```
186+
*
187+
* @param type - The entry type to filter by ('mark' or 'measure')
188+
* @returns Array of performance entries with DevTools detail payloads
189+
*/
48190
getEntriesByType: (type: EntryType) => PerformanceEntry[];
49191
};
50192
}

0 commit comments

Comments
 (0)