tp: move memory modules to linux and android packages

Change-Id: I874544a26f0ec6d85ac1fa3137ecbb551e09796a
diff --git a/Android.bp b/Android.bp
index de5c166..cf5c783 100644
--- a/Android.bp
+++ b/Android.bp
@@ -13113,10 +13113,12 @@
         "src/trace_processor/perfetto_sql/stdlib/android/frames/timeline_maxsdk28.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/freezer.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/garbage_collection.sql",
+        "src/trace_processor/perfetto_sql/stdlib/android/gpu/memory.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/input.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/io.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/job_scheduler.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/memory/heap_graph/dominator_tree.sql",
+        "src/trace_processor/perfetto_sql/stdlib/android/memory/process.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/monitor_contention.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/network_packets.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/oom_adjuster.sql",
@@ -13163,10 +13165,9 @@
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/process.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/thread.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/general.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/high_watermark.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/process.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/general.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql",
         "src/trace_processor/perfetto_sql/stdlib/pkvm/hypervisor.sql",
         "src/trace_processor/perfetto_sql/stdlib/prelude/casts.sql",
         "src/trace_processor/perfetto_sql/stdlib/prelude/slices.sql",
diff --git a/BUILD b/BUILD
index 6608e3d..c4795a4 100644
--- a/BUILD
+++ b/BUILD
@@ -2515,6 +2515,14 @@
     ],
 )
 
+# GN target: //src/trace_processor/perfetto_sql/stdlib/android/gpu:gpu
+perfetto_filegroup(
+    name = "src_trace_processor_perfetto_sql_stdlib_android_gpu_gpu",
+    srcs = [
+        "src/trace_processor/perfetto_sql/stdlib/android/gpu/memory.sql",
+    ],
+)
+
 # GN target: //src/trace_processor/perfetto_sql/stdlib/android/memory/heap_graph:heap_graph
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_android_memory_heap_graph_heap_graph",
@@ -2526,6 +2534,9 @@
 # GN target: //src/trace_processor/perfetto_sql/stdlib/android/memory:memory
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_android_memory_memory",
+    srcs = [
+        "src/trace_processor/perfetto_sql/stdlib/android/memory/process.sql",
+    ],
 )
 
 # GN target: //src/trace_processor/perfetto_sql/stdlib/android/startup:startup
@@ -2677,34 +2688,21 @@
     ],
 )
 
+# GN target: //src/trace_processor/perfetto_sql/stdlib/linux/memory:memory
+perfetto_filegroup(
+    name = "src_trace_processor_perfetto_sql_stdlib_linux_memory_memory",
+    srcs = [
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/general.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql",
+    ],
+)
+
 # GN target: //src/trace_processor/perfetto_sql/stdlib/linux:linux
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_linux_linux",
 )
 
-# GN target: //src/trace_processor/perfetto_sql/stdlib/memory/android:android
-perfetto_filegroup(
-    name = "src_trace_processor_perfetto_sql_stdlib_memory_android_android",
-    srcs = [
-        "src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql",
-    ],
-)
-
-# GN target: //src/trace_processor/perfetto_sql/stdlib/memory/linux:linux
-perfetto_filegroup(
-    name = "src_trace_processor_perfetto_sql_stdlib_memory_linux_linux",
-    srcs = [
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/general.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/high_watermark.sql",
-        "src/trace_processor/perfetto_sql/stdlib/memory/linux/process.sql",
-    ],
-)
-
-# GN target: //src/trace_processor/perfetto_sql/stdlib/memory:memory
-perfetto_filegroup(
-    name = "src_trace_processor_perfetto_sql_stdlib_memory_memory",
-)
-
 # GN target: //src/trace_processor/perfetto_sql/stdlib/pkvm:pkvm
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_pkvm_pkvm",
@@ -2817,6 +2815,7 @@
         ":src_trace_processor_perfetto_sql_stdlib_android_android",
         ":src_trace_processor_perfetto_sql_stdlib_android_auto_auto",
         ":src_trace_processor_perfetto_sql_stdlib_android_frames_frames",
+        ":src_trace_processor_perfetto_sql_stdlib_android_gpu_gpu",
         ":src_trace_processor_perfetto_sql_stdlib_android_memory_heap_graph_heap_graph",
         ":src_trace_processor_perfetto_sql_stdlib_android_memory_memory",
         ":src_trace_processor_perfetto_sql_stdlib_android_startup_startup",
@@ -2832,9 +2831,7 @@
         ":src_trace_processor_perfetto_sql_stdlib_linux_cpu_cpu",
         ":src_trace_processor_perfetto_sql_stdlib_linux_cpu_utilization_utilization",
         ":src_trace_processor_perfetto_sql_stdlib_linux_linux",
-        ":src_trace_processor_perfetto_sql_stdlib_memory_android_android",
-        ":src_trace_processor_perfetto_sql_stdlib_memory_linux_linux",
-        ":src_trace_processor_perfetto_sql_stdlib_memory_memory",
+        ":src_trace_processor_perfetto_sql_stdlib_linux_memory_memory",
         ":src_trace_processor_perfetto_sql_stdlib_pkvm_pkvm",
         ":src_trace_processor_perfetto_sql_stdlib_prelude_prelude",
         ":src_trace_processor_perfetto_sql_stdlib_sched_sched",
diff --git a/CHANGELOG b/CHANGELOG
index cc973ac..3784afe 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,10 +14,16 @@
       reason as above.
     * Moved `cpu.idle` module to `linux.cpu.idle` for the same
       reason as above.
-    * Moved `linux.cpu_idle` to `linux.cpu.idle` to make it
+    * Moved content of `linux.cpu_idle` into `linux.cpu.idle` to make it
       consistent with above changes.
