diff options
author | Simon MacMullen <simonmacm@google.com> | 2020-11-27 14:06:46 +0000 |
---|---|---|
committer | Simon MacMullen <simonmacm@google.com> | 2020-11-27 14:06:46 +0000 |
commit | 2b506e6d2c4a45bc4c7430a9b403588cf97c4e3c (patch) | |
tree | 16a2761ab82bf2e6b35dbae0e0393334b0183971 | |
parent | 3af2db390fde4398dd85b017248ef371b16cef8b (diff) | |
download | perfetto-2b506e6d2c4a45bc4c7430a9b403588cf97c4e3c.tar.gz |
Read the action field for suspend_resume ftrace events, if we have it.
Bug: 174310573
Change-Id: I6f305050da32e664ea06858fa83f8cd633076bd5
-rw-r--r-- | src/trace_processor/metrics/android/android_batt.sql | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/src/trace_processor/metrics/android/android_batt.sql b/src/trace_processor/metrics/android/android_batt.sql index eb2181ffa..5b94a12b7 100644 --- a/src/trace_processor/metrics/android/android_batt.sql +++ b/src/trace_processor/metrics/android/android_batt.sql @@ -82,7 +82,52 @@ FROM ( ) GROUP BY group_id; +-- Different device kernels log different actions when suspending. This table +-- tells us the action that straddles the actual suspend period. +CREATE TABLE device_action_mapping (device TEXT, action TEXT); +INSERT INTO device_action_mapping VALUES +('blueline', 'timekeeping_freeze'), +('crosshatch', 'timekeeping_freeze'), +('bonito', 'timekeeping_freeze'), +('sargo', 'timekeeping_freeze'), +('coral', 'timekeeping_freeze'), +('flame', 'timekeeping_freeze'), +('sunfish', 'timekeeping_freeze'), +('redfin', 'syscore_resume'), +('bramble', 'syscore_resume'); + +CREATE TABLE device_action AS +SELECT action +FROM device_action_mapping dam +WHERE EXISTS ( + SELECT 1 FROM metadata + WHERE name = 'android_build_fingerprint' AND str_value LIKE '%' || dam.device || '%'); + CREATE TABLE suspend_slice_ AS +-- Traces from after b/70292203 was fixed have the action string so just look +-- for it. +SELECT + ts, + dur +FROM ( + SELECT + ts, + LEAD(ts) OVER (ORDER BY ts, start DESC) - ts AS dur, + start + FROM ( + SELECT + ts, + EXTRACT_ARG(arg_set_id, 'action') AS action, + EXTRACT_ARG(arg_set_id, 'start') AS start + FROM raw + WHERE name = 'suspend_resume' + ) JOIN device_action USING(action) +) +WHERE start = 1 +UNION ALL +-- Traces from before b/70292203 was fixed (approx Nov 2020) do not have the +-- action string so we do some convoluted pattern matching that mostly works. +-- TODO(simonmacm) remove this when enough time has passed (mid 2021?) SELECT ts, dur @@ -91,6 +136,7 @@ FROM ( ts, ts - lag(ts) OVER w AS lag_dur, lead(ts) OVER w - ts AS dur, + action, start, event, lag(start) OVER w AS lag_start, @@ -104,6 +150,7 @@ FROM ( FROM ( SELECT ts, + EXTRACT_ARG(arg_set_id, 'action') AS action, EXTRACT_ARG(arg_set_id, 'start') AS start, EXTRACT_ARG(arg_set_id, 'val') AS event FROM raw @@ -111,8 +158,8 @@ FROM ( ) WINDOW w AS (ORDER BY ts) ) +WHERE action IS NULL AND ( -- We want to find the start and end events with action='timekeeping_freeze'. --- Unfortunately b/70292203 leads to the action string being lost. -- In practice, these events often show up in a sequence like the following: -- start = 1, event = 1 [string would have been 'machine_suspend'] -- start = 1, event = (any) [string would have been 'timekeeping_freeze'] * @@ -124,12 +171,12 @@ FROM ( -- -- So we look for this pattern of start and event, anchored on the event marked -- with "*". -WHERE ( - lag_start = 1 AND lag_event = 1 - AND start = 1 - AND lead_start = 0 - AND lead_2_start = 0 AND lead_2_event = 1 -) + ( + lag_start = 1 AND lag_event = 1 + AND start = 1 + AND lead_start = 0 + AND lead_2_start = 0 AND lead_2_event = 1 + ) -- Or in newer kernels we seem to have a very different pattern. We can take -- advantage of that fact that we get several events with identical timestamp -- just before sleeping (normally this never happens): @@ -140,15 +187,18 @@ WHERE ( -- (sleep happens here) -- -- gap = (any), start = 0, event = 0 - -OR ( - lag_dur = 0 - AND lead_start = 0 AND lead_event = 0 - AND start = 1 AND event = 0 - AND lag_start = 0 AND lag_event = 3 - AND lag_2_start = 1 AND lag_2_event = 3 + OR ( + lag_dur = 0 + AND lead_start = 0 AND lead_event = 0 + AND start = 1 AND event = 0 + AND lag_start = 0 AND lag_event = 3 + AND lag_2_start = 1 AND lag_2_event = 3 + ) ); +DROP TABLE device_action_mapping; +DROP TABLE device_action; + SELECT RUN_METRIC('android/global_counter_span_view.sql', 'table_name', 'screen_state', 'counter_name', 'ScreenState'); |