• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-- Create all the views used to generate the Android Memory metrics proto.
18-- Anon RSS
19SELECT RUN_METRIC('android/process_counter_span_view.sql',
20  'table_name', 'anon_rss',
21  'counter_name', 'mem.rss.anon');
22
23-- File RSS
24SELECT RUN_METRIC('android/process_counter_span_view.sql',
25  'table_name', 'file_rss',
26  'counter_name', 'mem.rss.file');
27
28SELECT RUN_METRIC('android/process_counter_span_view.sql',
29  'table_name', 'shmem_rss',
30  'counter_name', 'mem.rss.shmem');
31
32-- Swap
33SELECT RUN_METRIC('android/process_counter_span_view.sql',
34  'table_name', 'swap',
35  'counter_name', 'mem.swap');
36
37-- OOM score
38SELECT RUN_METRIC('android/process_oom_score.sql');
39
40-- Anon RSS + Swap
41DROP TABLE IF EXISTS anon_and_swap_join;
42CREATE VIRTUAL TABLE anon_and_swap_join
43USING SPAN_OUTER_JOIN(anon_rss_span PARTITIONED upid, swap_span PARTITIONED upid);
44
45DROP VIEW IF EXISTS anon_and_swap_span;
46CREATE VIEW anon_and_swap_span AS
47SELECT
48  ts, dur, upid,
49  IFNULL(anon_rss_val, 0) + IFNULL(swap_val, 0) AS anon_and_swap_val
50FROM anon_and_swap_join;
51
52-- Anon RSS + file RSS + Swap
53DROP TABLE IF EXISTS anon_and_file_and_swap_join;
54CREATE VIRTUAL TABLE anon_and_file_and_swap_join
55USING SPAN_OUTER_JOIN(
56  anon_and_swap_join PARTITIONED upid,
57  file_rss_span PARTITIONED upid
58);
59
60-- RSS + Swap
61DROP TABLE IF EXISTS rss_and_swap_join;
62CREATE VIRTUAL TABLE rss_and_swap_join
63USING SPAN_OUTER_JOIN(
64  anon_and_file_and_swap_join PARTITIONED upid,
65  shmem_rss_span PARTITIONED upid
66);
67
68DROP VIEW IF EXISTS rss_and_swap_span;
69CREATE VIEW rss_and_swap_span AS
70SELECT
71ts, dur, upid,
72CAST(IFNULL(file_rss_val, 0) AS INT) file_rss_val,
73CAST(IFNULL(anon_rss_val, 0) AS INT) anon_rss_val,
74CAST(IFNULL(shmem_rss_val, 0) AS INT) shmem_rss_val,
75CAST(IFNULL(swap_val, 0) AS INT) swap_val,
76CAST(
77  IFNULL(anon_rss_val, 0)
78  + IFNULL(swap_val, 0)
79  + IFNULL(file_rss_val, 0)
80  + IFNULL(shmem_rss_val, 0) AS int) AS rss_and_swap_val
81FROM rss_and_swap_join;
82
83-- If we have dalvik events enabled (for ART trace points) we can construct the java heap timeline.
84SELECT RUN_METRIC('android/process_counter_span_view.sql',
85  'table_name', 'java_heap_kb',
86  'counter_name', 'Heap size (KB)');
87
88DROP VIEW IF EXISTS java_heap_span;
89CREATE VIEW java_heap_span AS
90SELECT ts, dur, upid, java_heap_kb_val * 1024 AS java_heap_val
91FROM java_heap_kb_span;
92
93DROP TABLE IF EXISTS anon_rss_by_oom_span;
94CREATE VIRTUAL TABLE anon_rss_by_oom_span
95USING SPAN_JOIN(anon_rss_span PARTITIONED upid, oom_score_span PARTITIONED upid);
96
97DROP TABLE IF EXISTS file_rss_by_oom_span;
98CREATE VIRTUAL TABLE file_rss_by_oom_span
99USING SPAN_JOIN(file_rss_span PARTITIONED upid, oom_score_span PARTITIONED upid);
100
101DROP TABLE IF EXISTS swap_by_oom_span;
102CREATE VIRTUAL TABLE swap_by_oom_span
103USING SPAN_JOIN(swap_span PARTITIONED upid, oom_score_span PARTITIONED upid);
104
105DROP TABLE IF EXISTS anon_and_swap_by_oom_span;
106CREATE VIRTUAL TABLE anon_and_swap_by_oom_span
107USING SPAN_JOIN(anon_and_swap_span PARTITIONED upid, oom_score_span PARTITIONED upid);
108
109DROP TABLE IF EXISTS java_heap_by_oom_span;
110CREATE VIRTUAL TABLE java_heap_by_oom_span
111USING SPAN_JOIN(java_heap_span PARTITIONED upid, oom_score_span PARTITIONED upid);
112