1-- 2-- Copyright 2019 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 17DROP TABLE IF EXISTS {{table_name}}_stats; 18 19CREATE TABLE {{table_name}}_stats ( 20 process_name TEXT PRIMARY KEY, 21 min_value REAL, 22 max_value REAL, 23 avg_value REAL 24); 25 26INSERT INTO {{table_name}}_stats 27SELECT 28 process.name AS process_name, 29 MIN(span.{{table_name}}_val) AS min_value, 30 MAX(span.{{table_name}}_val) AS max_value, 31 SUM(span.{{table_name}}_val * span.dur) / SUM(span.dur) AS avg_value 32FROM {{table_name}}_span AS span JOIN process USING(upid) 33WHERE process.name IS NOT NULL 34GROUP BY 1 35ORDER BY 1; 36 37DROP VIEW IF EXISTS {{table_name}}_stats_proto; 38 39CREATE VIEW {{table_name}}_stats_proto AS 40SELECT 41 process_name, 42 AndroidMemoryMetric_Counter( 43 'min', min_value, 44 'max', max_value, 45 'avg', avg_value 46 ) AS proto 47FROM {{table_name}}_stats; 48