@@ -21,6 +21,20 @@ export interface TimelineEntry {
2121 componentCount : number ;
2222}
2323
24+ export interface CommitDetail {
25+ index : number ;
26+ timestamp : number ;
27+ duration : number ;
28+ components : Array < {
29+ id : number ;
30+ displayName : string ;
31+ actualDuration : number ;
32+ selfDuration : number ;
33+ causes : RenderCause [ ] ;
34+ } > ;
35+ totalComponents : number ;
36+ }
37+
2438export class Profiler {
2539 private session : ProfilingSession | null = null ;
2640 /** Display names captured during profiling (survives unmounts) */
@@ -240,6 +254,38 @@ export class Profiler {
240254 . slice ( 0 , limit ) ;
241255 }
242256
257+ getCommitDetails ( index : number , tree : ComponentTree , limit = 10 ) : CommitDetail | null {
258+ if ( ! this . session ) return null ;
259+ if ( index < 0 || index >= this . session . commits . length ) return null ;
260+
261+ const commit = this . session . commits [ index ] ;
262+ const components : CommitDetail [ 'components' ] = [ ] ;
263+
264+ for ( const [ id , actualDuration ] of commit . fiberActualDurations ) {
265+ const selfDuration = commit . fiberSelfDurations . get ( id ) || 0 ;
266+ const desc = commit . changeDescriptions . get ( id ) ;
267+ components . push ( {
268+ id,
269+ displayName : tree . getNode ( id ) ?. displayName || this . displayNames . get ( id ) || `Component#${ id } ` ,
270+ actualDuration,
271+ selfDuration,
272+ causes : desc ? describeCauses ( desc ) : [ ] ,
273+ } ) ;
274+ }
275+
276+ components . sort ( ( a , b ) => b . selfDuration - a . selfDuration ) ;
277+
278+ const totalCount = components . length ;
279+
280+ return {
281+ index,
282+ timestamp : commit . timestamp ,
283+ duration : commit . duration ,
284+ components : limit > 0 ? components . slice ( 0 , limit ) : components ,
285+ totalComponents : totalCount ,
286+ } ;
287+ }
288+
243289 getTimeline ( limit ?: number ) : TimelineEntry [ ] {
244290 if ( ! this . session ) return [ ] ;
245291
0 commit comments