• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16INCLUDE PERFETTO MODULE cpu.idle;
17INCLUDE PERFETTO MODULE wattson.device_infos;
18
19-- Get the corresponding deep idle time offset based on device and CPU.
20CREATE PERFETTO TABLE _filtered_deep_idle_offsets
21AS
22SELECT cpu, offset_ns
23FROM _device_cpu_deep_idle_offsets as offsets
24JOIN _wattson_device as device
25ON offsets.device = device.name;
26
27-- Adjust duration of active portion to be slightly longer to account for
28-- overhead cost of transitioning out of deep idle. This is done because the
29-- device is active and consumes power for longer than the logs actually report.
30CREATE PERFETTO TABLE _adjusted_deep_idle
31AS
32WITH
33  idle_prev AS (
34    SELECT
35      ts,
36      dur,
37      idle,
38      lag(idle) OVER (PARTITION BY track_id ORDER BY ts) AS idle_prev,
39      cpu
40    FROM cpu_idle_counters
41  ),
42  -- Adjusted ts if applicable, which makes the current deep idle state
43  -- slightly shorter.
44  idle_mod AS (
45    SELECT
46      IIF(
47        idle_prev = -1 AND idle = 1,
48        IIF(dur > offset_ns, ts + offset_ns, ts + dur),
49        ts
50      ) as ts,
51      -- ts_next is the starting timestamp of the next slice (i.e. end ts of
52      -- current slice)
53      ts + dur as ts_next,
54      cpu,
55      idle
56    FROM idle_prev
57    JOIN _filtered_deep_idle_offsets using (cpu)
58  )
59SELECT
60  ts,
61  lead(ts, 1, trace_end()) OVER (PARTITION BY cpu ORDER by ts) - ts as dur,
62  cpu,
63  idle
64FROM idle_mod
65WHERE ts != ts_next;
66
67