+    * Moved `memory.android.gpu` to `android.memory.gpu`  to make it consistent
+      with above changes.`
+    * Moved contents of `memory.linux.process` to `linux.memory.process` and
+      `android.memory.process` to make it consistent with above changes.
+    * Moved `memory.linux.high_watermark` to `linux.memory.high_watermark` to
+      make it consistent with above changes.
     * Moved `memory.heap_graph_dominator_tree` to
-      `android.memory.heap_graph.dominator_tree`. This is to prepare for the
+      `android.memory.heap_graph.dominator_tree`. This is to allow for the
       addition of more modules related to heap graphs.
   Trace Processor:
     *
diff --git a/python/generators/sql_processing/utils.py b/python/generators/sql_processing/utils.py
index 1bd5f3e..567e888 100644
--- a/python/generators/sql_processing/utils.py
+++ b/python/generators/sql_processing/utils.py
@@ -108,7 +108,7 @@
 }
 
 ALLOWED_PREFIXES = {
-    'android': ['heap_graph'],
+    'android': ['heap_graph', 'memory'],
     'counters': ['counter'],
     'chrome/util': ['cr'],
     'intervals': ['interval'],
diff --git a/src/trace_processor/metrics/sql/android/process_mem.sql b/src/trace_processor/metrics/sql/android/process_mem.sql
index f3b1c88..4622462 100644
--- a/src/trace_processor/metrics/sql/android/process_mem.sql
+++ b/src/trace_processor/metrics/sql/android/process_mem.sql
@@ -14,7 +14,8 @@
 -- limitations under the License.
 --
 
-INCLUDE PERFETTO MODULE memory.linux.process;
+INCLUDE PERFETTO MODULE android.memory.process;
+INCLUDE PERFETTO MODULE linux.memory.process;
 
 SELECT RUN_METRIC('android/process_oom_score.sql');
 
diff --git a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
index 9441df6..0e7c5ad 100644
--- a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
@@ -29,7 +29,6 @@
     "graphs",
     "intervals",
     "linux",
-    "memory",
     "pkvm",
     "prelude",
     "sched",
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/android/BUILD.gn
index ce4fe77..b1266c0 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/android/BUILD.gn
@@ -18,6 +18,7 @@
   deps = [
     "auto",
     "frames",
+    "gpu",
     "memory",
     "startup",
     "winscope",
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/android/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/android/gpu/BUILD.gn
similarity index 90%
rename from src/trace_processor/perfetto_sql/stdlib/memory/android/BUILD.gn
rename to src/trace_processor/perfetto_sql/stdlib/android/gpu/BUILD.gn
index 55123b6..eb757d2 100644
--- a/src/trace_processor/perfetto_sql/stdlib/memory/android/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/android/gpu/BUILD.gn
@@ -14,6 +14,6 @@
 
 import("../../../../../../gn/perfetto_sql.gni")
 
-perfetto_sql_source_set("android") {
-  sources = [ "gpu.sql" ]
+perfetto_sql_source_set("gpu") {
+  sources = [ "memory.sql" ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql b/src/trace_processor/perfetto_sql/stdlib/android/gpu/memory.sql
similarity index 77%
rename from src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql
rename to src/trace_processor/perfetto_sql/stdlib/android/gpu/memory.sql
index 39abaec..3eb8e11 100644
--- a/src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/android/gpu/memory.sql
@@ -13,18 +13,18 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
-INCLUDE PERFETTO MODULE memory.linux.general;
+INCLUDE PERFETTO MODULE linux.memory.general;
 
 -- Counter for GPU memory per process with duration.
-CREATE PERFETTO TABLE memory_gpu_per_process(
-    -- Timestamp
-    ts INT,
-    -- Duration
-    dur INT,
-    -- Upid of the process
-    upid INT,
-    -- GPU memory
-    gpu_memory INT
+CREATE PERFETTO TABLE android_gpu_memory_per_process(
+  -- Timestamp
+  ts INT,
+  -- Duration
+  dur INT,
+  -- Upid of the process
+  upid INT,
+  -- GPU memory
+  gpu_memory INT
 ) AS
 SELECT
   ts,
@@ -32,4 +32,4 @@
   upid,
   cast_int!(value) AS gpu_memory
 FROM _all_counters_per_process
-WHERE name = 'GPU Memory';
\ No newline at end of file
+WHERE name = 'GPU Memory';
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/memory/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/android/memory/BUILD.gn
index c308bcd..e6555fc 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/memory/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/android/memory/BUILD.gn
@@ -16,5 +16,5 @@
 
 perfetto_sql_source_set("memory") {
   deps = [ "heap_graph" ]
-  sources = []
+  sources = [ "process.sql" ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/memory/process.sql b/src/trace_processor/perfetto_sql/stdlib/android/memory/process.sql
new file mode 100644
index 0000000..efa56e1
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/android/memory/process.sql
@@ -0,0 +1,99 @@
+--
+-- Copyright 2024 The Android Open Source Project
+--
+-- Licensed under the Apache License, Version 2.0 (the 'License');
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an 'AS IS' BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+INCLUDE PERFETTO MODULE android.oom_adjuster;
+INCLUDE PERFETTO MODULE linux.memory.process;
+
+-- OOM score tables
+
+CREATE VIRTUAL TABLE _mem_ooms_sj
+USING SPAN_OUTER_JOIN(
+  android_oom_adj_intervals PARTITIONED upid,
+  _memory_rss_and_swap_per_process_table PARTITIONED upid);
+
+-- Process memory and it's OOM adjuster scores. Detects transitions, each new
+-- interval means that either the memory or OOM adjuster score of the process changed.
+CREATE PERFETTO TABLE memory_oom_score_with_rss_and_swap_per_process(
+  -- Timestamp the oom_adj score or memory of the process changed
+  ts INT,
+  -- Duration until the next oom_adj score or memory change of the process.
+  dur INT,
+  -- oom adjuster score of the process.
+  score INT,
+  -- oom adjuster bucket of the process.
+  bucket STRING,
+  -- Upid of the process having an oom_adj update.
+  upid INT,
+  -- Name of the process having an oom_adj update.
+  process_name STRING,
+  -- Pid of the process having an oom_adj update.
+  pid INT,
+  -- Slice of the latest oom_adj update in the system_server. Alias of
+  -- `slice.id`.
+  oom_adj_id INT,
+  -- Timestamp of the latest oom_adj update in the system_server.
+  oom_adj_ts INT,
+  -- Duration of the latest oom_adj update in the system_server.
+  oom_adj_dur INT,
+  -- Track of the latest oom_adj update in the system_server. Alias of
+  -- `track.id`.
+  oom_adj_track_id INT,
+  -- Thread name of the latest oom_adj update in the system_server.
+  oom_adj_thread_name STRING,
+  -- Reason for the latest oom_adj update in the system_server.
+  oom_adj_reason STRING,
+  -- Trigger for the latest oom_adj update in the system_server.
+  oom_adj_trigger STRING,
+  -- Anon RSS counter value
+  anon_rss INT,
+  -- File RSS counter value
+  file_rss INT,
+  -- Shared memory RSS counter value
+  shmem_rss INT,
+  -- Total RSS value. Sum of `anon_rss`, `file_rss` and `shmem_rss`. Returns
+  -- value even if one of the values is NULL.
+  rss INT,
+  -- Swap counter value
+  swap INT,
+  -- Sum or `anon_rss` and `swap`. Returns value even if one of the values is
+  -- NULL.
+  anon_rss_and_swap INT,
+  -- Sum or `rss` and `swap`. Returns value even if one of the values is NULL.
+  rss_and_swap INT
+) AS
+SELECT
+  ts,
+  dur,
+  score,
+  bucket,
+  upid,
+  process_name,
+  pid,
+  oom_adj_id,
+  oom_adj_ts,
+  oom_adj_dur,
+  oom_adj_track_id,
+  oom_adj_thread_name,
+  oom_adj_reason,
+  oom_adj_trigger,
+  anon_rss,
+  file_rss,
+  shmem_rss,
+  file_rss + anon_rss + COALESCE(shmem_rss, 0) AS rss,
+  swap,
+  anon_rss + COALESCE(swap, 0) AS anon_rss_and_swap,
+  anon_rss + file_rss  + COALESCE(shmem_rss, 0) + COALESCE(swap, 0) AS rss_and_swap
+FROM _mem_ooms_sj
+JOIN process USING (upid);
diff --git a/src/trace_processor/perfetto_sql/stdlib/gpu/frequency.sql b/src/trace_processor/perfetto_sql/stdlib/gpu/frequency.sql
index 2bd87b2..d1aaaa5 100644
--- a/src/trace_processor/perfetto_sql/stdlib/gpu/frequency.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/gpu/frequency.sql
@@ -39,4 +39,4 @@
     ON t.id = c.track_id AND t.name = 'gpufreq'
     WHERE gpu_id IS NOT NULL
 ))
-JOIN gpu_counter_track t ON t.id = track_id;
\ No newline at end of file
+JOIN gpu_counter_track t ON t.id = track_id;
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
index 7014a70..7c4dd47 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
@@ -16,5 +16,8 @@
 
 perfetto_sql_source_set("linux") {
   sources = []
-  deps = [ "cpu" ]
+  deps = [
+    "cpu",
+    "memory",
+  ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/linux/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/linux/memory/BUILD.gn
similarity index 95%
rename from src/trace_processor/perfetto_sql/stdlib/memory/linux/BUILD.gn
rename to src/trace_processor/perfetto_sql/stdlib/linux/memory/BUILD.gn
index 0711197..050d387 100644
--- a/src/trace_processor/perfetto_sql/stdlib/memory/linux/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/memory/BUILD.gn
@@ -14,7 +14,7 @@
 
 import("../../../../../../gn/perfetto_sql.gni")
 
-perfetto_sql_source_set("linux") {
+perfetto_sql_source_set("memory") {
   sources = [
     "general.sql",
     "high_watermark.sql",
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/linux/general.sql b/src/trace_processor/perfetto_sql/stdlib/linux/memory/general.sql
similarity index 100%
rename from src/trace_processor/perfetto_sql/stdlib/memory/linux/general.sql
rename to src/trace_processor/perfetto_sql/stdlib/linux/memory/general.sql
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/linux/high_watermark.sql b/src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql
similarity index 97%
rename from src/trace_processor/perfetto_sql/stdlib/memory/linux/high_watermark.sql
rename to src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql
index b01f2df..b43a75c 100644
--- a/src/trace_processor/perfetto_sql/stdlib/memory/linux/high_watermark.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql
@@ -13,8 +13,8 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
-INCLUDE PERFETTO MODULE memory.linux.process;
 INCLUDE PERFETTO MODULE counters.intervals;
+INCLUDE PERFETTO MODULE linux.memory.process;
 
 CREATE PERFETTO TABLE _memory_rss_high_watermark_per_process_table AS
 WITH with_rss AS (
@@ -64,4 +64,4 @@
     name AS process_name,
     rss_high_watermark
 FROM _memory_rss_high_watermark_per_process_table
-JOIN process USING (upid);
\ No newline at end of file
+JOIN process USING (upid);
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql b/src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql
new file mode 100644
index 0000000..771843c
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql
@@ -0,0 +1,134 @@
+--
+-- Copyright 2024 The Android Open Source Project
+--
+-- Licensed under the Apache License, Version 2.0 (the 'License');
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an 'AS IS' BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+INCLUDE PERFETTO MODULE linux.memory.general;
+
+-- All memory counters tables.
+
+CREATE PERFETTO VIEW _anon_rss AS
+SELECT
+  ts,
+  dur,
+  upid,
+  value AS anon_rss_val
+FROM _all_counters_per_process
+WHERE name = 'mem.rss.anon';
+
+CREATE PERFETTO VIEW _file_rss AS
+SELECT
+  ts,
+  dur,
+  upid,
+  value AS file_rss_val
+FROM _all_counters_per_process
+WHERE name = 'mem.rss.file';
+
+CREATE PERFETTO VIEW _shmem_rss AS
+SELECT
+  ts,
+  dur,
+  upid,
+  value AS shmem_rss_val
+FROM _all_counters_per_process
+WHERE name = 'mem.rss.shmem';
+
+CREATE PERFETTO VIEW _swap AS
+SELECT
+  ts,
+  dur,
+  upid,
+  value AS swap_val
+FROM _all_counters_per_process
+WHERE name = 'mem.swap';
+
+-- Span joins
+
+CREATE VIRTUAL TABLE _anon_swap_sj
+USING SPAN_OUTER_JOIN(
+  _anon_rss PARTITIONED upid,
+  _swap PARTITIONED upid);
+
+CREATE VIRTUAL TABLE _anon_swap_file_sj
+USING SPAN_OUTER_JOIN(
+  _anon_swap_sj PARTITIONED upid,
+  _file_rss PARTITIONED upid
+);
+
+CREATE VIRTUAL TABLE _rss_swap_sj
+USING SPAN_OUTER_JOIN(
+  _anon_swap_file_sj PARTITIONED upid,
+  _shmem_rss PARTITIONED upid
+);
+
+CREATE PERFETTO TABLE _memory_rss_and_swap_per_process_table AS
+SELECT
+  ts, dur, upid,
+  cast_int!(anon_rss_val) AS anon_rss,
+  cast_int!(file_rss_val) AS file_rss,
+  cast_int!(shmem_rss_val) AS shmem_rss,
+  cast_int!(swap_val) AS swap
+FROM _rss_swap_sj;
+
+
+-- Memory metrics timeline for each process.
+CREATE PERFETTO VIEW memory_rss_and_swap_per_process(
+  -- Timestamp
+  ts INT,
+  -- Duration
+  dur INT,
+  -- Upid of the process
+  upid INT,
+  -- Pid of the process
+  pid INT,
+  -- Name of the process
+  process_name STRING,
+  -- Anon RSS counter value
+  anon_rss INT,
+  -- File RSS counter value
+  file_rss INT,
+  -- Shared memory RSS counter value
+  shmem_rss INT,
+  -- Total RSS value. Sum of `anon_rss`, `file_rss` and `shmem_rss`. Returns
+  -- value even if one of the values is NULL.
+  rss INT,
+  -- Swap counter value
+  swap INT,
+  -- Sum or `anon_rss` and `swap`. Returns value even if one of the values is
+  -- NULL.
+  anon_rss_and_swap INT,
+  -- Sum or `rss` and `swap`. Returns value even if one of the values is NULL.
+  rss_and_swap INT
+) AS
+SELECT
+  ts,
+  dur,
+  upid,
+  pid,
+  name AS process_name,
+  anon_rss,
+  file_rss,
+  shmem_rss,
+  -- We do COALESCE only on `shmem_rss` and `swap`, as it can be expected all
+  -- process start to emit anon rss and file rss events (you'll need to at
+  -- least read code and have some memory to work with) - so the NULLs are real
+  --  values. But it is possible that you will never swap or never use shmem,
+  -- so those values are expected to often be NULLs, which shouldn't propagate
+  -- into the values like `anon_and_swap` or `rss`.
+  file_rss + anon_rss + COALESCE(shmem_rss, 0) AS rss,
+  swap,
+  anon_rss + COALESCE(swap, 0) AS anon_rss_and_swap,
+  anon_rss + file_rss  + COALESCE(shmem_rss, 0) + COALESCE(swap, 0) AS rss_and_swap
+FROM _memory_rss_and_swap_per_process_table
+JOIN process USING (upid);
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/memory/BUILD.gn
deleted file mode 100644
index 44a3fe1..0000000
--- a/src/trace_processor/perfetto_sql/stdlib/memory/BUILD.gn
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright (C) 2024 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import("../../../../../gn/perfetto_sql.gni")
-
-perfetto_sql_source_set("memory") {
-  deps = [
-    "android",
-    "linux",
-  ]
-  sources = []
-}
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/linux/process.sql b/src/trace_processor/perfetto_sql/stdlib/memory/linux/process.sql
deleted file mode 100644
index 4601c21..0000000
--- a/src/trace_processor/perfetto_sql/stdlib/memory/linux/process.sql
+++ /dev/null
@@ -1,217 +0,0 @@
---
--- Copyright 2024 The Android Open Source Project
---
--- Licensed under the Apache License, Version 2.0 (the 'License');
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
---     https://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an 'AS IS' BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
-
-INCLUDE PERFETTO MODULE android.oom_adjuster;
-INCLUDE PERFETTO MODULE memory.linux.general;
-
--- All memory counters tables.
-
-CREATE PERFETTO VIEW _anon_rss AS
-SELECT
-  ts,
-  dur,
-  upid,
-  value AS anon_rss_val
-FROM _all_counters_per_process
-WHERE name = 'mem.rss.anon';
-
-CREATE PERFETTO VIEW _file_rss AS
-SELECT
-  ts,
-  dur,
-  upid,
-  value AS file_rss_val
-FROM _all_counters_per_process
-WHERE name = 'mem.rss.file';
-
-CREATE PERFETTO VIEW _shmem_rss AS
-SELECT
-  ts,
-  dur,
-  upid,
-  value AS shmem_rss_val
-FROM _all_counters_per_process
-WHERE name = 'mem.rss.shmem';
-
-CREATE PERFETTO VIEW _swap AS
-SELECT
-  ts,
-  dur,
-  upid,
-  value AS swap_val
-FROM _all_counters_per_process
-WHERE name = 'mem.swap';
-
--- Span joins
-
-CREATE VIRTUAL TABLE _anon_swap_sj
-USING SPAN_OUTER_JOIN(
-  _anon_rss PARTITIONED upid,
-  _swap PARTITIONED upid);
-
-CREATE VIRTUAL TABLE _anon_swap_file_sj
-USING SPAN_OUTER_JOIN(
-  _anon_swap_sj PARTITIONED upid,
-  _file_rss PARTITIONED upid
-);
-
-CREATE VIRTUAL TABLE _rss_swap_sj
-USING SPAN_OUTER_JOIN(
-  _anon_swap_file_sj PARTITIONED upid,
-  _shmem_rss PARTITIONED upid
-);
-
-CREATE PERFETTO TABLE _memory_rss_and_swap_per_process_table AS
-SELECT
-  ts, dur, upid,
-  cast_int!(anon_rss_val) AS anon_rss,
-  cast_int!(file_rss_val) AS file_rss,
-  cast_int!(shmem_rss_val) AS shmem_rss,
-  cast_int!(swap_val) AS swap
-FROM _rss_swap_sj;
-
-
--- Memory metrics timeline for each process.
-CREATE PERFETTO VIEW memory_rss_and_swap_per_process(
-  -- Timestamp
-  ts INT,
-  -- Duration
-  dur INT,
-  -- Upid of the process
-  upid INT,
-  -- Pid of the process
-  pid INT,
-  -- Name of the process
-  process_name STRING,
-  -- Anon RSS counter value
-  anon_rss INT,
-  -- File RSS counter value
-  file_rss INT,
-  -- Shared memory RSS counter value
-  shmem_rss INT,
-  -- Total RSS value. Sum of `anon_rss`, `file_rss` and `shmem_rss`. Returns
-  -- value even if one of the values is NULL.
-  rss INT,
-  -- Swap counter value
-  swap INT,
-  -- Sum or `anon_rss` and `swap`. Returns value even if one of the values is
-  -- NULL.
-  anon_rss_and_swap INT,
-  -- Sum or `rss` and `swap`. Returns value even if one of the values is NULL.
-  rss_and_swap INT
-) AS
-SELECT
-  ts,
-  dur,
-  upid,
-  pid,
-  name AS process_name,
-  anon_rss,
-  file_rss,
-  shmem_rss,
-  -- We do COALESCE only on `shmem_rss` and `swap`, as it can be expected all
-  -- process start to emit anon rss and file rss events (you'll need to at
-  -- least read code and have some memory to work with) - so the NULLs are real
-  --  values. But it is possible that you will never swap or never use shmem,
-  -- so those values are expected to often be NULLs, which shouldn't propagate
-  -- into the values like `anon_and_swap` or `rss`.
-  file_rss + anon_rss + COALESCE(shmem_rss, 0) AS rss,
-  swap,
-  anon_rss + COALESCE(swap, 0) AS anon_rss_and_swap,
-  anon_rss + file_rss  + COALESCE(shmem_rss, 0) + COALESCE(swap, 0) AS rss_and_swap
-FROM _memory_rss_and_swap_per_process_table
-JOIN process USING (upid);
-
--- OOM score tables
-
-CREATE VIRTUAL TABLE _mem_ooms_sj
-USING SPAN_OUTER_JOIN(
-  android_oom_adj_intervals PARTITIONED upid,
-  _memory_rss_and_swap_per_process_table PARTITIONED upid);
-
--- Process memory and it's OOM adjuster scores. Detects transitions, each new
--- interval means that either the memory or OOM adjuster score of the process changed.
-CREATE PERFETTO TABLE memory_oom_score_with_rss_and_swap_per_process(
-  -- Timestamp the oom_adj score or memory of the process changed
-  ts INT,
-  -- Duration until the next oom_adj score or memory change of the process.
-  dur INT,
-  -- oom adjuster score of the process.
-  score INT,
-  -- oom adjuster bucket of the process.
-  bucket STRING,
-  -- Upid of the process having an oom_adj update.
-  upid INT,
-  -- Name of the process having an oom_adj update.
-  process_name STRING,
-  -- Pid of the process having an oom_adj update.
-  pid INT,
-  -- Slice of the latest oom_adj update in the system_server. Alias of
-  -- `slice.id`.
-  oom_adj_id INT,
-  -- Timestamp of the latest oom_adj update in the system_server.
-  oom_adj_ts INT,
-  -- Duration of the latest oom_adj update in the system_server.
-  oom_adj_dur INT,
-  -- Track of the latest oom_adj update in the system_server. Alias of
-  -- `track.id`.
-  oom_adj_track_id INT,
-  -- Thread name of the latest oom_adj update in the system_server.
-  oom_adj_thread_name STRING,
-  -- Reason for the latest oom_adj update in the system_server.
-  oom_adj_reason STRING,
-  -- Trigger for the latest oom_adj update in the system_server.
-  oom_adj_trigger STRING,
-  -- Anon RSS counter value
-  anon_rss INT,
-  -- File RSS counter value
-  file_rss INT,
-  -- Shared memory RSS counter value
-  shmem_rss INT,
-  -- Total RSS value. Sum of `anon_rss`, `file_rss` and `shmem_rss`. Returns
-  -- value even if one of the values is NULL.
-  rss INT,
-  -- Swap counter value
-  swap INT,
-  -- Sum or `anon_rss` and `swap`. Returns value even if one of the values is
-  -- NULL.
-  anon_rss_and_swap INT,
-  -- Sum or `rss` and `swap`. Returns value even if one of the values is NULL.
-  rss_and_swap INT
-) AS
-SELECT
-  ts,
-  dur,
-  score,
-  bucket,
-  upid,
-  process_name,
-  pid,
-  oom_adj_id,
-  oom_adj_ts,
-  oom_adj_dur,
-  oom_adj_track_id,
-  oom_adj_thread_name,
-  oom_adj_reason,
-  oom_adj_trigger,
-  anon_rss,
-  file_rss,
-  shmem_rss,
-  file_rss + anon_rss + COALESCE(shmem_rss, 0) AS rss,
-  swap,
-  anon_rss + COALESCE(swap, 0) AS anon_rss_and_swap,
-  anon_rss + file_rss  + COALESCE(shmem_rss, 0) + COALESCE(swap, 0) AS rss_and_swap
-FROM _mem_ooms_sj
-JOIN process USING (upid);
diff --git a/test/trace_processor/diff_tests/include_index.py b/test/trace_processor/diff_tests/include_index.py
index 8201fad..8149ea9 100644
--- a/test/trace_processor/diff_tests/include_index.py
+++ b/test/trace_processor/diff_tests/include_index.py
@@ -102,6 +102,8 @@
 from diff_tests.stdlib.android.frames_tests import Frames
 from diff_tests.stdlib.android.startups_tests import Startups
 from diff_tests.stdlib.android.tests import AndroidStdlib
+from diff_tests.stdlib.android.gpu import AndroidGpu
+from diff_tests.stdlib.android.memory import AndroidMemory
 from diff_tests.stdlib.chrome.chrome_stdlib_testsuites import CHROME_STDLIB_TESTSUITES
 from diff_tests.stdlib.common.tests import StdlibCommon
 from diff_tests.stdlib.common.tests import StdlibCommon
@@ -115,8 +117,8 @@
 from diff_tests.stdlib.intervals.intersect_tests import IntervalsIntersect
 from diff_tests.stdlib.intervals.tests import StdlibIntervals
 from diff_tests.stdlib.linux.cpu import LinuxCpu
+from diff_tests.stdlib.linux.memory import Memory
 from diff_tests.stdlib.android.heap_graph_tests import HeapGraph
-from diff_tests.stdlib.memory.tests import Memory
 from diff_tests.stdlib.pkvm.tests import Pkvm
 from diff_tests.stdlib.prelude.math_functions_tests import PreludeMathFunctions
 from diff_tests.stdlib.prelude.pprof_functions_tests import PreludePprofFunctions
@@ -268,6 +270,8 @@
     chrome_stdlib_tests += test_suite.fetch()
 
   stdlib_tests = [
+      *AndroidMemory(index_path, 'stdlib/android', 'AndroidMemory').fetch(),
+      *AndroidGpu(index_path, 'stdlib/android', 'AndroidGpu').fetch(),
       *AndroidStdlib(index_path, 'stdlib/android', 'AndroidStdlib').fetch(),
       *LinuxCpu(index_path, 'stdlib/linux/cpu', 'LinuxCpu').fetch(),
       *DominatorTree(index_path, 'stdlib/graphs', 'DominatorTree').fetch(),
@@ -282,7 +286,7 @@
                               'StdlibCounterIntervals').fetch(),
       *DynamicTables(index_path, 'stdlib/dynamic_tables',
                      'DynamicTables').fetch(),
-      *Memory(index_path, 'stdlib/memory', 'Memory').fetch(),
+      *Memory(index_path, 'stdlib/linux', 'Memory').fetch(),
       *PreludeMathFunctions(index_path, 'stdlib/prelude',
                             'PreludeMathFunctions').fetch(),
       *HeapGraph(index_path, 'stdlib/android',
diff --git a/test/trace_processor/diff_tests/stdlib/android/gpu.py b/test/trace_processor/diff_tests/stdlib/android/gpu.py
new file mode 100644
index 0000000..6ee18ac
--- /dev/null
+++ b/test/trace_processor/diff_tests/stdlib/android/gpu.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License a
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from python.generators.diff_tests.testing import Path, DataPath, Metric, Systrace
+from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
+from python.generators.diff_tests.testing import DiffTestBlueprint
+from python.generators.diff_tests.testing import TestSuite
+from python.generators.diff_tests.testing import PrintProfileProto
+
+
+class AndroidGpu(TestSuite):
+
+  def test_memory_gpu_per_process(self):
+    return DiffTestBlueprint(
+        trace=Path('../../metrics/graphics/gpu_metric.py'),
+        query="""
+        INCLUDE PERFETTO MODULE android.gpu.memory;
+        SELECT *
+        FROM android_gpu_memory_per_process;
+        """,
+        out=Csv("""
+        "ts","dur","upid","gpu_memory"
+        2,2,2,6
+        4,6,2,8
+        4,5,1,2
+        9,1,1,8
+        6,1,3,7
+        7,3,3,10
+         """))
diff --git a/test/trace_processor/diff_tests/stdlib/android/memory.py b/test/trace_processor/diff_tests/stdlib/android/memory.py
new file mode 100644
index 0000000..1da5baf
--- /dev/null
+++ b/test/trace_processor/diff_tests/stdlib/android/memory.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License a
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from python.generators.diff_tests.testing import Path, DataPath, Metric, Systrace
+from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
+from python.generators.diff_tests.testing import DiffTestBlueprint
+from python.generators.diff_tests.testing import TestSuite
+from python.generators.diff_tests.testing import PrintProfileProto
+
+
+class AndroidMemory(TestSuite):
+
+  def test_memory_oom_score_with_rss_and_swap_per_process(self):
+    return DiffTestBlueprint(
+        trace=DataPath('sched_wakeup_trace.atr'),
+        query="""
+        INCLUDE PERFETTO MODULE android.memory.process;
+        SELECT *
+        FROM memory_oom_score_with_rss_and_swap_per_process
+        WHERE oom_adj_reason IS NOT NULL
+        ORDER BY ts
+        LIMIT 10;
+      """,
+        out=Csv("""
+        "ts","dur","score","bucket","upid","process_name","pid","oom_adj_id","oom_adj_ts","oom_adj_dur","oom_adj_track_id","oom_adj_thread_name","oom_adj_reason","oom_adj_trigger","anon_rss","file_rss","shmem_rss","rss","swap","anon_rss_and_swap","rss_and_swap"
+        1737065264829,701108081,925,"cached",269,"com.android.providers.calendar",1937,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49229824,57495552,835584,107560960,0,49229824,107560960
+        1737066678827,2934486383,935,"cached",287,"com.android.imsserviceentitlement",2397,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48881664,57081856,831488,106795008,0,48881664,106795008
+        1737066873002,2934292208,945,"cached",292,"com.android.carrierconfig",2593,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48586752,49872896,823296,99282944,0,48586752,99282944
+        1737067058812,2934106398,955,"cached",288,"com.android.messaging",2416,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",54956032,71417856,843776,127217664,0,54956032,127217664
+        1737067246975,699224817,955,"cached",267,"android.process.acore",1866,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",52498432,72048640,856064,125403136,0,52498432,125403136
+        1737068421919,2932743291,965,"cached",273,"com.android.shell",2079,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48738304,52056064,823296,101617664,0,48738304,101617664
+        1737068599673,970398,965,"cached",271,"android.process.media",2003,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49917952,60444672,839680,111202304,0,49917952,111202304
+        1737068933602,2932231608,975,"cached",286,"com.android.gallery3d",2371,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49561600,54521856,831488,104914944,0,49561600,104914944
+        1737069091010,682459310,975,"cached",289,"com.android.packageinstaller",2480,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49364992,52539392,827392,102731776,0,49364992,102731776
+        1737069240534,489635,985,"cached",268,"com.android.managedprovisioning",1868,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",50683904,53985280,815104,105484288,0,50683904,105484288
+         """))
diff --git a/test/trace_processor/diff_tests/stdlib/linux/memory.py b/test/trace_processor/diff_tests/stdlib/linux/memory.py
new file mode 100644
index 0000000..be5d8ab
--- /dev/null
+++ b/test/trace_processor/diff_tests/stdlib/linux/memory.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License a
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from python.generators.diff_tests.testing import Path, DataPath, Metric, Systrace
+from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
+from python.generators.diff_tests.testing import DiffTestBlueprint
+from python.generators.diff_tests.testing import TestSuite
+from python.generators.diff_tests.testing import PrintProfileProto
+
+
+class Memory(TestSuite):
+
+  def test_memory_rss_and_swap_per_process(self):
+    return DiffTestBlueprint(
+        trace=DataPath('android_postboot_unlock.pftrace'),
+        query="""
+        INCLUDE PERFETTO MODULE linux.memory.process;
+
+        SELECT *
+        FROM memory_rss_and_swap_per_process
+        WHERE upid = 1
+        LIMIT 5
+        """,
+        out=Csv("""
+        "ts","dur","upid","pid","process_name","anon_rss","file_rss","shmem_rss","rss","swap","anon_rss_and_swap","rss_and_swap"
+        37592474220,12993896,1,1982,"com.android.systemui",125865984,"[NULL]","[NULL]","[NULL]","[NULL]",125865984,"[NULL]"
+        37605468116,1628,1,1982,"com.android.systemui",126050304,"[NULL]","[NULL]","[NULL]","[NULL]",126050304,"[NULL]"
+        37605469744,1302,1,1982,"com.android.systemui",126050304,"[NULL]",2990080,"[NULL]","[NULL]",126050304,"[NULL]"
+        37605471046,685791,1,1982,"com.android.systemui",126046208,"[NULL]",2990080,"[NULL]","[NULL]",126046208,"[NULL]"
+        37606156837,6510,1,1982,"com.android.systemui",126042112,"[NULL]",2990080,"[NULL]","[NULL]",126042112,"[NULL]"
+            """))
+
+  def test_memory_rss_high_watermark_per_process(self):
+    return DiffTestBlueprint(
+        trace=DataPath('android_postboot_unlock.pftrace'),
+        query="""
+        INCLUDE PERFETTO MODULE linux.memory.high_watermark;
+
+        SELECT *
+        FROM memory_rss_high_watermark_per_process
+        WHERE upid = 1
+        LIMIT 10;
+        """,
+        out=Csv("""
+        "ts","dur","upid","pid","process_name","rss_high_watermark"
+        37592474220,12993896,1,1982,"com.android.systemui",125865984
+        37605468116,1628,1,1982,"com.android.systemui",126050304
+        37605469744,333774129,1,1982,"com.android.systemui",129040384
+        37939243873,120479574,1,1982,"com.android.systemui",372977664
+        38059723447,936,1,1982,"com.android.systemui",373043200
+        38059724383,6749186,1,1982,"com.android.systemui",373174272
+        38066473569,7869426,1,1982,"com.android.systemui",373309440
+        38074342995,11596761,1,1982,"com.android.systemui",373444608
+        38085939756,4877848,1,1982,"com.android.systemui",373579776
+        38090817604,11930827,1,1982,"com.android.systemui",373714944
+              """))
diff --git a/test/trace_processor/diff_tests/stdlib/memory/tests.py b/test/trace_processor/diff_tests/stdlib/memory/tests.py
deleted file mode 100644
index d781b54..0000000
--- a/test/trace_processor/diff_tests/stdlib/memory/tests.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (C) 2024 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License a
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from python.generators.diff_tests.testing import Path, DataPath, Metric, Systrace
-from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
-from python.generators.diff_tests.testing import DiffTestBlueprint
-from python.generators.diff_tests.testing import TestSuite
-from python.generators.diff_tests.testing import PrintProfileProto
-
-
-class Memory(TestSuite):
-
-  def test_memory_rss_and_swap_per_process(self):
-    return DiffTestBlueprint(
-        trace=DataPath('android_postboot_unlock.pftrace'),
-        query="""
-        INCLUDE PERFETTO MODULE memory.linux.process;
-
-        SELECT *
-        FROM memory_rss_and_swap_per_process
-        WHERE upid = 1
-        LIMIT 5
-        """,
-        out=Csv("""
-        "ts","dur","upid","pid","process_name","anon_rss","file_rss","shmem_rss","rss","swap","anon_rss_and_swap","rss_and_swap"
-        37592474220,12993896,1,1982,"com.android.systemui",125865984,"[NULL]","[NULL]","[NULL]","[NULL]",125865984,"[NULL]"
-        37605468116,1628,1,1982,"com.android.systemui",126050304,"[NULL]","[NULL]","[NULL]","[NULL]",126050304,"[NULL]"
-        37605469744,1302,1,1982,"com.android.systemui",126050304,"[NULL]",2990080,"[NULL]","[NULL]",126050304,"[NULL]"
-        37605471046,685791,1,1982,"com.android.systemui",126046208,"[NULL]",2990080,"[NULL]","[NULL]",126046208,"[NULL]"
-        37606156837,6510,1,1982,"com.android.systemui",126042112,"[NULL]",2990080,"[NULL]","[NULL]",126042112,"[NULL]"
-            """))
-
-  def test_memory_rss_high_watermark_per_process(self):
-    return DiffTestBlueprint(
-        trace=DataPath('android_postboot_unlock.pftrace'),
-        query="""
-        INCLUDE PERFETTO MODULE memory.linux.high_watermark;
-
-        SELECT *
-        FROM memory_rss_high_watermark_per_process
-        WHERE upid = 1
-        LIMIT 10;
-        """,
-        out=Csv("""
-        "ts","dur","upid","pid","process_name","rss_high_watermark"
-        37592474220,12993896,1,1982,"com.android.systemui",125865984
-        37605468116,1628,1,1982,"com.android.systemui",126050304
-        37605469744,333774129,1,1982,"com.android.systemui",129040384
-        37939243873,120479574,1,1982,"com.android.systemui",372977664
-        38059723447,936,1,1982,"com.android.systemui",373043200
-        38059724383,6749186,1,1982,"com.android.systemui",373174272
-        38066473569,7869426,1,1982,"com.android.systemui",373309440
-        38074342995,11596761,1,1982,"com.android.systemui",373444608
-        38085939756,4877848,1,1982,"com.android.systemui",373579776
-        38090817604,11930827,1,1982,"com.android.systemui",373714944
-              """))
-
-  def test_memory_oom_score_with_rss_and_swap_per_process(self):
-    return DiffTestBlueprint(
-        trace=DataPath('sched_wakeup_trace.atr'),
-        query="""
-        INCLUDE PERFETTO MODULE memory.linux.process;
-        SELECT *
-        FROM memory_oom_score_with_rss_and_swap_per_process
-        WHERE oom_adj_reason IS NOT NULL
-        ORDER BY ts
-        LIMIT 10;
-      """,
-        out=Csv("""
-        "ts","dur","score","bucket","upid","process_name","pid","oom_adj_id","oom_adj_ts","oom_adj_dur","oom_adj_track_id","oom_adj_thread_name","oom_adj_reason","oom_adj_trigger","anon_rss","file_rss","shmem_rss","rss","swap","anon_rss_and_swap","rss_and_swap"
-        1737065264829,701108081,925,"cached",269,"com.android.providers.calendar",1937,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49229824,57495552,835584,107560960,0,49229824,107560960
-        1737066678827,2934486383,935,"cached",287,"com.android.imsserviceentitlement",2397,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48881664,57081856,831488,106795008,0,48881664,106795008
-        1737066873002,2934292208,945,"cached",292,"com.android.carrierconfig",2593,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48586752,49872896,823296,99282944,0,48586752,99282944
-        1737067058812,2934106398,955,"cached",288,"com.android.messaging",2416,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",54956032,71417856,843776,127217664,0,54956032,127217664
-        1737067246975,699224817,955,"cached",267,"android.process.acore",1866,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",52498432,72048640,856064,125403136,0,52498432,125403136
-        1737068421919,2932743291,965,"cached",273,"com.android.shell",2079,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",48738304,52056064,823296,101617664,0,48738304,101617664
-        1737068599673,970398,965,"cached",271,"android.process.media",2003,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49917952,60444672,839680,111202304,0,49917952,111202304
-        1737068933602,2932231608,975,"cached",286,"com.android.gallery3d",2371,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49561600,54521856,831488,104914944,0,49561600,104914944
-        1737069091010,682459310,975,"cached",289,"com.android.packageinstaller",2480,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",49364992,52539392,827392,102731776,0,49364992,102731776
-        1737069240534,489635,985,"cached",268,"com.android.managedprovisioning",1868,332,1737064421516,29484835,1217,"binder:642_1","processEnd","IActivityManager#1598246212",50683904,53985280,815104,105484288,0,50683904,105484288
-         """))
-
-  def test_memory_gpu_per_process(self):
-    return DiffTestBlueprint(
-        trace=Path('../../metrics/graphics/gpu_metric.py'),
-        query="""
-        INCLUDE PERFETTO MODULE memory.android.gpu;
-        SELECT *
-        FROM memory_gpu_per_process;
-        """,
-        out=Csv("""
-        "ts","dur","upid","gpu_memory"
-        2,2,2,6
-        4,6,2,8
-        4,5,1,2
-        9,1,1,8
-        6,1,3,7
-        7,3,3,10
-         """))
diff --git a/ui/src/plugins/com.google.PixelMemory/index.ts b/ui/src/plugins/com.google.PixelMemory/index.ts
index 0412e19..80ac5af 100644
--- a/ui/src/plugins/com.google.PixelMemory/index.ts
+++ b/ui/src/plugins/com.google.PixelMemory/index.ts
@@ -27,15 +27,17 @@
           if (pid === null) return;
         }
         const RSS_ALL = `
-          INCLUDE PERFETTO MODULE memory.linux.process;
-          INCLUDE PERFETTO MODULE memory.android.gpu;
+          INCLUDE PERFETTO MODULE android.gpu.memory;
+          INCLUDE PERFETTO MODULE linux.memory.process;
 
           DROP TABLE IF EXISTS process_mem_rss_anon_file_shmem_swap_gpu;
 
           CREATE VIRTUAL TABLE process_mem_rss_anon_file_shmem_swap_gpu
           USING
             SPAN_OUTER_JOIN(
-              memory_gpu_per_process PARTITIONED upid, memory_rss_and_swap_per_process PARTITIONED upid);
+              android_gpu_memory_per_process PARTITIONED upid,
+              memory_rss_and_swap_per_process PARTITIONED upid
+            );
         `;
         await ctx.engine.query(RSS_ALL);
         await addDebugCounterTrack(