Merge "metric: overhaul process associations in startup metric" am: dd8b3410c7
Original change: https://android-review.googlesource.com/c/platform/external/perfetto/+/1911490
Change-Id: Ia26f07c58771e9224af935ed38be7a28fd0c9e90
diff --git a/src/trace_processor/metrics/sql/android/startup/launches.sql b/src/trace_processor/metrics/sql/android/startup/launches.sql
index 4993cd5..492bac5 100644
--- a/src/trace_processor/metrics/sql/android/startup/launches.sql
+++ b/src/trace_processor/metrics/sql/android/startup/launches.sql
@@ -57,22 +57,38 @@
-- However it is possible that the process dies during the activity launch
-- and is respawned.
DROP TABLE IF EXISTS launch_processes;
-CREATE TABLE launch_processes(launch_id INT, upid BIG INT);
+CREATE TABLE launch_processes(launch_id INT, upid BIG INT, launch_type STRING);
-INSERT INTO launch_processes
-SELECT launches.id, process.upid
-FROM launches
-LEFT JOIN package_list ON (
- launches.package = package_list.package_name
-)
-JOIN process ON (
- launches.package = process.name OR
- process.uid = package_list.uid
-)
-JOIN thread ON (
- process.upid = thread.upid AND
- process.pid = thread.tid
-)
-WHERE (process.start_ts IS NULL OR process.start_ts < launches.ts_end)
-AND (thread.end_ts IS NULL OR thread.end_ts > launches.ts_end)
-ORDER BY process.start_ts DESC;
+SELECT CREATE_FUNCTION(
+ 'STARTUP_SLICE_COUNT(start_ts LONG, end_ts LONG, utid INT, name STRING)',
+ 'INT',
+ '
+ SELECT COUNT(1)
+ FROM thread_track t
+ JOIN slice s ON s.track_id = t.id
+ WHERE
+ t.utid = $utid AND
+ s.ts >= $start_ts AND
+ s.ts < $end_ts AND
+ s.name = $name
+ '
+);
+
+INSERT INTO launch_processes(launch_id, upid, launch_type)
+SELECT
+ l.id AS launch_id,
+ p.upid,
+ CASE
+ WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'bindApplication') > 0
+ THEN 'cold'
+ WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'activityStart') > 0
+ THEN 'warm'
+ WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'activityResume') > 0
+ THEN 'hot'
+ ELSE NULL
+ END AS launch_type
+FROM launches l
+LEFT JOIN package_list ON (l.package = package_list.package_name)
+JOIN process p ON (l.package = p.name OR p.uid = package_list.uid)
+JOIN thread t ON (p.upid = t.upid AND t.is_main_thread)
+WHERE launch_type IS NOT NULL;
diff --git a/test/trace_processor/startup/android_startup.out b/test/trace_processor/startup/android_startup.out
index a7dd383..5d323e4 100644
--- a/test/trace_processor/startup/android_startup.out
+++ b/test/trace_processor/startup/android_startup.out
@@ -18,12 +18,12 @@
}
}
zygote_new_process: false
- activity_hosting_process_count: 2
+ activity_hosting_process_count: 1
to_first_frame {
dur_ns: 108
main_thread_by_task_state {
- running_dur_ns: 41
- runnable_dur_ns: 129
+ running_dur_ns: 10
+ runnable_dur_ns: 80
uninterruptible_sleep_dur_ns: 0
interruptible_sleep_dur_ns: 10
}
@@ -34,6 +34,10 @@
}
mcycles_by_core_type {
}
+ time_activity_start {
+ dur_ns: 2
+ dur_ms: 2e-06
+ }
dur_ms: 0.000108
}
report_fully_drawn {
diff --git a/test/trace_processor/startup/android_startup.py b/test/trace_processor/startup/android_startup.py
index 494849c..c5f0e37 100644
--- a/test/trace_processor/startup/android_startup.py
+++ b/test/trace_processor/startup/android_startup.py
@@ -22,7 +22,7 @@
trace.add_process(1, 0, 'init')
trace.add_process(2, 1, 'system_server')
trace.add_process(3, 1, 'com.google.android.calendar', 10001)
-trace.add_process(4, 1, 'com.google.android.calendar')
+trace.add_process(4, 3, 'com.google.android.calendar', 10001)
trace.add_package_list(
ts=1, name='com.google.android.calendar', uid=10001, version_code=123)
@@ -42,6 +42,13 @@
ts=110, tid=2, pid=2, buf='launching: com.google.android.calendar')
trace.add_sched(ts=110, prev_pid=0, next_pid=3)
+
+# As the process already existed before intent started, this is a
+# warm/hot start (we choose warm). Therefore, emit an activityStart
+# slice.
+trace.add_atrace_begin(ts=115, tid=3, pid=3, buf='activityStart')
+trace.add_atrace_end(ts=117, tid=3, pid=3)
+
# P1: 10ns running
trace.add_sched(ts=120, prev_pid=3, next_pid=0, prev_state='S')
# P1: 10ns sleep
diff --git a/test/trace_processor/startup/android_startup_attribution.out b/test/trace_processor/startup/android_startup_attribution.out
index 87b1a30..3c74145 100644
--- a/test/trace_processor/startup/android_startup_attribution.out
+++ b/test/trace_processor/startup/android_startup_attribution.out
@@ -17,6 +17,10 @@
dur_ns: 2
dur_ms: 2e-06
}
+ time_activity_resume {
+ dur_ns: 5
+ dur_ms: 5e-06
+ }
dur_ms: 999.9999
time_dex_open {
dur_ns: 20
diff --git a/test/trace_processor/startup/android_startup_attribution.py b/test/trace_processor/startup/android_startup_attribution.py
index cf3ab8e..2f8a4be 100644
--- a/test/trace_processor/startup/android_startup_attribution.py
+++ b/test/trace_processor/startup/android_startup_attribution.py
@@ -18,7 +18,7 @@
import synth_common
APP_PID = 3
-APP_TID = 1
+APP_TID = APP_PID
SECOND_APP_TID = 3
JIT_TID = 4
GC_TID = 5
@@ -65,6 +65,10 @@
tid=SYSTEM_SERVER_TID,
buf='launching: com.some.app')
+# Emulate a hot start (and therefore that we only see activityResume).
+trace.add_atrace_begin(ts=125, tid=APP_TID, pid=APP_PID, buf='activityResume')
+trace.add_atrace_end(ts=130, tid=APP_TID, pid=APP_PID)
+
# OpenDex slices within the startup.
trace.add_atrace_begin(
ts=150, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(something)')
diff --git a/test/trace_processor/startup/android_startup_process_track.out b/test/trace_processor/startup/android_startup_process_track.out
index 357603d..7a8ae0f 100644
--- a/test/trace_processor/startup/android_startup_process_track.out
+++ b/test/trace_processor/startup/android_startup_process_track.out
@@ -8,7 +8,7 @@
}
zygote_new_process: false
to_first_frame {
- dur_ns: 4
+ dur_ns: 5
main_thread_by_task_state {
running_dur_ns: 0
runnable_dur_ns: 0
@@ -22,11 +22,19 @@
}
mcycles_by_core_type {
}
- dur_ms: 4e-06
+ time_bind_application {
+ dur_ns: 1
+ dur_ms: 1e-06
+ }
+ dur_ms: 5e-06
+ to_bind_application {
+ dur_ns: 3
+ dur_ms: 3e-06
+ }
}
event_timestamps {
intent_received: 100
- first_frame: 104
+ first_frame: 105
}
activity_hosting_process_count: 1
}
@@ -39,7 +47,7 @@
}
zygote_new_process: false
to_first_frame {
- dur_ns: 4
+ dur_ns: 5
main_thread_by_task_state {
running_dur_ns: 0
runnable_dur_ns: 0
@@ -53,11 +61,19 @@
}
mcycles_by_core_type {
}
- dur_ms: 4e-06
+ time_bind_application {
+ dur_ns: 1
+ dur_ms: 1e-06
+ }
+ dur_ms: 5e-06
+ to_bind_application {
+ dur_ns: 3
+ dur_ms: 3e-06
+ }
}
event_timestamps {
intent_received: 200
- first_frame: 204
+ first_frame: 205
}
activity_hosting_process_count: 1
}
diff --git a/test/trace_processor/startup/android_startup_process_track.py b/test/trace_processor/startup/android_startup_process_track.py
index a9696ad..07fcf92 100644
--- a/test/trace_processor/startup/android_startup_process_track.py
+++ b/test/trace_processor/startup/android_startup_process_track.py
@@ -34,10 +34,12 @@
new_tid=pid,
new_comm='com.google.android.calendar',
flags=0)
+ trace.add_atrace_begin(ts=ts + 3, tid=pid, pid=pid, buf='bindApplication')
+ trace.add_atrace_end(ts=ts + 4, tid=pid, pid=pid)
trace.add_atrace_async_end(
- ts=ts + 4, tid=2, pid=2, buf='launching: com.google.android.calendar')
+ ts=ts + 5, tid=2, pid=2, buf='launching: com.google.android.calendar')
trace.add_atrace_begin(
- ts=ts + 5,
+ ts=ts + 6,
tid=2,
pid=2,
buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')