@@ -21,26 +21,34 @@ interface Timingresult {
2121
2222export function extractRelevantEvents ( entries : any [ ] ) {
2323 let filteredEvents : Timingresult [ ] = [ ] ;
24- let click = 0 ;
24+ let click_start = 0 ;
25+ let click_end = 0 ;
2526
2627 entries . forEach ( x => {
2728 let e = x ;
2829 if ( config . LOG_DEBUG ) console . log ( JSON . stringify ( e ) ) ;
2930 if ( e . name === 'EventDispatch' ) {
3031 if ( e . args . data . type === "click" ) {
3132 if ( config . LOG_DETAILS ) console . log ( "CLICK " , + e . ts ) ;
32- click = e . ts ;
33+ click_start = + e . ts ;
34+ click_end = + e . ts + e . dur ;
3335 filteredEvents . push ( { type :'click' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur } ) ;
3436 }
3537 } else if ( e . name === 'CompositeLayers' && e . ph === "X" ) {
36- if ( config . LOG_DETAILS ) console . log ( "CompositeLayers" , + e . ts + e . dur , + e . ts + e . dur - click ) ;
38+ if ( config . LOG_DETAILS ) console . log ( "CompositeLayers" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
3739 filteredEvents . push ( { type :'compositelayers' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
3840 } else if ( e . name === 'Layout' && e . ph === "X" ) {
39- if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts + e . dur , + e . ts + e . dur - click ) ;
41+ if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
4042 filteredEvents . push ( { type :'layout' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
4143 } else if ( e . name === 'Paint' && e . ph === "X" ) {
42- if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts + e . dur , + e . ts + e . dur - click ) ;
44+ if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
4345 filteredEvents . push ( { type :'paint' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
46+ } else if ( e . name === 'FireAnimationFrame' && e . ph === "X" ) {
47+ if ( config . LOG_DETAILS ) console . log ( "FireAnimationFrame" , + e . ts + e . dur , + e . ts - click_start ) ;
48+ filteredEvents . push ( { type :'fireAnimationFrame' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
49+ } else if ( e . name === 'RequestAnimationFrame' ) {
50+ if ( config . LOG_DETAILS ) console . log ( "RequestAnimationFrame" , + e . ts , + e . ts - click_start , + e . ts - click_end ) ;
51+ filteredEvents . push ( { type :'requestAnimationFrame' , ts : + e . ts , dur : 0 , end : + e . ts , evt : JSON . stringify ( e ) } ) ;
4452 }
4553 } ) ;
4654 return filteredEvents ;
@@ -67,7 +75,7 @@ export async function computeResultsCPU(fileName: string, durationMeasurementMod
6775 const perfLogEvents = ( await fetchEventsFromPerformanceLog ( fileName ) ) ;
6876 let eventsDuringBenchmark = R . sortBy ( ( e : Timingresult ) => e . end ) ( perfLogEvents ) ;
6977
70- // console.log("eventsDuringBenchmark ", asString( eventsDuringBenchmark) );
78+ // console.log("eventsDuringBenchmark ", eventsDuringBenchmark);
7179
7280 console . log ( "computeResultsCPU " , durationMeasurementMode )
7381
@@ -76,39 +84,65 @@ export async function computeResultsCPU(fileName: string, durationMeasurementMod
7684 console . log ( "exactly one click event is expected" , eventsDuringBenchmark ) ;
7785 throw "exactly one click event is expected" ;
7886 }
87+ let click = clicks [ 0 ] ;
7988
8089 let onlyUsePaintEventsAfter : Timingresult ;
81- let layouts = R . filter ( type_eq ( 'layout' ) ) ( eventsDuringBenchmark )
82- layouts = R . filter ( ( e : Timingresult ) => e . ts > clicks [ 0 ] . end ) ( layouts ) ;
90+ let layouts = R . filter ( ( e : Timingresult ) => e . ts > click . end ) ( R . filter ( type_eq ( 'layout' ) ) ( eventsDuringBenchmark ) )
8391 if ( durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ) {
8492 if ( layouts . length > 1 ) {
8593 console . log ( "INFO: more than one layout event found" ) ;
8694 layouts . forEach ( l => {
87- console . log ( "layout event" , l . end - clicks [ 0 ] . ts ) ;
95+ console . log ( "layout event" , l . end - click . ts ) ;
8896 } )
8997 } else if ( layouts . length == 0 ) {
9098 console . log ( "ERROR: exactly one layout event is expected" , eventsDuringBenchmark ) ;
9199 throw "exactly one layouts event is expected" ;
92100 }
93101 onlyUsePaintEventsAfter = layouts [ layouts . length - 1 ] ;
94102 } else {
95- onlyUsePaintEventsAfter = clicks [ 0 ] ;
103+ onlyUsePaintEventsAfter = click ;
96104 }
97105
98- let paints = R . filter ( type_eq ( 'paint' ) ) ( eventsDuringBenchmark ) ;
99- paints = R . filter ( ( e : Timingresult ) => e . ts > onlyUsePaintEventsAfter . end ) ( paints ) ;
106+ let paints = R . filter ( ( e : Timingresult ) => e . ts > onlyUsePaintEventsAfter . end ) ( R . filter ( type_eq ( 'paint' ) ) ( eventsDuringBenchmark ) ) ;
100107 if ( paints . length == 0 ) {
101108 console . log ( "ERROR: No paint event found" ) ;
102109 throw "No paint event found" ;
103110 }
104111 if ( paints . length > 1 ) {
105112 console . log ( "more than one paint event found" ) ;
106113 paints . forEach ( l => {
107- console . log ( "paints event" , ( l . end - clicks [ 0 ] . ts ) / 1000.0 ) ;
114+ console . log ( "paints event" , ( l . end - click . ts ) / 1000.0 ) ;
108115 } )
109116 }
110- let duration = ( paints [ durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ? 0 : paints . length - 1 ] . end - clicks [ 0 ] . ts ) / 1000.0 ;
117+ let paint = paints [ durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ? 0 : paints . length - 1 ] ;
118+ let duration = ( paint . end - clicks [ 0 ] . ts ) / 1000.0 ;
111119 console . log ( "duration" , duration ) ;
120+
121+ let rafs_withinClick = R . filter ( ( e : Timingresult ) => e . ts >= click . ts && e . ts <= click . end ) ( R . filter ( type_eq ( 'requestAnimationFrame' ) ) ( eventsDuringBenchmark ) ) ;
122+ if ( rafs_withinClick . length = 1 ) {
123+ let fafs = R . filter ( ( e : Timingresult ) => e . ts >= click . ts && e . ts < paint . ts ) ( R . filter ( type_eq ( 'fireAnimationFrame' ) ) ( eventsDuringBenchmark ) ) ;
124+ if ( layouts . length > 0 ) {
125+ fafs = R . filter ( ( e : Timingresult ) => e . end < layouts [ 0 ] . ts ) ( fafs ) ;
126+ }
127+ if ( paints . length > 0 ) {
128+ fafs = R . filter ( ( e : Timingresult ) => e . end < paints [ 0 ] . ts ) ( fafs ) ;
129+ }
130+ if ( fafs . length != 1 ) {
131+ console . log ( `*#* there were ${ fafs . length } fafs` ) ;
132+ }
133+ if ( fafs . length > 0 && rafs_withinClick . length > 0 ) {
134+ let waitDelay = ( fafs [ 0 ] . ts - click . end ) / 1000.0 ;
135+ duration = duration - waitDelay ;
136+ if ( waitDelay > 16 ) {
137+ console . log ( `*#* WARNING: duration of raf delay is longer than expected: ${ waitDelay } ` ) ;
138+ }
139+ console . log ( `*#* there was one faf and one raf with a idle duration of ${ waitDelay } . New duration ${ duration } ` ) ;
140+ } else if ( fafs . length != 0 && rafs_withinClick . length == 1 ) {
141+ console . log ( `*#* ERROR: unexpected raf faf pattern: ${ fafs . length } fafs and ${ rafs_withinClick . length } rafs` ) ;
142+ }
143+ }
144+
145+
112146 return duration ;
113147}
114148
0 commit comments