• 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
17-- Create all the views used to for LMK related stuff.
18CREATE TABLE last_oom_adj(upid BIG INT PRIMARY KEY, ts BIG INT, score INT);
19
20INSERT INTO last_oom_adj
21SELECT upid, ts, score
22FROM (
23  SELECT ref AS upid,
24         ts,
25         CAST(value AS INT) AS score,
26         row_number() OVER (PARTITION BY counter_id ORDER BY ts DESC) AS rank
27  FROM counter_definitions JOIN counter_values USING(counter_id)
28  WHERE name = 'oom_score_adj'
29  AND ref_type = 'upid')
30WHERE rank = 1;
31
32CREATE VIEW lmk_events AS
33SELECT ref AS upid
34FROM instants
35WHERE name = 'mem.lmk' AND ref_type = 'upid';
36
37CREATE VIEW lmk_by_score AS
38SELECT process.name, last_oom_adj.score
39FROM lmk_events
40LEFT JOIN process ON lmk_events.upid = process.upid
41LEFT JOIN last_oom_adj ON lmk_events.upid = last_oom_adj.upid
42ORDER BY lmk_events.upid;
43