• 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
17DROP TABLE IF EXISTS {{table_name}}_by_priority_stats;
18CREATE TABLE {{table_name}}_by_priority_stats (
19  process_name TEXT,
20  priority TEXT,
21  min_value REAL,
22  max_value REAL,
23  avg_value REAL,
24  PRIMARY KEY (process_name, priority)
25);
26
27INSERT INTO {{table_name}}_by_priority_stats
28SELECT
29  process.name AS process_name,
30  CASE
31    WHEN oom_score_val < -900 THEN 'native'
32    WHEN oom_score_val < -800 THEN 'system'
33    WHEN oom_score_val < -700 THEN 'persistent'
34    WHEN oom_score_val <  0   THEN 'persistent_service'
35    WHEN oom_score_val <  100 THEN 'foreground'
36    WHEN oom_score_val <  200 THEN 'visible'
37    WHEN oom_score_val <  300 THEN 'perceptible'
38    WHEN oom_score_val <  400 THEN 'backup'
39    WHEN oom_score_val <  500 THEN 'heavy_weight'
40    WHEN oom_score_val <  600 THEN 'service_a'
41    WHEN oom_score_val <  700 THEN 'home'
42    WHEN oom_score_val <  800 THEN 'prev'
43    WHEN oom_score_val <  900 THEN 'service_b'
44    ELSE 'cached'
45  END AS priority,
46  MIN(span.{{table_name}}_val) AS min_value,
47  MAX(span.{{table_name}}_val) AS max_value,
48  SUM(span.{{table_name}}_val * span.dur) / SUM(span.dur) AS avg_value
49FROM {{table_name}}_by_oom_span AS span JOIN process USING(upid)
50WHERE process.name IS NOT NULL
51GROUP BY 1, 2
52ORDER BY 1, 2;
53
54DROP VIEW IF EXISTS {{table_name}}_by_priority_stats_proto;
55CREATE VIEW {{table_name}}_by_priority_stats_proto AS
56SELECT
57  process_name,
58  priority,
59  AndroidMemoryMetric_Counter(
60    'min', min_value,
61    'max', max_value,
62    'avg', avg_value
63  ) AS proto
64FROM {{table_name}}_by_priority_stats;
65