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 templated metric that takes 3 parameters: 18-- input: name of a table/view which must have columns: id, ts, dur and a 19-- "category" column 20-- output: name of the view that will be created 21-- category: name of the category column in the input table, which will be 22-- preserved in the output 23 24SELECT RUN_METRIC('chrome/chrome_processes.sql'); 25SELECT RUN_METRIC('android/android_proxy_power.sql'); 26 27-- View containing estimated power slices broken down by cpu. 28DROP VIEW IF EXISTS power_per_chrome_thread; 29CREATE VIEW power_per_chrome_thread AS 30SELECT ts, 31 dur, 32 cpu, 33 power_per_thread.utid, 34 end_state, 35 priority, 36 power_ma, 37 power_per_thread.type, 38 name AS thread_name, 39 upid, 40 is_main_thread 41FROM power_per_thread 42 JOIN chrome_thread 43WHERE power_per_thread.utid = chrome_thread.utid; 44 45DROP TABLE IF EXISTS {{input}}_power; 46CREATE VIRTUAL TABLE {{input}}_power USING SPAN_JOIN( 47 {{input}}, 48 power_per_chrome_thread PARTITIONED utid 49); 50 51-- Estimated power usage for chrome across the categroy slices contained in 52-- input. 53DROP VIEW IF EXISTS {{output}}; 54CREATE VIEW {{output}} AS 55SELECT id, 56 ts, 57 dur, 58 {{category}}, 59 mas, 60 mas / dur * 1e9 AS ma 61FROM ( 62 SELECT s.id, 63 s.ts, 64 s.dur, 65 s.{{category}}, 66 SUM(r.power_ma * r.dur) / 1e9 AS mas 67 FROM {{input}}_power r 68 JOIN {{input}} s 69 WHERE r.id == s.id 70 GROUP BY s.id 71 ); 72