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 17SELECT RUN_METRIC('android/global_counter_span_view.sql', 18 'table_name', 'global_gpu_memory', 19 'counter_name', 'GPU Memory'); 20 21SELECT RUN_METRIC('android/process_counter_span_view.sql', 22 'table_name', 'proc_gpu_memory', 23 'counter_name', 'GPU Memory'); 24 25DROP VIEW IF EXISTS proc_gpu_memory_view; 26CREATE VIEW proc_gpu_memory_view AS 27SELECT 28 upid, 29 MAX(proc_gpu_memory_val) as mem_max, 30 MIN(proc_gpu_memory_val) as mem_min, 31 SUM(proc_gpu_memory_val * dur) as mem_valxdur, 32 SUM(dur) as mem_dur 33FROM proc_gpu_memory_span 34GROUP BY upid; 35 36DROP VIEW IF EXISTS agg_proc_gpu_view; 37CREATE VIEW agg_proc_gpu_view AS 38SELECT 39 name, 40 MAX(mem_max) as mem_max, 41 MIN(mem_min) as mem_min, 42 SUM(mem_valxdur) / SUM(mem_dur) as mem_avg 43FROM process 44JOIN proc_gpu_memory_view 45USING(upid) 46GROUP BY name; 47 48DROP VIEW IF EXISTS proc_gpu_view; 49CREATE VIEW proc_gpu_view AS 50SELECT 51 AndroidGpuMetric_Process( 52 'name', name, 53 'mem_max', CAST(mem_max as INT64), 54 'mem_min', CAST(mem_min as INT64), 55 'mem_avg', CAST(mem_avg as INT64) 56 ) AS proto 57FROM agg_proc_gpu_view; 58 59DROP VIEW IF EXISTS android_gpu_output; 60CREATE VIEW android_gpu_output AS 61SELECT AndroidGpuMetric( 62 'processes', (SELECT RepeatedField(proto) FROM proc_gpu_view), 63 'mem_max', CAST(MAX(global_gpu_memory_val) as INT64), 64 'mem_min', CAST(MIN(global_gpu_memory_val) as INT64), 65 'mem_avg', CAST(SUM(global_gpu_memory_val * dur) / SUM(dur) as INT64) 66) 67FROM global_gpu_memory_span; 68