[android_Desktop_mode] Fix bug when reset atoms in trace.
When we see an instance of the "reset" event for the
desktop_mode_session_task_info_update atom, we should use that
as the time point of a window being removed rather than the end
of the trace if there was no explicit remove event.
Test: tools/diff_test_trace_processor.py out/linux/trace_processor_shell --name-filter '.*desktop_mode.*'
Bug: 370730027
Change-Id: Ie9e64b77a6bf61aae9d07737f24ae658e3cd5c00
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/desktop_mode.sql b/src/trace_processor/perfetto_sql/stdlib/android/desktop_mode.sql
index 496e4ee..29c0b84 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/desktop_mode.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/android/desktop_mode.sql
@@ -51,12 +51,21 @@
dw_statsd_events_update_by_instance AS (
SELECT instance_id, session_id, min(uid) AS uid FROM atoms
WHERE type = 'TASK_INFO_CHANGED' GROUP BY instance_id, session_id),
+ dw_statsd_reset_event AS (
+ SELECT ts FROM atoms
+ WHERE type = 'TASK_INIT_STATSD'
+ UNION
+ SELECT trace_end()),
dw_windows AS (
SELECT
a.ts AS raw_add_ts,
r.ts AS raw_remove_ts,
ifnull(a.ts, trace_start()) AS ts, -- Assume trace_start() if no add event found.
- ifnull(r.ts, trace_end()) - ifnull(a.ts, trace_start()) AS dur, -- Assume trace_end() if no remove event found.
+ ifnull(r.ts,
+ (
+ SELECT MIN(ts) FROM dw_statsd_reset_event
+ WHERE ts > ifnull(a.ts, trace_start())
+ )) - ifnull(a.ts, trace_start()) AS dur, -- Assume next reset event or trace_end() if no remove event found.
ifnull(a.instance_id, r.instance_id) AS instance_id,
ifnull(a.uid, r.uid) AS uid
FROM dw_statsd_events_add a
diff --git a/test/data/android_desktop_mode/task_update_reset_events.pb.sha256 b/test/data/android_desktop_mode/task_update_reset_events.pb.sha256
new file mode 100644
index 0000000..f047a6a
--- /dev/null
+++ b/test/data/android_desktop_mode/task_update_reset_events.pb.sha256
@@ -0,0 +1 @@
+1aca7da3154a8893d214444d10559d88e689d090e6d39206e30959aa2a2cd306
\ No newline at end of file
diff --git a/test/trace_processor/diff_tests/stdlib/android/desktop_mode_tests.py b/test/trace_processor/diff_tests/stdlib/android/desktop_mode_tests.py
index 6c16720..0570da9 100644
--- a/test/trace_processor/diff_tests/stdlib/android/desktop_mode_tests.py
+++ b/test/trace_processor/diff_tests/stdlib/android/desktop_mode_tests.py
@@ -108,3 +108,37 @@
8966481546961,"[NULL]",8966481546961,3595287192,1000028,1110329
"""))
+ def test_android_desktop_mode_windows_statsd_events_reset_events(self):
+ return DiffTestBlueprint(
+ trace=DataPath('android_desktop_mode/task_update_reset_events.pb'),
+ query="""
+ INCLUDE PERFETTO MODULE android.desktop_mode;
+ SELECT * FROM android_desktop_mode_windows;
+ """,
+ out=Csv("""
+ "raw_add_ts","raw_remove_ts","ts","dur","instance_id","uid"
+ 84164708379314,84188981730278,84164708379314,24273350964,1000054,1010210
+ 84182861720998,84184961957530,84182861720998,2100236532,1000056,1010197
+ 84190656246474,"[NULL]",84190656246474,663853800,1000054,1010210
+ 84190656724094,"[NULL]",84190656724094,663376180,1000058,1010222
+ 84199757126076,84223637163807,84199757126076,23880037731,1000054,1010210
+ 84199757350156,84223637751006,84199757350156,23880400850,1000058,1010222
+ 84204112441752,84208226333681,84204112441752,4113891929,1000062,1010226
+ 84226052369131,84241418229490,84226052369131,15365860359,1000054,1010210
+ 84226054551300,84241419846189,84226054551300,15365294889,1000058,1010222
+ 84248341935751,"[NULL]",84248341935751,407771770,1000054,1010210
+ 84248342227662,"[NULL]",84248342227662,407479859,1000058,1010222
+ 84253290279911,84292320102806,84253290279911,39029822895,1000054,1010210
+ 84253290608646,84292320892072,84253290608646,39030283426,1000058,1010222
+ 84294338295719,84856791435520,84294338295719,562453139801,1000054,1010210
+ 84294339318912,84859506938084,84294339318912,565167619172,1000058,1010222
+ 84304813959094,84858368194309,84304813959094,553554235215,1000069,1010211
+ 84335762434858,84852636055309,84335762434858,516873620451,1000070,1010297
+ 84357340686822,84378879321354,84357340686822,21538634532,1000071,1010225
+ 84361592237320,84363638663184,84361592237320,2046425864,1000072,1010317
+ 84370549790954,84853627568534,84370549790954,483077777580,1000074,1010317
+ 84575862070921,84643498791291,84575862070921,67636720370,1000075,1001000
+ 84619864755554,84638100287708,84619864755554,18235532154,1000076,1010235
+ 84782344478655,84804145589506,84782344478655,21801110851,1000077,1010238
+ """))
+