• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2025 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
17CREATE PERFETTO TABLE _show_maps AS
18SELECT
19  id,
20  -- There is a variable number of spaces between show map columns so that the text is
21  -- aligned. This makes it difficult to extract the column values. So we first convert
22  -- to CSV format by replacing two spaces with one space 5 times before replacing a
23  -- space with a comma. This is sufficient to reduce the the variable number of spaces to
24  -- CSV.
25  replace(
26    replace(replace(replace(replace(trim(line), '  ', ' '), '  ', ' '), '  ', ' '), '  ', ' '),
27    ' ',
28    ','
29  ) AS line,
30  section
31FROM android_dumpstate
32WHERE
33  section GLOB 'SHOW MAP*';
34
35CREATE PERFETTO TABLE _show_maps_process AS
36SELECT
37  *,
38  CAST(replace(str_split(section, ' ', 2), ':', '') AS INTEGER) AS pid,
39  trim(str_split(section, ' ', 3)) AS process_name,
40  lead(id) OVER (ORDER BY id) AS next_id
41FROM _show_maps
42WHERE
43  trim(line) GLOB 'virtual*shared*shared*private*private*Anon*Shmem*File*Shared*Private*'
44GROUP BY
45  section;
46
47CREATE PERFETTO TABLE _show_maps_process_boundary AS
48SELECT
49  s.*,
50  process_name,
51  pid
52FROM _show_maps AS s
53JOIN _show_maps_process AS p
54  ON s.id BETWEEN p.id AND p.next_id;
55
56-- This table represents memory mapping information from /proc/[pid]/smaps
57-- All memory values are in kilobytes (KB)
58CREATE PERFETTO TABLE android_dumpsys_show_map (
59  -- Name of the process.
60  process_name STRING,
61  -- Process ID.
62  pid JOINID(process.pid),
63  -- Virtual Set Size in kilobytes - total virtual memory mapped by the process.
64  vss_kb LONG,
65  -- Resident Set Size in kilobytes - actual physical memory used by the process.
66  rss_kb LONG,
67  -- Proportional Set Size in kilobytes - amount of memory shared with other processes.
68  pss_kb LONG,
69  -- Clean shared pages in kilobytes - shared pages that haven't been modified.
70  shared_clean_kb LONG,
71  -- Dirty shared pages in kilobytes - shared pages that have been modified.
72  shared_dirty_kb LONG,
73  -- Clean private pages in kilobytes - private pages that haven't been modified.
74  private_clean_kb LONG,
75  -- Dirty private pages in kilobytes - private pages that have been modified.
76  private_dirty_kb LONG,
77  -- Swap memory in kilobytes - memory that has been moved to swap space.
78  swap_kb LONG,
79  -- Proportional Swap Size in kilobytes - swap shared with other processes.
80  swap_pss_kb LONG,
81  -- Anonymous huge pages in kilobytes - large anonymous memory regions.
82  anon_huge_pages_kb LONG,
83  -- Shared Memory PMD mapped in kilobytes - page middle directory mapped shared memory.
84  shmem_pmd_mapped_kb LONG,
85  -- File PMD mapped in kilobytes - page middle directory mapped file memory.
86  file_pmd_mapped_kb LONG,
87  -- Shared huge TLB in kilobytes - shared huge page table entries.
88  shared_huge_tlb_kb LONG,
89  -- Private huge TLB in kilobytes - private huge page table entries.
90  private_hugetlb_kb LONG,
91  -- Locked memory in kilobytes - memory that can't be swapped out.
92  locked_kb LONG,
93  -- Number of mappings of the object.
94  mapping_count LONG,
95  -- Path to the mapped object (file, library, etc.).
96  mapped_object STRING
97) AS
98SELECT
99  process_name,
100  pid,
101  CAST(str_split(line, ',', 0) AS INTEGER) AS vss_kb,
102  CAST(str_split(line, ',', 1) AS INTEGER) AS rss_kb,
103  CAST(str_split(line, ',', 2) AS INTEGER) AS pss_kb,
104  CAST(str_split(line, ',', 3) AS INTEGER) AS shared_clean_kb,
105  CAST(str_split(line, ',', 4) AS INTEGER) AS shared_dirty_kb,
106  CAST(str_split(line, ',', 5) AS INTEGER) AS private_clean_kb,
107  CAST(str_split(line, ',', 6) AS INTEGER) AS private_dirty_kb,
108  CAST(str_split(line, ',', 7) AS INTEGER) AS swap_kb,
109  CAST(str_split(line, ',', 8) AS INTEGER) AS swap_pss_kb,
110  CAST(str_split(line, ',', 9) AS INTEGER) AS anon_huge_pages_kb,
111  CAST(str_split(line, ',', 10) AS INTEGER) AS shmem_pmd_mapped_kb,
112  CAST(str_split(line, ',', 11) AS INTEGER) AS file_pmd_mapped_kb,
113  CAST(str_split(line, ',', 12) AS INTEGER) AS shared_huge_tlb_kb,
114  CAST(str_split(line, ',', 13) AS INTEGER) AS private_hugetlb_kb,
115  CAST(str_split(line, ',', 14) AS INTEGER) AS locked_kb,
116  CAST(str_split(line, ',', 15) AS INTEGER) AS mapping_count,
117  str_split(line, ',', 16) AS mapped_object
118FROM _show_maps_process_boundary
119WHERE
120  -- Check if the row starts with a number which means it's not a delimeter or header
121  -- Also exclude TOTAL since this can be computed from the table and could yield
122  -- wrong results if summing pss for instance over a process.
123  substr(trim(line), 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
124  AND str_split(line, ',', 16) != 'TOTAL';
125