@@ -15,61 +15,73 @@ interface TimingResult {
15
15
evt ?: any ;
16
16
}
17
17
18
- export function extractRelevantEvents ( entries : any [ ] ) {
18
+ /**
19
+ *
20
+ * @param entries
21
+ * @param startLogicEvent usually "click", but might be "pointerup" if needed
22
+ * @returns
23
+ */
24
+ export function extractRelevantEvents ( entries : any [ ] , startLogicEvent : string ) {
19
25
let filteredEvents : TimingResult [ ] = [ ] ;
20
- let click_start = 0 ;
21
- let click_end = 0 ;
26
+ let startLogicEvent_startTS = 0 ;
27
+ let startLogicEvent_endTS = 0 ;
22
28
23
29
entries . forEach ( ( x ) => {
24
30
let e = x ;
25
31
if ( config . LOG_DEBUG ) console . log ( JSON . stringify ( e ) ) ;
26
32
if ( e . name === "EventDispatch" ) {
33
+ if ( e . args . data . type === startLogicEvent ) {
34
+ if ( config . LOG_DETAILS ) console . log ( "startLogicEvent" , e . args . data . type , + e . ts ) ;
35
+ startLogicEvent_startTS = + e . ts ;
36
+ startLogicEvent_endTS = + e . ts + e . dur ;
37
+ filteredEvents . push ( { type : "startLogicEvent" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
38
+ }
27
39
if ( e . args . data . type === "click" ) {
28
- if ( config . LOG_DETAILS ) console . log ( "CLICK" , + e . ts ) ;
29
- click_start = + e . ts ;
30
- click_end = + e . ts + e . dur ;
31
40
filteredEvents . push ( { type : "click" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
32
- } else if ( e . args . data . type === "mousedown" ) {
41
+ } else if ( e . args . data . type === "mousedown" ) {
33
42
if ( config . LOG_DETAILS ) console . log ( "MOUSEDOWN" , + e . ts ) ;
34
43
filteredEvents . push ( { type : "mousedown" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
44
+ } else if ( e . args . data . type === "pointerup" ) {
45
+ if ( config . LOG_DETAILS ) console . log ( "POINTERUP" , + e . ts ) ;
46
+ filteredEvents . push ( { type : "pointerup" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
35
47
}
36
48
} else if ( e . name === "Layout" && e . ph === "X" ) {
37
- if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts , + e . ts + e . dur - click_start ) ;
49
+ if ( config . LOG_DETAILS ) console . log ( "Layout" , + e . ts , + e . ts + e . dur - startLogicEvent_startTS ) ;
38
50
filteredEvents . push ( { type : "layout" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
39
51
} else if ( e . name === "FunctionCall" && e . ph === "X" ) {
40
- if ( config . LOG_DETAILS ) console . log ( "FunctionCall" , + e . ts , + e . ts + e . dur - click_start ) ;
52
+ if ( config . LOG_DETAILS ) console . log ( "FunctionCall" , + e . ts , + e . ts + e . dur - startLogicEvent_startTS ) ;
41
53
filteredEvents . push ( { type : "functioncall" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
42
54
} else if ( e . name === "HitTest" && e . ph === "X" ) {
43
- if ( config . LOG_DETAILS ) console . log ( "HitTest" , + e . ts , + e . ts + e . dur - click_start ) ;
55
+ if ( config . LOG_DETAILS ) console . log ( "HitTest" , + e . ts , + e . ts + e . dur - startLogicEvent_startTS ) ;
44
56
filteredEvents . push ( { type : "hittest" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
45
57
} else if ( e . name === "Commit" && e . ph === "X" ) {
46
- if ( config . LOG_DETAILS ) console . log ( "COMMIT PAINT" , + e . ts , + e . ts + e . dur - click_start ) ;
58
+ if ( config . LOG_DETAILS ) console . log ( "COMMIT PAINT" , + e . ts , + e . ts + e . dur - startLogicEvent_startTS ) ;
47
59
filteredEvents . push ( { type : "commit" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
48
60
} else if ( e . name === "Paint" && e . ph === "X" ) {
49
- if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts , + e . ts + e . dur - click_start ) ;
61
+ if ( config . LOG_DETAILS ) console . log ( "PAINT" , + e . ts , + e . ts + e . dur - startLogicEvent_startTS ) ;
50
62
filteredEvents . push ( { type : "paint" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
51
63
} else if ( e . name === "FireAnimationFrame" && e . ph === "X" ) {
52
- if ( config . LOG_DETAILS ) console . log ( "FireAnimationFrame" , + e . ts , + e . ts - click_start ) ;
64
+ if ( config . LOG_DETAILS ) console . log ( "FireAnimationFrame" , + e . ts , + e . ts - startLogicEvent_startTS ) ;
53
65
filteredEvents . push ( { type : "fireAnimationFrame" , ts : + e . ts , dur : + e . dur , end : + e . ts + e . dur , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
54
66
} else if ( e . name === "TimerFire" && e . ph === "X" ) {
55
- if ( config . LOG_DETAILS ) console . log ( "TimerFire" , + e . ts , + e . ts - click_start , + e . ts - click_end ) ;
67
+ if ( config . LOG_DETAILS ) console . log ( "TimerFire" , + e . ts , + e . ts - startLogicEvent_startTS , + e . ts - startLogicEvent_endTS ) ;
56
68
filteredEvents . push ( { type : "timerFire" , ts : + e . ts , dur : 0 , end : + e . ts , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
57
69
} else if ( e . name === "RequestAnimationFrame" ) {
58
- if ( config . LOG_DETAILS ) console . log ( "RequestAnimationFrame" , + e . ts , + e . ts - click_start , + e . ts - click_end ) ;
70
+ if ( config . LOG_DETAILS ) console . log ( "RequestAnimationFrame" , + e . ts , + e . ts - startLogicEvent_startTS , + e . ts - startLogicEvent_endTS ) ;
59
71
filteredEvents . push ( { type : "requestAnimationFrame" , ts : + e . ts , dur : 0 , end : + e . ts , pid : e . pid , evt : JSON . stringify ( e ) } ) ;
60
72
}
61
73
} ) ;
62
74
return filteredEvents ;
63
75
}
64
76
65
- async function fetchEventsFromPerformanceLog ( fileName : string ) : Promise < TimingResult [ ] > {
77
+ async function fetchEventsFromPerformanceLog ( fileName : string , startLogicEventName : string ) : Promise < TimingResult [ ] > {
66
78
let timingResults : TimingResult [ ] = [ ] ;
67
79
let entries = [ ] ;
68
80
do {
69
81
let contents = await readFile ( fileName , { encoding : "utf8" } ) ;
70
82
let json = JSON . parse ( contents ) ;
71
83
let entries = json [ "traceEvents" ] ;
72
- const filteredEvents = extractRelevantEvents ( entries ) ;
84
+ const filteredEvents = extractRelevantEvents ( entries , startLogicEventName ) ;
73
85
timingResults = timingResults . concat ( filteredEvents ) ;
74
86
} while ( entries . length > 0 ) ;
75
87
return timingResults ;
@@ -158,8 +170,9 @@ function logEvents(events: TimingResult[], click: TimingResult) {
158
170
159
171
export async function computeResultsCPU (
160
172
fileName : string ,
173
+ startLogicEventName : string ,
161
174
) : Promise < CPUDurationResult > {
162
- const perfLogEvents = await fetchEventsFromPerformanceLog ( fileName ) ;
175
+ const perfLogEvents = await fetchEventsFromPerformanceLog ( fileName , startLogicEventName ) ;
163
176
let events = R . sortBy ( ( e : TimingResult ) => e . end ) ( perfLogEvents ) ;
164
177
165
178
// Find mousedown event. This is the start of the benchmark
@@ -173,9 +186,9 @@ export async function computeResultsCPU(
173
186
console . log ( "more than one mousedown event" , fileName , events ) ;
174
187
throw "at most one mousedown event is expected" ;
175
188
}
176
-
177
- // Find click event. This is the start of the benchmark
178
- let clicks = R . filter ( type_eq ( "click " ) ) ( events ) ;
189
+
190
+ // Find click event. This is the start of the benchmark. We're using the synthetic "startLogicEvent" event we've created above
191
+ let clicks = R . filter ( type_eq ( "startLogicEvent " ) ) ( events ) ;
179
192
// Invariant: There must be exactly one click event
180
193
if ( clicks . length !== 1 ) {
181
194
console . log ( "exactly one click event is expected" , fileName , events ) ;
@@ -189,7 +202,7 @@ export async function computeResultsCPU(
189
202
if ( mousedownToClick > 0 ) {
190
203
console . log ( "mousedownToClick" , mousedownToClick , fileName ) ;
191
204
}
192
- if ( mousedownToClick > 10000 ) {
205
+ if ( mousedownToClick > 5000 ) {
193
206
console . log ( "difference between mousedown and click is unusually long" , mousedownToClick , fileName ) ;
194
207
// throw "difference between mousedown and click is unusually long";
195
208
}
@@ -445,15 +458,16 @@ export async function parseCPUTrace(
445
458
benchmarkOptions : BenchmarkOptions ,
446
459
framework : FrameworkData ,
447
460
benchmarkInfo : CPUBenchmarkInfo ,
448
- plausibilityCheck : PlausibilityCheck
461
+ plausibilityCheck : PlausibilityCheck ,
462
+ startLogicEventName : string
449
463
) {
450
464
let results : CPUBenchmarkResult [ ] = [ ] ;
451
465
for ( let i = 0 ; i < benchmarkOptions . numIterationsForCPUBenchmarks + benchmarkInfo . additionalNumberOfRuns ; i ++ ) {
452
466
let trace = `${ fileNameTrace ( framework , benchmarkInfo , i , benchmarkOptions ) } ` ;
453
467
if ( fs . existsSync ( trace ) ) {
454
468
console . log ( "analyzing trace" , trace ) ;
455
469
try {
456
- let result = await computeResultsCPU ( trace ) ;
470
+ let result = await computeResultsCPU ( trace , startLogicEventName ) ;
457
471
plausibilityCheck . check ( result , trace , framework , benchmarkInfo ) ;
458
472
let resultJS = await computeResultsJS ( result , config , trace ) ;
459
473
let resultPaint = await computeResultsPaint ( result , config , trace ) ;
0 commit comments