• 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
17SELECT RUN_METRIC('android/android_ion.sql');
18SELECT RUN_METRIC('android/android_lmk.sql');
19SELECT RUN_METRIC('android/process_mem.sql');
20SELECT RUN_METRIC('android/process_metadata.sql');
21
22DROP VIEW IF EXISTS android_lmk_reason_output;
23CREATE VIEW android_lmk_reason_output AS
24WITH
25total_ion_name AS (
26  SELECT
27  CASE
28    WHEN EXISTS(SELECT TRUE FROM ion_timeline WHERE heap_name = 'all')
29      THEN 'all'
30    ELSE 'system'
31  END AS name
32),
33oom_score_at_lmk_time AS (
34  SELECT
35    lmk_events.ts,
36    oom_score_span.upid,
37    oom_score_val
38  FROM lmk_events
39  JOIN oom_score_span ON (
40    lmk_events.ts
41    BETWEEN oom_score_span.ts
42    AND oom_score_span.ts + MAX(oom_score_span.dur - 1, 0))
43),
44ion_at_lmk_time AS (
45  SELECT
46    lmk_events.ts,
47    CAST(ion_timeline.value AS INT) ion_size
48  FROM lmk_events
49  JOIN ion_timeline ON (
50    lmk_events.ts
51    BETWEEN ion_timeline.ts
52    AND ion_timeline.ts + MAX(ion_timeline.dur - 1, 0))
53  WHERE ion_timeline.heap_name IN (SELECT name FROM total_ion_name)
54),
55lmk_process_sizes AS (
56  SELECT
57    lmk_events.ts,
58    rss_and_swap_span.upid,
59    file_rss_val,
60    anon_rss_val,
61    shmem_rss_val,
62    swap_val,
63    rss_and_swap_val
64  FROM lmk_events
65  JOIN rss_and_swap_span
66  WHERE lmk_events.ts
67    BETWEEN rss_and_swap_span.ts
68    AND rss_and_swap_span.ts + MAX(rss_and_swap_span.dur - 1, 0)
69),
70lmk_process_sizes_output AS (
71  SELECT ts, RepeatedField(AndroidLmkReasonMetric_Process(
72    'process', metadata,
73    'oom_score_adj', oom_score_val,
74    'size', rss_and_swap_val,
75    'file_rss_bytes', file_rss_val,
76    'anon_rss_bytes', anon_rss_val,
77    'shmem_rss_bytes', shmem_rss_val,
78    'swap_bytes', swap_val
79  )) processes
80  FROM lmk_process_sizes
81  JOIN process_metadata USING (upid)
82  LEFT JOIN oom_score_at_lmk_time USING (ts, upid)
83  GROUP BY ts
84)
85SELECT AndroidLmkReasonMetric(
86  'lmks', (
87    SELECT RepeatedField(AndroidLmkReasonMetric_Lmk(
88      'oom_score_adj', oom_score_val,
89      'system_ion_heap_size', ion_size,
90      'ion_heaps_bytes', ion_size,
91      'processes', processes
92    ))
93    FROM lmk_events
94    LEFT JOIN oom_score_at_lmk_time USING (ts, upid)
95    LEFT JOIN ion_at_lmk_time USING (ts)
96    LEFT JOIN lmk_process_sizes_output USING (ts)
97    WHERE oom_score_val IS NOT NULL
98    ORDER BY ts
99  )
100);
101