Support getting last entry in a trace by elapsed timestamp
Test: atest FlickerLibTest
Bug: 265791451
Change-Id: Iae535583b25c4fc7298769c40a999447e4656bf9
diff --git a/libraries/flicker/src/com/android/server/wm/traces/common/ITrace.kt b/libraries/flicker/src/com/android/server/wm/traces/common/ITrace.kt
index 8e1507c..ff565b7 100644
--- a/libraries/flicker/src/com/android/server/wm/traces/common/ITrace.kt
+++ b/libraries/flicker/src/com/android/server/wm/traces/common/ITrace.kt
@@ -29,6 +29,12 @@
?: throw RuntimeException("Entry does not exist for timestamp $timestamp")
}
+ @JsName("getLastEntryByElapsedTimestamp")
+ fun getLastEntryByElapsedTimestamp(timestamp: Long): Entry {
+ return entries.asList().asReversed().firstOrNull { it.timestamp.elapsedNanos <= timestamp }
+ ?: throw RuntimeException("No entry at or before timestamp $timestamp")
+ }
+
@JsName("getEntryBySystemUptime")
fun getEntryBySystemUptime(timestamp: Long): Entry {
return entries.firstOrNull { it.timestamp.systemUptimeNanos == timestamp }