• 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 PERFETTO TABLE lmk_events AS
22WITH raw_events AS (
23  SELECT upid, MAX(ts) AS ts
24  FROM instant
25  JOIN process_track ON instant.track_id = process_track.id
26  WHERE instant.name = 'mem.lmk'
27  GROUP BY 1
28)
29SELECT
30  raw_events.ts,
31  raw_events.upid,
32  oom_scores.oom_score_val AS score
33FROM raw_events
34LEFT JOIN oom_score_span oom_scores
35  ON (raw_events.upid = oom_scores.upid
36      AND raw_events.ts >= oom_scores.ts
37      AND raw_events.ts < oom_scores.ts + oom_scores.dur)
38ORDER BY 1;
39
40DROP VIEW IF EXISTS android_lmk_output;
41CREATE PERFETTO VIEW android_lmk_output AS
42WITH lmk_counts AS (
43  SELECT score, COUNT(1) AS count
44  FROM lmk_events
45  GROUP BY score
46)
47SELECT AndroidLmkMetric(
48  'total_count', (SELECT COUNT(1) FROM lmk_events),
49  'by_oom_score', (
50    SELECT
51      RepeatedField(AndroidLmkMetric_ByOomScore(
52        'oom_score_adj', score,
53        'count', count
54      ))
55    FROM lmk_counts
56    WHERE score IS NOT NULL
57  ),
58  'oom_victim_count', (
59    SELECT COUNT(1)
60    FROM instant
61    WHERE name = 'mem.oom_kill'
62  )
63);
64