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 17SELECT RUN_METRIC('android/process_mem.sql'); 18 19SELECT RUN_METRIC('android/span_view_stats.sql', 'table_name', 'anon_rss'); 20 21SELECT RUN_METRIC('android/span_view_stats.sql', 'table_name', 'file_rss'); 22 23SELECT RUN_METRIC('android/span_view_stats.sql', 'table_name', 'swap'); 24 25SELECT RUN_METRIC('android/span_view_stats.sql', 'table_name', 'anon_and_swap'); 26 27SELECT RUN_METRIC('android/span_view_stats.sql', 'table_name', 'java_heap'); 28 29SELECT RUN_METRIC('android/mem_stats_priority_breakdown.sql', 'table_name', 'anon_rss'); 30 31SELECT RUN_METRIC('android/mem_stats_priority_breakdown.sql', 'table_name', 'file_rss'); 32 33SELECT RUN_METRIC('android/mem_stats_priority_breakdown.sql', 'table_name', 'swap'); 34 35SELECT RUN_METRIC('android/mem_stats_priority_breakdown.sql', 'table_name', 'anon_and_swap'); 36 37SELECT RUN_METRIC('android/mem_stats_priority_breakdown.sql', 'table_name', 'java_heap'); 38 39-- Find out all process + priority pairs with data to drive the joins (no outer join in sqlite). 40DROP VIEW IF EXISTS mem_all_processes; 41CREATE VIEW mem_all_processes AS 42SELECT DISTINCT process_name 43FROM 44( 45 SELECT process_name FROM anon_rss_stats_proto 46 UNION 47 SELECT process_name FROM file_rss_stats_proto 48 UNION 49 SELECT process_name FROM swap_stats_proto 50 UNION 51 SELECT process_name FROM anon_and_swap_stats_proto 52 UNION 53 SELECT process_name FROM java_heap_stats_proto 54); 55 56DROP VIEW IF EXISTS mem_all_process_priorities; 57CREATE VIEW mem_all_process_priorities AS 58SELECT DISTINCT process_name, priority 59FROM 60( 61 SELECT process_name, priority FROM anon_rss_by_priority_stats_proto 62 UNION 63 SELECT process_name, priority FROM file_rss_by_priority_stats_proto 64 UNION 65 SELECT process_name, priority FROM swap_by_priority_stats_proto 66 UNION 67 SELECT process_name, priority FROM anon_and_swap_by_priority_stats_proto 68 UNION 69 SELECT process_name, priority FROM java_heap_by_priority_stats_proto 70); 71 72DROP VIEW IF EXISTS process_priority_view; 73CREATE VIEW process_priority_view AS 74SELECT 75 process_name, 76 AndroidMemoryMetric_PriorityBreakdown( 77 'priority', priority, 78 'counters', AndroidMemoryMetric_ProcessMemoryCounters( 79 'anon_rss', anon_rss_by_priority_stats_proto.proto, 80 'file_rss', file_rss_by_priority_stats_proto.proto, 81 'swap', swap_by_priority_stats_proto.proto, 82 'anon_and_swap', anon_and_swap_by_priority_stats_proto.proto, 83 'java_heap', java_heap_by_priority_stats_proto.proto 84 ) 85 ) AS priority_breakdown_proto 86FROM mem_all_process_priorities 87LEFT JOIN anon_rss_by_priority_stats_proto USING (process_name, priority) 88LEFT JOIN file_rss_by_priority_stats_proto USING (process_name, priority) 89LEFT JOIN swap_by_priority_stats_proto USING (process_name, priority) 90LEFT JOIN anon_and_swap_by_priority_stats_proto USING (process_name, priority) 91LEFT JOIN java_heap_by_priority_stats_proto USING (process_name, priority); 92 93DROP VIEW IF EXISTS process_metrics_view; 94CREATE VIEW process_metrics_view AS 95SELECT 96 AndroidMemoryMetric_ProcessMetrics( 97 'process_name', process_name, 98 'total_counters', AndroidMemoryMetric_ProcessMemoryCounters( 99 'anon_rss', anon_rss_stats_proto.proto, 100 'file_rss', file_rss_stats_proto.proto, 101 'swap', swap_stats_proto.proto, 102 'anon_and_swap', anon_and_swap_stats_proto.proto, 103 'java_heap', java_heap_stats_proto.proto 104 ), 105 'priority_breakdown', ( 106 SELECT RepeatedField(priority_breakdown_proto) 107 FROM process_priority_view AS ppv 108 WHERE mem_all_processes.process_name = ppv.process_name 109 ) 110 ) AS metric 111FROM 112 mem_all_processes 113 LEFT JOIN anon_rss_stats_proto USING (process_name) 114 LEFT JOIN file_rss_stats_proto USING (process_name) 115 LEFT JOIN swap_stats_proto USING (process_name) 116 LEFT JOIN anon_and_swap_stats_proto USING (process_name) 117 LEFT JOIN java_heap_stats_proto USING (process_name); 118 119DROP VIEW IF EXISTS android_mem_output; 120CREATE VIEW android_mem_output AS 121SELECT 122 AndroidMemoryMetric( 123 'process_metrics', 124 (SELECT RepeatedField(metric) FROM process_metrics_view) 125 ); 126