Skip to content

Commit 0d58a0d

Browse files
committed
allow other events than click to be the starting point for the duration measurement (e.g. pointerup)
1 parent 70b5de9 commit 0d58a0d

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

webdriver-ts/src/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface FrameworkData {
9090
useRowShadowRoot: boolean;
9191
shadowRootName: string | undefined;
9292
buttonsInShadowRoot: boolean;
93+
startLogicEventName: string;
9394
issues: number[];
9495
frameworkHomeURL: string;
9596
}
@@ -108,6 +109,7 @@ export interface FrameworkInformation {
108109
versions?: { [key: string]: string };
109110
frameworkVersionString: string;
110111
frameworkHomeURL: string;
112+
startLogicEventName: string;
111113
}
112114

113115
export interface MatchPredicate {
@@ -163,6 +165,7 @@ export async function initializeFrameworks(
163165
buttonsInShadowRoot: !!frameworkVersionInformation.buttonsInShadowRoot,
164166
issues: (frameworkVersionInformation.issues ?? []).map(Number),
165167
frameworkHomeURL: frameworkVersionInformation.frameworkHomeURL ?? "",
168+
startLogicEventName: frameworkVersionInformation.startLogicEventName
166169
});
167170
}
168171
}

webdriver-ts/src/forkedBenchmarkRunnerPlaywright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async function runCPUBenchmark(
113113
if (throttleCPU) {
114114
await client.send("Emulation.setCPUThrottlingRate", { rate: 1 });
115115
}
116-
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions));
116+
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions), framework.startLogicEventName);
117117
let resultScript = await computeResultsJS(
118118
result,
119119
config,

webdriver-ts/src/forkedBenchmarkRunnerPuppeteer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function runCPUBenchmark(
151151
// console.log("afterBenchmark", m1, m2);
152152
// let result = (m2.TaskDuration - m1.TaskDuration)*1000.0; //await computeResultsCPU(fileNameTrace(framework, benchmark, i), benchmarkOptions, framework, benchmark, warnings, benchmarkOptions.batchSize);
153153
try {
154-
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions));
154+
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions), framework.startLogicEventName);
155155
let resultScript = await computeResultsJS(
156156
result,
157157
config,

webdriver-ts/src/forkedBenchmarkRunnerWebdriverCDP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async function runCPUBenchmark(
162162
await cdpConnection.execute("Tracing.end", {});
163163
await p;
164164

165-
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions));
165+
let result = await computeResultsCPU(fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions), framework.startLogicEventName);
166166
let resultScript = await computeResultsJS(
167167
result,
168168
config,

webdriver-ts/src/parseTrace.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ async function debugSingle() {
1212
// const trace = `traces/alpine-v3.12.0-keyed_07_create10k_0.json`;
1313
// const trace = `traces/arrowjs-v1.0.0-alpha.9-keyed_07_create10k_0.json`;
1414
// const trace = `traces/better-react-v1.1.3-keyed_04_select1k_1.json`;
15-
const trace = `traces/openui5-v1.120.0-keyed_02_replace1k_0.json`;
15+
const trace = `traces/targetjs-v1.0.137-keyed_09_clear1k_x8_3.json`;
1616
// const trace = `traces/vanillajs-keyed_01_run1k_0.json`;
1717
console.log("analyzing trace", trace);
18-
const cpuTrace = await computeResultsCPU(trace);
18+
const cpuTrace = await computeResultsCPU(trace, "click");
1919
console.log(trace, cpuTrace);
2020
values.push(cpuTrace.duration);
2121
let resultJS = await computeResultsJS(cpuTrace, config, trace);
@@ -54,12 +54,12 @@ async function debugAll() {
5454
let plausibilityCheck = new PlausibilityCheck();
5555
for (let framework of frameworks) {
5656
for (let benchmarkInfo of cpuCPUBenchmarks) {
57-
await parseCPUTrace(benchmarkOptions, framework, benchmarkInfo, plausibilityCheck);
57+
await parseCPUTrace(benchmarkOptions, framework, benchmarkInfo, plausibilityCheck, framework.startLogicEventName);
5858
}
5959
}
6060
plausibilityCheck.print();
6161
}
6262

63-
debugSingle()
63+
debugAll()
6464
.then(() => console.log("done"))
6565
.catch((error) => console.log(error));

webdriver-ts/src/timeline.ts

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,73 @@ interface TimingResult {
1515
evt?: any;
1616
}
1717

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) {
1925
let filteredEvents: TimingResult[] = [];
20-
let click_start = 0;
21-
let click_end = 0;
26+
let startLogicEvent_startTS = 0;
27+
let startLogicEvent_endTS = 0;
2228

2329
entries.forEach((x) => {
2430
let e = x;
2531
if (config.LOG_DEBUG) console.log(JSON.stringify(e));
2632
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+
}
2739
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;
3140
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") {
3342
if (config.LOG_DETAILS) console.log("MOUSEDOWN", +e.ts);
3443
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) });
3547
}
3648
} 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);
3850
filteredEvents.push({ type: "layout", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
3951
} 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);
4153
filteredEvents.push({ type: "functioncall", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
4254
} 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);
4456
filteredEvents.push({ type: "hittest", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
4557
} 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);
4759
filteredEvents.push({ type: "commit", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
4860
} 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);
5062
filteredEvents.push({ type: "paint", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
5163
} 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);
5365
filteredEvents.push({ type: "fireAnimationFrame", ts: +e.ts, dur: +e.dur, end: +e.ts + e.dur, pid: e.pid, evt: JSON.stringify(e) });
5466
} 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);
5668
filteredEvents.push({ type: "timerFire", ts: +e.ts, dur: 0, end: +e.ts, pid: e.pid, evt: JSON.stringify(e) });
5769
} 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);
5971
filteredEvents.push({ type: "requestAnimationFrame", ts: +e.ts, dur: 0, end: +e.ts, pid: e.pid, evt: JSON.stringify(e) });
6072
}
6173
});
6274
return filteredEvents;
6375
}
6476

