• 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/process_oom_score.sql');
18
19-- All LMK events ordered by timestamp
20CREATE TABLE IF NOT EXISTS lmk_events AS
21WITH raw_events AS (
22  SELECT ref AS upid, MIN(ts) AS ts
23  FROM instants
24  WHERE name = 'mem.lmk' AND ref_type = 'upid'
25  GROUP BY 1
26)
27SELECT
28  raw_events.ts,
29  raw_events.upid,
30  oom_scores.oom_score_val AS score
31FROM raw_events
32LEFT JOIN oom_score_span oom_scores
33  ON (raw_events.upid = oom_scores.upid AND
34      raw_events.ts >= oom_scores.ts AND
35      raw_events.ts < oom_scores.ts + oom_scores.dur)
36ORDER BY 1;
37
38CREATE VIEW IF NOT EXISTS android_lmk_annotations AS
39WITH raw_events AS (
40  SELECT
41    ts,
42    LEAD(ts) OVER (ORDER BY ts) - ts AS dur,
43    value AS tid
44  FROM counter c
45  JOIN counter_track t ON t.id = c.track_id
46  WHERE t.name = 'kill_one_process'
47),
48lmks_with_proc_name AS (
49  SELECT
50    *,
51    process.name as process_name
52  FROM raw_events
53  LEFT JOIN thread ON
54    thread.tid = raw_events.tid AND
55    raw_events.ts BETWEEN thread.start_ts AND thread.end_ts
56  LEFT JOIN process USING(upid)
57  WHERE raw_events.tid != 0
58)
59SELECT
60  'slice' as track_type,
61  'Low Memory Kills (LMKs)' as track_name,
62  ts,
63  dur,
64  CASE
65    WHEN process_name IS NULL THEN printf('Process %d', lmk.pid)
66    ELSE printf('%s (pid: %d)', process_name, lmk.pid)
67  END AS slice_name
68FROM lmks_with_proc_name as lmk;
69
70CREATE VIEW IF NOT EXISTS android_lmk_output AS
71WITH lmk_counts AS (
72  SELECT score, COUNT(1) AS count
73  FROM lmk_events
74  GROUP BY score
75)
76SELECT AndroidLmkMetric(
77  'total_count', (SELECT COUNT(1) FROM lmk_events),
78  'by_oom_score', (
79    SELECT
80      RepeatedField(AndroidLmkMetric_ByOomScore(
81        'oom_score_adj', score,
82        'count', count
83      ))
84    FROM lmk_counts
85    WHERE score IS NOT NULL
86  ),
87  'oom_victim_count', (
88    SELECT COUNT(1) FROM instants WHERE name = 'mem.oom_kill'
89  )
90);
91