1-- 2-- Copyright 2020 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-- 16 17-- This is a mapping from counter names on different devices 18-- to what subsystems they are measuring. 19DROP TABLE IF EXISTS power_counters; 20CREATE TABLE power_counters (name TEXT UNIQUE, subsystem TEXT); 21 22INSERT INTO power_counters 23VALUES ('power.VPH_PWR_S5C_S6C_uws', 'cpu_big'), 24 ('power.VPH_PWR_S4C_uws', 'cpu_little'), 25 ('power.VPH_PWR_S2C_S3C_uws', 'soc'), 26 ('power.VPH_PWR_OLED_uws', 'display'), 27 ('power.PPVAR_VPH_PWR_S1A_S9A_S10A_uws', 'soc'), 28 ('power.PPVAR_VPH_PWR_S2A_S3A_uws', 'cpu_big'), 29 ('power.PPVAR_VPH_PWR_S1C_uws', 'cpu_little'), 30 ('power.WCN3998_VDD13 [from PP1304_L2C]_uws', 'wifi'), 31 ('power.PPVAR_VPH_PWR_WLAN_uws', 'wifi'), 32 ('power.PPVAR_VPH_PWR_OLED_uws', 'display'), 33 ('power.PPVAR_VPH_PWR_QTM525_uws', 'cellular'), 34 ('power.PPVAR_VPH_PWR_RF_uws', 'cellular'), 35 ('power.rails.aoc.logic', 'aoc'), 36 ('power.rails.aoc.memory', 'aoc'), 37 ('power.rails.cpu.big', 'cpu_big'), 38 ('power.rails.cpu.little', 'cpu_little'), 39 ('power.rails.cpu.mid', 'cpu_mid'), 40 ('power.rails.ddr.a', 'mem'), 41 ('power.rails.ddr.b', 'mem'), 42 ('power.rails.ddr.c', 'mem'), 43 ('power.rails.gpu', 'gpu'), 44 ('power.rails.display', 'display'), 45 ('power.rails.gps', 'gps'), 46 ('power.rails.memory.interface', 'mem'), 47 ('power.rails.modem', 'cellular'), 48 ('power.rails.radio.frontend', 'cellular'), 49 ('power.rails.system.fabric', 'soc'), 50 ('power.rails.wifi.bt', 'wifi'); 51 52-- Convert power counter data into table of events, where each event has 53-- start timestamp, duration and the average power drain during its duration 54-- in Watts. 55-- Note that power counters wrap around at different values on different 56-- devices. When that happens, we ignore the value before overflow, and only 57-- take into account the value after it. This underestimates the actual power 58-- drain between those counters. 59DROP VIEW IF EXISTS drain_in_watts; 60CREATE VIEW drain_in_watts AS 61SELECT name, 62 ts, 63 LEAD(ts) OVER ( 64 PARTITION BY track_id 65 ORDER BY ts 66 ) - ts AS dur, 67 CASE 68 WHEN LEAD(value) OVER ( 69 PARTITION BY track_id 70 ORDER BY ts 71 ) >= value THEN ( 72 LEAD(value) OVER ( 73 PARTITION BY track_id 74 ORDER BY ts 75 ) - value 76 ) 77 ELSE LEAD(value) OVER ( 78 PARTITION BY track_id 79 ORDER BY ts 80 ) 81 END / ( 82 LEAD(ts) OVER ( 83 PARTITION BY track_id 84 ORDER BY ts 85 ) - ts 86 ) * 1e3 AS drain_w 87FROM counter 88 JOIN counter_track ON (counter.track_id = counter_track.id) 89WHERE counter_track.type = 'counter_track' 90 AND name LIKE "power.%"; 91 92