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