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 17-- This gives us access to the RSS breakdowns. 18SELECT RUN_METRIC('android/process_mem.sql'); 19 20-- Compute DMA spans. 21SELECT RUN_METRIC('android/global_counter_span_view.sql', 22 'table_name', 'dma', 23 'counter_name', 'mem.dma_heap'); 24 25-- RSS of GCA. 26DROP VIEW IF EXISTS rss_gca; 27CREATE VIEW rss_gca AS 28SELECT ts, dur, rss_val AS gca_rss_val 29FROM rss_and_swap_span 30JOIN ( 31 SELECT max(start_ts), upid 32 FROM process 33 WHERE name GLOB '*GoogleCamera*' 34 LIMIT 1 35) AS gca USING (upid); 36 37-- RSS of camera HAL. 38DROP VIEW IF EXISTS rss_camera_hal; 39CREATE VIEW rss_camera_hal AS 40SELECT ts, dur, rss_val AS hal_rss_val 41FROM rss_and_swap_span 42JOIN ( 43 SELECT max(start_ts), upid 44 FROM process 45 WHERE name GLOB '*camera.provider*' 46 LIMIT 1 47) AS hal USING (upid); 48 49-- RSS of cameraserver. 50DROP VIEW IF EXISTS rss_cameraserver; 51CREATE VIEW rss_cameraserver AS 52SELECT ts, dur, rss_val AS cameraserver_rss_val 53FROM rss_and_swap_span 54JOIN ( 55 SELECT max(start_ts), upid 56 FROM process 57 WHERE name = 'cameraserver' 58 LIMIT 1 59) AS cameraserver USING (upid); 60 61-- RSS of GCA + HAL. 62DROP TABLE IF EXISTS rss_gca_hal; 63CREATE VIRTUAL TABLE rss_gca_hal 64USING SPAN_OUTER_JOIN(rss_gca, rss_camera_hal); 65 66-- RSS of GCA + HAL + cameraserver. 67DROP TABLE IF EXISTS rss_all_camera; 68CREATE VIRTUAL TABLE rss_all_camera 69USING SPAN_OUTER_JOIN(rss_gca_hal, rss_cameraserver); 70 71-- RSS of GCA + HAL + cameraserver + DMA. 72DROP TABLE IF EXISTS rss_and_dma_all_camera_join; 73CREATE VIRTUAL TABLE rss_and_dma_all_camera_join 74USING SPAN_OUTER_JOIN(dma_span, rss_all_camera); 75 76DROP VIEW IF EXISTS rss_and_dma_all_camera_span; 77CREATE VIEW rss_and_dma_all_camera_span AS 78SELECT 79 ts, 80 dur, 81 CAST( 82 IFNULL(gca_rss_val, 0) + 83 IFNULL(hal_rss_val, 0) + 84 IFNULL(cameraserver_rss_val, 0) + 85 IFNULL(dma_val, 0) AS int) AS rss_and_dma_val 86FROM rss_and_dma_all_camera_join; 87 88-- we are dividing and casting to real when calculating avg_value 89-- to avoid issues such as the one in b/203613535 90DROP VIEW IF EXISTS rss_and_dma_all_camera_stats; 91CREATE VIEW rss_and_dma_all_camera_stats AS 92SELECT 93 MIN(rss_and_dma_val) AS min_value, 94 MAX(rss_and_dma_val) AS max_value, 95 SUM(rss_and_dma_val * dur / 1e3) / SUM(dur / 1e3) AS avg_value 96FROM rss_and_dma_all_camera_span; 97 98DROP VIEW IF EXISTS android_camera_event; 99CREATE VIEW android_camera_event AS 100SELECT 101 'counter' AS track_type, 102 'Camera Memory' AS track_name, 103 ts, 104 rss_and_dma_val AS value 105FROM rss_and_dma_all_camera_span; 106 107DROP VIEW IF EXISTS android_camera_output; 108CREATE VIEW android_camera_output AS 109SELECT 110 AndroidCameraMetric( 111 'gc_rss_and_dma', AndroidCameraMetric_Counter( 112 'min', CAST(min_value AS real), 113 'max', CAST(max_value AS real), 114 'avg', CAST(avg_value AS real) 115 ) 116 ) 117FROM rss_and_dma_all_camera_stats; 118