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