From 595c67d790c09c8cd018efd7cc2efa480aeb0b21 Mon Sep 17 00:00:00 2001 From: Hui Ling Shi Date: Wed, 27 Jul 2022 12:29:10 +0000 Subject: [PATCH] [11] Change matching WM/SF entry to IME entry algo Due to there being some slightly different timestamps between WM/SF trace and IME trace, we want to allow some "fault tolerance" -- even if a WM/SF entry comes after IME entry in time, it may still be the corresponding entry if it's within a manually-defined "fault tolerance" time. For now, fault tolerance is defined to be 200ms. So if a WM/SF entry is within IME entry +- 200ms, it may be considered a matching / corresponding entry. Within this range, we will always try to pick a WM/SF entry that comes before the IME entry. If there is no such WM/SF entry, then we will pick one that comes after. Bug: 236226833 Test: manual on local build of Winscope Change-Id: I0782ec520284517bf964eeffd552e6175758c9f1 --- .../winscope/src/ImeAdditionalProperties.vue | 8 ++--- tools/winscope/src/ime_processing.js | 32 +++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tools/winscope/src/ImeAdditionalProperties.vue b/tools/winscope/src/ImeAdditionalProperties.vue index 53d6c2731..0ecd679a5 100644 --- a/tools/winscope/src/ImeAdditionalProperties.vue +++ b/tools/winscope/src/ImeAdditionalProperties.vue @@ -159,13 +159,13 @@
Visibility
- InputMethod Window: - {{ + InputMethod Window: + {{ entry.wmProperties.isInputMethodWindowVisible }}
- InputMethod Surface: - {{ + InputMethod Surface: + {{ entry.sfProperties.isInputMethodSurfaceVisible }}
diff --git a/tools/winscope/src/ime_processing.js b/tools/winscope/src/ime_processing.js index 13c0c1d48..1fe913a78 100644 --- a/tools/winscope/src/ime_processing.js +++ b/tools/winscope/src/ime_processing.js @@ -100,23 +100,35 @@ function combineWmSfPropertiesIntoImeData(imeTraceFile, wmOrSfTraceFile) { } function matchCorrespondingTimestamps(imeTimestamps, wmOrSfTimestamps) { - // find the latest sf / wm timestamp that comes before current ime timestamp + // we want to take the earliest sf / wm entry that is within + // +-[FAULT_TOLERANCE] ns of the ime entry as the corresponding sf / wm entry + const FAULT_TOLERANCE = 200000000; // 200ms in ns + let wmOrSfIndex = 0; const intersectWmOrSfIndices = []; for (let imeIndex = 0; imeIndex < imeTimestamps.length; imeIndex++) { const currImeTimestamp = imeTimestamps[imeIndex]; - - let currWmOrSfTimestamp = wmOrSfTimestamps[wmOrSfIndex]; - while (currWmOrSfTimestamp < currImeTimestamp) { + let wmOrSfTimestamp = wmOrSfTimestamps[wmOrSfIndex]; + while (wmOrSfTimestamp < currImeTimestamp) { wmOrSfIndex++; - currWmOrSfTimestamp = wmOrSfTimestamps[wmOrSfIndex]; + wmOrSfTimestamp = wmOrSfTimestamps[wmOrSfIndex]; + } + // wmOrSfIndex should now be at the first entry that is past + // [currImeTimestamp] ns. We want the most recent entry that comes + // before [currImeTimestamp] ns if it's within + // [currImeTimestamp - FAULT_TOLERANCE] ns. Otherwise, we want the most + // recent entry that comes after [currImeTimestamp] ns if it's within + // [currImeTimestamp + FAULT_TOLERANCE] ns. + const previousWmOrSfTimestamp = wmOrSfTimestamps[wmOrSfIndex - 1]; + if (previousWmOrSfTimestamp >= currImeTimestamp - FAULT_TOLERANCE) { + intersectWmOrSfIndices.push(wmOrSfIndex - 1); + } else if (wmOrSfTimestamp <= currImeTimestamp + FAULT_TOLERANCE) { + intersectWmOrSfIndices.push(wmOrSfIndex); + } else { + intersectWmOrSfIndices.push(null); } - // if wmOrSfIndex is 0, i.e. no corresponding entry is found, - // we take the first wm / sf entry - // intersectWmOrSfIndices.push(Math.max(0, wmOrSfIndex - 1)); - intersectWmOrSfIndices.push(wmOrSfIndex - 1); } - console.log('done matching corresponding timestamps'); + console.log('done matching corresponding timestamps', intersectWmOrSfIndices); return intersectWmOrSfIndices; }