• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 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
16INCLUDE PERFETTO MODULE counters.intervals;
17
18INCLUDE PERFETTO MODULE linux.memory.process;
19
20CREATE PERFETTO TABLE _memory_rss_high_watermark_per_process_table AS
21WITH
22  with_rss AS (
23    SELECT
24      ts,
25      dur,
26      upid,
27      coalesce(file_rss, 0) + coalesce(anon_rss, 0) + coalesce(shmem_rss, 0) AS rss
28    FROM _memory_rss_and_swap_per_process_table
29  ),
30  high_watermark_as_counter AS (
31    SELECT
32      ts,
33      max(rss) OVER (PARTITION BY upid ORDER BY ts) AS value,
34      -- `id` and `track_id` are hacks to use this table in
35      -- `counter_leading_intervals` macro. As `track_id` is using for looking
36      -- for duplicates, we are aliasing `upid` with it. `Id` is ignored by the macro.
37      upid AS track_id,
38      0 AS id
39    FROM with_rss
40  )
41SELECT
42  ts,
43  dur,
44  track_id AS upid,
45  cast_int!(value) AS rss_high_watermark
46FROM counter_leading_intervals!(high_watermark_as_counter);
47
48-- For each process fetches the memory high watermark until or during
49-- timestamp.
50CREATE PERFETTO VIEW memory_rss_high_watermark_per_process (
51  -- Timestamp
52  ts TIMESTAMP,
53  -- Duration
54  dur DURATION,
55  -- Upid of the process
56  upid JOINID(process.id),
57  -- Pid of the process
58  pid LONG,
59  -- Name of the process
60  process_name STRING,
61  -- Maximum `rss` value until now
62  rss_high_watermark LONG
63) AS
64SELECT
65  ts,
66  dur,
67  upid,
68  pid,
69  name AS process_name,
70  rss_high_watermark
71FROM _memory_rss_high_watermark_per_process_table
72JOIN process
73  USING (upid);
74