@@ -35,17 +35,20 @@ export function extractRelevantEvents(entries: any[]) {
35
35
filteredEvents . push ( { type :'click' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur } ) ;
36
36
}
37
37
} else if ( e . name === 'CompositeLayers' && e . ph === "X" ) {
38
- if ( config . LOG_DETAILS ) console . log ( "CompositeLayers" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
38
+ if ( config . LOG_DETAILS ) console . log ( "CompositeLayers" , + e . ts , + e . ts + e . dur - click_start ) ;
39
39
filteredEvents . push ( { type :'compositelayers' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
40
40
} else if ( e . name === 'Layout' && e . ph === "X" ) {
41
- if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
41
+ if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts , + e . ts + e . dur - click_start ) ;
42
42
filteredEvents . push ( { type :'layout' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
43
43
} else if ( e . name === 'Paint' && e . ph === "X" ) {
44
- if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts + e . dur , + e . ts + e . dur - click_start ) ;
44
+ if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts , + e . ts + e . dur - click_start ) ;
45
45
filteredEvents . push ( { type :'paint' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
46
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 ) ;
47
+ if ( config . LOG_DETAILS ) console . log ( "FireAnimationFrame" , + e . ts , + e . ts - click_start ) ;
48
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 === 'UpdateLayoutTree' && e . ph === "X" ) {
50
+ if ( config . LOG_DETAILS ) console . log ( "UpdateLayoutTree" , + e . ts , + e . ts - click_start ) ;
51
+ filteredEvents . push ( { type :'updateLayoutTree' , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , evt : JSON . stringify ( e ) } ) ;
49
52
} else if ( e . name === 'RequestAnimationFrame' ) {
50
53
if ( config . LOG_DETAILS ) console . log ( "RequestAnimationFrame" , + e . ts , + e . ts - click_start , + e . ts - click_end ) ;
51
54
filteredEvents . push ( { type :'requestAnimationFrame' , ts : + e . ts , dur : 0 , end : + e . ts , evt : JSON . stringify ( e ) } ) ;
@@ -71,6 +74,70 @@ function type_eq(requiredType: string) {
71
74
return ( e : Timingresult ) => e . type === requiredType ;
72
75
}
73
76
77
+ // export async function computeResultsCPUNew(fileName: string, durationMeasurementMode: DurationMeasurementMode): Promise<number> {
78
+ // let contents = await readFile(fileName, {encoding: "utf8"});
79
+ // let traceObj = JSON.parse(contents)
80
+ // let entries = traceObj['traceEvents'];
81
+
82
+ // let clickEvents = entries.filter((e:any) => {
83
+ // return (e.name==='EventDispatch') && (e.args.data.type==="click") ;
84
+ // });
85
+ // console.log("# clickEvents", clickEvents.length);
86
+ // let click_ts = +clickEvents[0].ts;
87
+
88
+ // // let eventsBeforeClick = entries.filter((e:any) => {
89
+ // // return (e.ts< click_ts &&
90
+ // // !( (e.name=='CompositeLayers')
91
+ // // || (e.name==='RunTask')
92
+ // // || (e.name==='Layout')
93
+ // // || (e.name==='Paint')
94
+ // // || (e.name==='FireAnimationFrame')
95
+ // // || (e.name==='UpdateLayoutTree')
96
+ // // || (e.name==='RequestAnimationFrame')
97
+ // // || (e.name==='HitTest')
98
+ // // || (e.name==='ScheduleStyleRecalculation')
99
+ // // || (e.name==='EventDispatch')
100
+ // // || (e.name==='UpdateLayerTree')
101
+ // // || (e.name==='UpdateLayer')
102
+ // // || (e.name==='SetLayerTreeId')
103
+ // // || (e.name==='IntersectionObserverController::computeIntersections')
104
+ // // || (e.name==='FunctionCall')
105
+ // // || (e.name==='RasterTask')
106
+ // // || (e.name==='EventTiming')
107
+ // // ))
108
+ // // });
109
+ // // console.log("before", click_ts);
110
+ // // console.log(eventsBeforeClick);
111
+
112
+ // let eventsAfterClick = entries.filter((e:any) => {
113
+ // return !(e.ts< click_ts &&
114
+ // ( (e.name=='CompositeLayers')
115
+ // || (e.name==='RunTask')
116
+ // || (e.name==='Layout')
117
+ // || (e.name==='Paint')
118
+ // || (e.name==='FireAnimationFrame')
119
+ // || (e.name==='UpdateLayoutTree')
120
+ // || (e.name==='RequestAnimationFrame')
121
+ // || (e.name==='HitTest')
122
+ // || (e.name==='ScheduleStyleRecalculation')
123
+ // || (e.name==='EventDispatch')
124
+ // || (e.name==='UpdateLayerTree')
125
+ // || (e.name==='UpdateLayer')
126
+ // || (e.name==='SetLayerTreeId')
127
+ // || (e.name==='IntersectionObserverController::computeIntersections')
128
+ // || (e.name==='FunctionCall')
129
+ // || (e.name==='RasterTask')
130
+ // || (e.name==='EventTiming')
131
+ // ))
132
+ // });
133
+ // console.log("#events total", entries.length, "#events after click", eventsAfterClick.length);
134
+
135
+
136
+ // const tasks = new Tracelib(eventsAfterClick)
137
+ // const summary = tasks.getSummary()
138
+ // console.log("painting", summary.painting, "rendering", summary.rendering, "scripting", summary.scripting)
139
+ // return summary.painting +summary.rendering + summary.scripting;
140
+ // }
74
141
export async function computeResultsCPU ( fileName : string , durationMeasurementMode : DurationMeasurementMode ) : Promise < number > {
75
142
const perfLogEvents = ( await fetchEventsFromPerformanceLog ( fileName ) ) ;
76
143
let eventsDuringBenchmark = R . sortBy ( ( e : Timingresult ) => e . end ) ( perfLogEvents ) ;
@@ -105,44 +172,54 @@ export async function computeResultsCPU(fileName: string, durationMeasurementMod
105
172
106
173
let paints = R . filter ( ( e : Timingresult ) => e . ts > onlyUsePaintEventsAfter . end ) ( R . filter ( type_eq ( 'paint' ) ) ( eventsDuringBenchmark ) ) ;
107
174
if ( paints . length == 0 ) {
108
- console . log ( "ERROR: No paint event found" ) ;
175
+ console . log ( "ERROR: No paint event found " , fileName ) ;
109
176
throw "No paint event found" ;
110
177
}
178
+ let paint = paints [ durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ? 0 : paints . length - 1 ] ;
179
+ let duration = ( paint . end - clicks [ 0 ] . ts ) / 1000.0 ;
111
180
if ( paints . length > 1 ) {
112
- console . log ( "more than one paint event found" ) ;
181
+ console . log ( "more than one paint event found " , fileName ) ;
113
182
paints . forEach ( l => {
114
183
console . log ( "paints event" , ( l . end - click . ts ) / 1000.0 ) ;
115
184
} )
185
+ if ( durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ) {
186
+ console . log ( "IGNORING more than one paint due to FIRST_PAINT_AFTER_LAYOUT" , fileName , duration ) ;
187
+ }
116
188
}
117
- let paint = paints [ durationMeasurementMode == DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT ? 0 : paints . length - 1 ] ;
118
- let duration = ( paint . end - clicks [ 0 ] . ts ) / 1000.0 ;
119
189
console . log ( "duration" , duration ) ;
120
190
191
+ // let updateLayoutTree = R.filter((e: Timingresult) => e.ts > click.end)(R.filter(type_eq('updateLayoutTree'))(eventsDuringBenchmark));
192
+ // console.log("updateLayoutTree", updateLayoutTree.length, updateLayoutTree[0].end);
193
+
121
194
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 } ` ) ;
195
+ let fafs = R . filter ( ( e : Timingresult ) => e . ts >= click . ts && e . ts < paint . ts ) ( R . filter ( type_eq ( 'fireAnimationFrame' ) ) ( eventsDuringBenchmark ) ) ;
196
+
197
+ if ( rafs_withinClick . length > 0 && fafs . length > 0 ) {
198
+ let waitDelay = ( fafs [ 0 ] . ts - click . end ) / 1000.0 ;
199
+ if ( rafs_withinClick . length == 1 && fafs . length == 1 ) {
200
+ if ( waitDelay > 16 ) {
201
+ let ignored = false ;
202
+ for ( let e of layouts ) {
203
+ if ( e . ts < fafs [ 0 ] . ts ) {
204
+ console . log ( "IGNORING 1 raf, 1 faf, but layout before raf" , waitDelay , fileName ) ;
205
+ ignored = true ;
206
+ break ;
207
+ }
138
208
}
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` ) ;
209
+ if ( ! ignored ) {
210
+ duration = duration - waitDelay ;
211
+ console . log ( "FOUND delay for 1 raf, 1 faf, but layout before raf" , waitDelay , fileName ) ;
212
+ }
213
+ } else {
214
+ console . log ( "IGNORING delay < 16 msecs 1 raf, 1 faf " , waitDelay , fileName ) ;
142
215
}
216
+ } else if ( fafs . length == 1 ) {
217
+ throw "Unexpected situation. Did not happen in the past. One fire animation frame, but non consistent request animation frames in " + fileName ;
218
+ } else {
219
+ console . log ( `IGNORING Bad case ${ rafs_withinClick . length } raf, ${ fafs . length } faf ${ fileName } ` ) ;
220
+ }
143
221
}
144
222
145
-
146
223
return duration ;
147
224
}
148
225
@@ -241,11 +318,13 @@ async function runCPUBenchmark(framework: FrameworkData, benchmark: CPUBenchmark
241
318
}
242
319
243
320
let categories = [
321
+ "blink.user_timing" ,
244
322
"devtools.timeline" ,
245
323
'disabled-by-default-devtools.timeline' ,
246
324
] ;
247
325
// let categories = [
248
- // 'devtools.timeline',
326
+ // "loading",
327
+ // 'devtools.timeline',
249
328
// 'disabled-by-default-devtools.timeline',
250
329
// '-*',
251
330
// 'v8.execute',
0 commit comments