65-
async function fetchEventsFromPerformanceLog(fileName: string): Promise<TimingResult[]> {
77+
async function fetchEventsFromPerformanceLog(fileName: string, startLogicEventName: string): Promise<TimingResult[]> {
6678
let timingResults: TimingResult[] = [];
6779
let entries = [];
6880
do {
6981
let contents = await readFile(fileName, { encoding: "utf8" });
7082
let json = JSON.parse(contents);
7183
let entries = json["traceEvents"];
72-
const filteredEvents = extractRelevantEvents(entries);
84+
const filteredEvents = extractRelevantEvents(entries, startLogicEventName);
7385
timingResults = timingResults.concat(filteredEvents);
7486
} while (entries.length > 0);
7587
return timingResults;
@@ -158,8 +170,9 @@ function logEvents(events: TimingResult[], click: TimingResult) {
158170

159171
export async function computeResultsCPU(
160172
fileName: string,
173+
startLogicEventName: string,
161174
): Promise<CPUDurationResult> {
162-
const perfLogEvents = await fetchEventsFromPerformanceLog(fileName);
175+
const perfLogEvents = await fetchEventsFromPerformanceLog(fileName, startLogicEventName);
163176
let events = R.sortBy((e: TimingResult) => e.end)(perfLogEvents);
164177

165178
// Find mousedown event. This is the start of the benchmark
@@ -173,9 +186,9 @@ export async function computeResultsCPU(
173186
console.log("more than one mousedown event", fileName, events);
174187
throw "at most one mousedown event is expected";
175188
}
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);
179192
// Invariant: There must be exactly one click event
180193
if (clicks.length !== 1) {
181194
console.log("exactly one click event is expected", fileName, events);
@@ -189,7 +202,7 @@ export async function computeResultsCPU(
189202
if (mousedownToClick>0) {
190203
console.log("mousedownToClick", mousedownToClick, fileName);
191204
}
192-
if (mousedownToClick > 10000) {
205+
if (mousedownToClick > 5000) {
193206
console.log("difference between mousedown and click is unusually long", mousedownToClick, fileName);
194207
// throw "difference between mousedown and click is unusually long";
195208
}
@@ -445,15 +458,16 @@ export async function parseCPUTrace(
445458
benchmarkOptions: BenchmarkOptions,
446459
framework: FrameworkData,
447460
benchmarkInfo: CPUBenchmarkInfo,
448-
plausibilityCheck: PlausibilityCheck
461+
plausibilityCheck: PlausibilityCheck,
462+
startLogicEventName: string
449463
) {
450464
let results: CPUBenchmarkResult[] = [];
451465
for (let i = 0; i < benchmarkOptions.numIterationsForCPUBenchmarks + benchmarkInfo.additionalNumberOfRuns; i++) {
452466
let trace = `${fileNameTrace(framework, benchmarkInfo, i, benchmarkOptions)}`;
453467
if (fs.existsSync(trace)) {
454468
console.log("analyzing trace", trace);
455469
try {
456-
let result = await computeResultsCPU(trace);
470+
let result = await computeResultsCPU(trace, startLogicEventName);
457471
plausibilityCheck.check(result, trace, framework, benchmarkInfo);
458472
let resultJS = await computeResultsJS(result, config, trace);
459473
let resultPaint = await computeResultsPaint(result, config, trace);

0 commit comments

Comments
 (0)