Merge "tp: fix compile of TP from external project using Bazel" into main
diff --git a/Android.bp b/Android.bp
index 6cb0053..04d53c2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5168,6 +5168,7 @@
         "protos/perfetto/metrics/android/android_boot_unagg.proto",
         "protos/perfetto/metrics/android/android_frame_timeline_metric.proto",
         "protos/perfetto/metrics/android/android_garbage_collection_unagg_metric.proto",
+        "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto",
         "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto",
         "protos/perfetto/metrics/android/android_trusty_workqueues.proto",
         "protos/perfetto/metrics/android/anr_metric.proto",
@@ -5257,6 +5258,7 @@
         "protos/perfetto/metrics/android/android_boot_unagg.proto",
         "protos/perfetto/metrics/android/android_frame_timeline_metric.proto",
         "protos/perfetto/metrics/android/android_garbage_collection_unagg_metric.proto",
+        "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto",
         "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto",
         "protos/perfetto/metrics/android/android_trusty_workqueues.proto",
         "protos/perfetto/metrics/android/anr_metric.proto",
@@ -5321,6 +5323,7 @@
 genrule {
     name: "perfetto_protos_perfetto_metrics_webview_descriptor",
     srcs: [
+        ":libprotobuf-internal-descriptor-proto",
         "protos/perfetto/metrics/android/ad_services_metric.proto",
         "protos/perfetto/metrics/android/android_blocking_call.proto",
         "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto",
@@ -5329,6 +5332,7 @@
         "protos/perfetto/metrics/android/android_boot_unagg.proto",
         "protos/perfetto/metrics/android/android_frame_timeline_metric.proto",
         "protos/perfetto/metrics/android/android_garbage_collection_unagg_metric.proto",
+        "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto",
         "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto",
         "protos/perfetto/metrics/android/android_trusty_workqueues.proto",
         "protos/perfetto/metrics/android/anr_metric.proto",
@@ -5385,7 +5389,7 @@
     tools: [
         "aprotoc",
     ],
-    cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --descriptor_set_out=$(out) $(in)",
+    cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --proto_path=external/protobuf/src --descriptor_set_out=$(out) $(in)",
     out: [
         "perfetto_protos_perfetto_metrics_webview_descriptor.bin",
     ],
@@ -11304,6 +11308,7 @@
     name: "perfetto_src_trace_processor_containers_unittests",
     srcs: [
         "src/trace_processor/containers/bit_vector_unittest.cc",
+        "src/trace_processor/containers/implicit_segment_forest_unittest.cc",
         "src/trace_processor/containers/null_term_string_view_unittest.cc",
         "src/trace_processor/containers/row_map_unittest.cc",
         "src/trace_processor/containers/string_pool_unittest.cc",
@@ -12037,6 +12042,7 @@
         "src/trace_processor/metrics/sql/android/android_multiuser.sql",
         "src/trace_processor/metrics/sql/android/android_multiuser_populator.sql",
         "src/trace_processor/metrics/sql/android/android_netperf.sql",
+        "src/trace_processor/metrics/sql/android/android_oom_adjuster.sql",
         "src/trace_processor/metrics/sql/android/android_other_traces.sql",
         "src/trace_processor/metrics/sql/android/android_package_list.sql",
         "src/trace_processor/metrics/sql/android/android_powrails.sql",
@@ -12285,6 +12291,8 @@
 filegroup {
     name: "perfetto_src_trace_processor_perfetto_sql_intrinsics_operators_operators",
     srcs: [
+        "src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.cc",
+        "src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.cc",
         "src/trace_processor/perfetto_sql/intrinsics/operators/span_join_operator.cc",
         "src/trace_processor/perfetto_sql/intrinsics/operators/window_operator.cc",
     ],
@@ -12431,6 +12439,7 @@
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_minsdk29.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_minsdk33.sql",
+        "src/trace_processor/perfetto_sql/stdlib/android/startup/time_to_display.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/statsd.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/suspend.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/thread.sql",
@@ -12485,6 +12494,10 @@
         "src/trace_processor/perfetto_sql/stdlib/stack_trace/jit.sql",
         "src/trace_processor/perfetto_sql/stdlib/time/conversion.sql",
         "src/trace_processor/perfetto_sql/stdlib/v8/jit.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/processes.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/slices.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/threads.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql",
         "src/trace_processor/perfetto_sql/stdlib/wattson/arm_dsu.sql",
         "src/trace_processor/perfetto_sql/stdlib/wattson/cpu_freq.sql",
         "src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql",
@@ -12891,6 +12904,7 @@
 filegroup {
     name: "perfetto_src_trace_redaction_trace_redaction",
     srcs: [
+        "src/trace_redaction/collect_frame_cookies.cc",
         "src/trace_redaction/collect_timeline_events.cc",
         "src/trace_redaction/filter_ftrace_using_allowlist.cc",
         "src/trace_redaction/filter_packet_using_allowlist.cc",
@@ -12921,6 +12935,7 @@
 filegroup {
     name: "perfetto_src_trace_redaction_unittests",
     srcs: [
+        "src/trace_redaction/collect_frame_cookies_unittest.cc",
         "src/trace_redaction/collect_timeline_events_unittest.cc",
         "src/trace_redaction/filter_ftrace_using_allowlist_unittest.cc",
         "src/trace_redaction/filter_packet_using_allowlist_unittest.cc",
diff --git a/BUILD b/BUILD
index 12fe725..c6408f1 100644
--- a/BUILD
+++ b/BUILD
@@ -1366,6 +1366,7 @@
         ":include_perfetto_public_base",
         ":include_perfetto_public_protozero",
         "src/trace_processor/containers/bit_vector.h",
+        "src/trace_processor/containers/implicit_segment_forest.h",
         "src/trace_processor/containers/null_term_string_view.h",
         "src/trace_processor/containers/row_map.h",
         "src/trace_processor/containers/row_map_algorithms.h",
@@ -1997,6 +1998,7 @@
         "src/trace_processor/metrics/sql/android/android_multiuser.sql",
         "src/trace_processor/metrics/sql/android/android_multiuser_populator.sql",
         "src/trace_processor/metrics/sql/android/android_netperf.sql",
+        "src/trace_processor/metrics/sql/android/android_oom_adjuster.sql",
         "src/trace_processor/metrics/sql/android/android_other_traces.sql",
         "src/trace_processor/metrics/sql/android/android_package_list.sql",
         "src/trace_processor/metrics/sql/android/android_powrails.sql",
@@ -2312,6 +2314,10 @@
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_intrinsics_operators_operators",
     srcs = [
+        "src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.cc",
+        "src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h",
+        "src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.cc",
+        "src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h",
         "src/trace_processor/perfetto_sql/intrinsics/operators/span_join_operator.cc",
         "src/trace_processor/perfetto_sql/intrinsics/operators/span_join_operator.h",
         "src/trace_processor/perfetto_sql/intrinsics/operators/window_operator.cc",
@@ -2417,6 +2423,7 @@
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_minsdk29.sql",
         "src/trace_processor/perfetto_sql/stdlib/android/startup/startups_minsdk33.sql",
+        "src/trace_processor/perfetto_sql/stdlib/android/startup/time_to_display.sql",
     ],
 )
 
@@ -2620,6 +2627,17 @@
     ],
 )
 
+# GN target: //src/trace_processor/perfetto_sql/stdlib/viz/summary:summary
+perfetto_filegroup(
+    name = "src_trace_processor_perfetto_sql_stdlib_viz_summary_summary",
+    srcs = [
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/processes.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/slices.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/threads.sql",
+        "src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql",
+    ],
+)
+
 # GN target: //src/trace_processor/perfetto_sql/stdlib/wattson:wattson
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_wattson_wattson",
@@ -2655,6 +2673,7 @@
         ":src_trace_processor_perfetto_sql_stdlib_stack_trace_stack_trace",
         ":src_trace_processor_perfetto_sql_stdlib_time_time",
         ":src_trace_processor_perfetto_sql_stdlib_v8_v8",
+        ":src_trace_processor_perfetto_sql_stdlib_viz_summary_summary",
         ":src_trace_processor_perfetto_sql_stdlib_wattson_wattson",
     ],
     outs = [
@@ -4428,6 +4447,7 @@
         "protos/perfetto/metrics/android/android_boot_unagg.proto",
         "protos/perfetto/metrics/android/android_frame_timeline_metric.proto",
         "protos/perfetto/metrics/android/android_garbage_collection_unagg_metric.proto",
+        "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto",
         "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto",
         "protos/perfetto/metrics/android/android_trusty_workqueues.proto",
         "protos/perfetto/metrics/android/anr_metric.proto",
diff --git a/CHANGELOG b/CHANGELOG
index b600600..99ff035 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,7 +4,18 @@
   Trace Processor:
     *
   UI:
-    *
+    * Add tracks to the list of searchable items.
+    * Use mipmaps to improve track query performance on large traces.
+    * Fix slow scrolling bug in ftrace explorer tab on low DPI machines.
+    * Overhaul track decider queries to improve trace load times.
+    * Add track
+    * Tidy up command names & remove some example ones.
+    * Remove arg auto-completion in pivot table.
+    * Show dominator tree views by default.
+    * Fix counter event selection off-by-one error.
+    * Add viewport control to the plugin API.
+    * Sticky track titles to improve track button accessibility in tall tracks.
+    * A handful of small bugfixes.
   SDK:
     * The TRACE_EVENT macro used to reject `const char *` event names: either
       `StaticString` or `DynamicString` needed to be specified. In the last year
diff --git a/docs/contributing/ui-plugins.md b/docs/contributing/ui-plugins.md
index 09fa88e..9b1535a 100644
--- a/docs/contributing/ui-plugins.md
+++ b/docs/contributing/ui-plugins.md
@@ -36,9 +36,10 @@
 - Commands should have ids with the pattern `example.com#DoSomething`
 - Command's ids should be prefixed with the id of the plugin which
   provides them.
-- Commands names should have the form "Verb something something".
-  Good: "Pin janky frame timeline tracks"
-  Bad: "Tracks are Displayed if Janky"
+- Command names should have the form "Verb something something", and should be
+  in normal sentence case. I.e. don't capitalize the first letter of each word.
+  - Good: "Pin janky frame timeline tracks"
+  - Bad: "Tracks are Displayed if Janky"
 
 ### Start the dev server
 ```sh
diff --git a/gn/proto_library.gni b/gn/proto_library.gni
index f69d3ce..a7a77c6 100644
--- a/gn/proto_library.gni
+++ b/gn/proto_library.gni
@@ -371,7 +371,7 @@
 
         metadata = {
           proto_library_sources = invoker.sources
-          import_dirs = import_dirs_
+          proto_import_dirs = import_dirs_
           exports = get_path_info(public_deps_, "abspath")
         }
         forward_variables_from(invoker, vars_to_forward)
diff --git a/gn/standalone/proto_library.gni b/gn/standalone/proto_library.gni
index 07b8140..1a23a97 100644
--- a/gn/standalone/proto_library.gni
+++ b/gn/standalone/proto_library.gni
@@ -170,6 +170,10 @@
       ]
     }
 
+    metadata = {
+      proto_import_dirs = import_dirs
+    }
+
     if (generate_cc) {
       cc_generator_options_ = ""
       if (defined(invoker.cc_generator_options)) {
diff --git a/protos/perfetto/metrics/android/BUILD.gn b/protos/perfetto/metrics/android/BUILD.gn
index 5b8fab6..5430c22 100644
--- a/protos/perfetto/metrics/android/BUILD.gn
+++ b/protos/perfetto/metrics/android/BUILD.gn
@@ -28,6 +28,7 @@
     "android_boot_unagg.proto",
     "android_frame_timeline_metric.proto",
     "android_garbage_collection_unagg_metric.proto",
+    "android_oom_adjuster_metric.proto",
     "android_sysui_notifications_blocking_calls_metric.proto",
     "android_trusty_workqueues.proto",
     "anr_metric.proto",
diff --git a/protos/perfetto/metrics/android/android_boot.proto b/protos/perfetto/metrics/android/android_boot.proto
index a043efe..9f90ba5 100644
--- a/protos/perfetto/metrics/android/android_boot.proto
+++ b/protos/perfetto/metrics/android/android_boot.proto
@@ -56,8 +56,39 @@
     optional int64 alloc_gc_count = 11;
     optional double mb_per_ms_of_gc = 12;
   }
+  message OomAdjusterTransitionCounts {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason.
+    optional string name = 1;
+    // name of previous oom bucket.
+    optional string src_bucket = 2;
+    // name of oom bucket.
+    optional string dest_bucket = 3;
+    // count of transitions
+    optional int64 count = 4;
+  }
+  message OomAdjBucketDurationAggregation {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason
+    optional string name = 1;
+    // name of oom bucket.
+    optional string bucket = 2;
+    // Duration of the time in the bucket
+    optional int64 total_dur = 3;
+  }
+  message OomAdjDurationAggregation {
+    optional int64 min_oom_adj_dur = 1;
+    optional int64 max_oom_adj_dur = 2;
+    optional double avg_oom_adj_dur = 3;
+    optional int64 oom_adj_event_count = 4;
+    optional string oom_adj_reason = 5;
+  }
   optional ProcessStartAggregation full_trace_process_start_aggregation = 6;
   optional ProcessStartAggregation post_boot_process_start_aggregation = 7;
   optional GarbageCollectionAggregation full_trace_gc_aggregation = 8;
   optional GarbageCollectionAggregation post_boot_gc_aggregation = 9;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_global = 10;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_by_process = 11;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_by_oom_adj_reason = 12;
+  repeated OomAdjBucketDurationAggregation post_boot_oom_adj_bucket_duration_agg_global = 13;
+  repeated OomAdjBucketDurationAggregation post_boot_oom_adj_bucket_duration_agg_by_process = 14;
+  repeated OomAdjDurationAggregation post_boot_oom_adj_duration_agg = 15;
 }
diff --git a/protos/perfetto/metrics/android/android_oom_adjuster_metric.proto b/protos/perfetto/metrics/android/android_oom_adjuster_metric.proto
new file mode 100644
index 0000000..95af7b4
--- /dev/null
+++ b/protos/perfetto/metrics/android/android_oom_adjuster_metric.proto
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+syntax = "proto2";
+
+package perfetto.protos;
+
+message AndroidOomAdjusterMetric {
+  message OomAdjusterTransitionCounts {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason.
+    optional string name = 1;
+    // name of previous oom bucket.
+    optional string src_bucket = 2;
+    // name of oom bucket.
+    optional string dest_bucket = 3;
+    // count of transitions
+    optional int64 count = 4;
+  }
+  message OomAdjBucketDurationAggregation {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason
+    optional string name = 1;
+    // name of oom bucket.
+    optional string bucket = 2;
+    // Duration of the time in the bucket
+    optional int64 total_dur = 3;
+  }
+  message OomAdjDurationAggregation {
+    optional int64 min_oom_adj_dur = 1;
+    optional int64 max_oom_adj_dur = 2;
+    optional double avg_oom_adj_dur = 3;
+    optional int64 oom_adj_event_count = 4;
+    optional string oom_adj_reason = 5;
+  }
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_global = 1;
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_by_process = 2;
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_by_oom_adj_reason = 3;
+  repeated OomAdjBucketDurationAggregation oom_adj_bucket_duration_agg_global = 4;
+  repeated OomAdjBucketDurationAggregation oom_adj_bucket_duration_agg_by_process = 5;
+  repeated OomAdjDurationAggregation oom_adj_duration_agg = 6;
+}
\ No newline at end of file
diff --git a/protos/perfetto/metrics/metrics.proto b/protos/perfetto/metrics/metrics.proto
index 83395ec..c3025c3 100644
--- a/protos/perfetto/metrics/metrics.proto
+++ b/protos/perfetto/metrics/metrics.proto
@@ -71,6 +71,7 @@
 import "protos/perfetto/metrics/android/monitor_contention_metric.proto";
 import "protos/perfetto/metrics/android/monitor_contention_agg_metric.proto";
 import "protos/perfetto/metrics/android/app_process_starts_metric.proto";
+import "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto";
 
 // Trace processor metadata
 message TraceMetadata {
@@ -298,6 +299,10 @@
   // All blocking calls (e.g. binder calls) for a trace.
   optional AndroidBlockingCallsUnagg android_blocking_calls_unagg = 65;
 
+  // Android OOM unaggregated metrics.
+  optional AndroidOomAdjusterMetric android_oom_adjuster = 66;
+
+  // Android
   // Demo extensions.
   extensions 450 to 499;
 
diff --git a/protos/perfetto/metrics/perfetto_merged_metrics.proto b/protos/perfetto/metrics/perfetto_merged_metrics.proto
index 6b7a611..86f7d59 100644
--- a/protos/perfetto/metrics/perfetto_merged_metrics.proto
+++ b/protos/perfetto/metrics/perfetto_merged_metrics.proto
@@ -203,10 +203,41 @@
     optional int64 alloc_gc_count = 11;
     optional double mb_per_ms_of_gc = 12;
   }
+  message OomAdjusterTransitionCounts {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason.
+    optional string name = 1;
+    // name of previous oom bucket.
+    optional string src_bucket = 2;
+    // name of oom bucket.
+    optional string dest_bucket = 3;
+    // count of transitions
+    optional int64 count = 4;
+  }
+  message OomAdjBucketDurationAggregation {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason
+    optional string name = 1;
+    // name of oom bucket.
+    optional string bucket = 2;
+    // Duration of the time in the bucket
+    optional int64 total_dur = 3;
+  }
+  message OomAdjDurationAggregation {
+    optional int64 min_oom_adj_dur = 1;
+    optional int64 max_oom_adj_dur = 2;
+    optional double avg_oom_adj_dur = 3;
+    optional int64 oom_adj_event_count = 4;
+    optional string oom_adj_reason = 5;
+  }
   optional ProcessStartAggregation full_trace_process_start_aggregation = 6;
   optional ProcessStartAggregation post_boot_process_start_aggregation = 7;
   optional GarbageCollectionAggregation full_trace_gc_aggregation = 8;
   optional GarbageCollectionAggregation post_boot_gc_aggregation = 9;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_global = 10;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_by_process = 11;
+  repeated OomAdjusterTransitionCounts post_boot_oom_adjuster_transition_counts_by_oom_adj_reason = 12;
+  repeated OomAdjBucketDurationAggregation post_boot_oom_adj_bucket_duration_agg_global = 13;
+  repeated OomAdjBucketDurationAggregation post_boot_oom_adj_bucket_duration_agg_by_process = 14;
+  repeated OomAdjDurationAggregation post_boot_oom_adj_duration_agg = 15;
 }
 
 // End of protos/perfetto/metrics/android/android_boot.proto
@@ -365,6 +396,43 @@
 
 // End of protos/perfetto/metrics/android/android_frame_timeline_metric.proto
 
+// Begin of protos/perfetto/metrics/android/android_oom_adjuster_metric.proto
+
+message AndroidOomAdjusterMetric {
+  message OomAdjusterTransitionCounts {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason.
+    optional string name = 1;
+    // name of previous oom bucket.
+    optional string src_bucket = 2;
+    // name of oom bucket.
+    optional string dest_bucket = 3;
+    // count of transitions
+    optional int64 count = 4;
+  }
+  message OomAdjBucketDurationAggregation {
+    // name of the item aggregated by. example: process_name, oom_adjuster_reason
+    optional string name = 1;
+    // name of oom bucket.
+    optional string bucket = 2;
+    // Duration of the time in the bucket
+    optional int64 total_dur = 3;
+  }
+  message OomAdjDurationAggregation {
+    optional int64 min_oom_adj_dur = 1;
+    optional int64 max_oom_adj_dur = 2;
+    optional double avg_oom_adj_dur = 3;
+    optional int64 oom_adj_event_count = 4;
+    optional string oom_adj_reason = 5;
+  }
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_global = 1;
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_by_process = 2;
+  repeated OomAdjusterTransitionCounts oom_adjuster_transition_counts_by_oom_adj_reason = 3;
+  repeated OomAdjBucketDurationAggregation oom_adj_bucket_duration_agg_global = 4;
+  repeated OomAdjBucketDurationAggregation oom_adj_bucket_duration_agg_by_process = 5;
+  repeated OomAdjDurationAggregation oom_adj_duration_agg = 6;
+}
+// End of protos/perfetto/metrics/android/android_oom_adjuster_metric.proto
+
 // Begin of protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto
 
 // Blocking calls inside System UI Notifications. Shows count and total duration for each.
@@ -2721,6 +2789,10 @@
   // All blocking calls (e.g. binder calls) for a trace.
   optional AndroidBlockingCallsUnagg android_blocking_calls_unagg = 65;
 
+  // Android OOM unaggregated metrics.
+  optional AndroidOomAdjusterMetric android_oom_adjuster = 66;
+
+  // Android
   // Demo extensions.
   extensions 450 to 499;
 
diff --git a/protos/third_party/chromium/chrome_track_event.proto b/protos/third_party/chromium/chrome_track_event.proto
index bea5d6e..0a8842f 100644
--- a/protos/third_party/chromium/chrome_track_event.proto
+++ b/protos/third_party/chromium/chrome_track_event.proto
@@ -303,6 +303,9 @@
   // Number of "pending reuse" references active in the RenderProcessHost,
   // recorded when Cleanup() was called.
   optional uint32 pending_reuse_ref_count = 5;
+  // Number of NavigationStateKeepAlive references active in the
+  // RenderProcessHost, recorded when Cleanup() was called.
+  optional uint32 navigation_state_keepalive_count = 6;
 }
 
 message ChildProcessLauncherPriority {
diff --git a/python/generators/trace_processor_table/serialize.py b/python/generators/trace_processor_table/serialize.py
index b9d5170..1e613e3 100644
--- a/python/generators/trace_processor_table/serialize.py
+++ b/python/generators/trace_processor_table/serialize.py
@@ -674,15 +674,13 @@
 
   Iterator IterateRows() {{ return Iterator(this, Table::IterateRows()); }}
 
-  ConstIterator FilterToIterator(
-      const std::vector<Constraint>& cs) const {{
+  ConstIterator FilterToIterator(const Query& q) const {{
     return ConstIterator(
-      this, ApplyAndIterateRows(QueryToRowMap(cs, {{}})));
+      this, ApplyAndIterateRows(QueryToRowMap(q)));
   }}
 
-  Iterator FilterToIterator(
-      const std::vector<Constraint>& cs) {{
-    return Iterator(this, ApplyAndIterateRows(QueryToRowMap(cs, {{}})));
+  Iterator FilterToIterator(const Query& q) {{
+    return Iterator(this, ApplyAndIterateRows(QueryToRowMap(q)));
   }}
 
   void ShrinkToFit() {{
diff --git a/python/perfetto/prebuilts/perfetto_prebuilts.py b/python/perfetto/prebuilts/perfetto_prebuilts.py
index 087a337..61283cc 100644
--- a/python/perfetto/prebuilts/perfetto_prebuilts.py
+++ b/python/perfetto/prebuilts/perfetto_prebuilts.py
@@ -46,6 +46,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -62,28 +65,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/python/perfetto/trace_processor/metrics.descriptor b/python/perfetto/trace_processor/metrics.descriptor
index cc4850f..c337e46 100644
--- a/python/perfetto/trace_processor/metrics.descriptor
+++ b/python/perfetto/trace_processor/metrics.descriptor
Binary files differ
diff --git a/src/protozero/protoc_plugin/protozero_c_plugin.cc b/src/protozero/protoc_plugin/protozero_c_plugin.cc
index 5bd05dd..804968e 100644
--- a/src/protozero/protoc_plugin/protozero_c_plugin.cc
+++ b/src/protozero/protoc_plugin/protozero_c_plugin.cc
@@ -258,8 +258,9 @@
     for (int i = 0; i < source_->enum_type_count(); ++i)
       enums_.push_back(source_->enum_type(i));
 
-    if (source_->extension_count() > 0)
-      Abort("top-level extension blocks are not supported");
+    if (source_->extension_count() > 0) {
+      // TODO(b/336524288): emit field numbers
+    }
 
     for (const Descriptor* message : messages_) {
       for (int i = 0; i < message->enum_type_count(); ++i) {
@@ -293,7 +294,6 @@
     while (!stack.empty()) {
       const FileDescriptor* imp = stack.back();
       stack.pop_back();
-
       for (int i = 0; i < imp->public_dependency_count(); ++i) {
         stack.push_back(imp->public_dependency(i));
       }
diff --git a/src/protozero/protoc_plugin/protozero_plugin.cc b/src/protozero/protoc_plugin/protozero_plugin.cc
index 7a29776..26f3110 100644
--- a/src/protozero/protoc_plugin/protozero_plugin.cc
+++ b/src/protozero/protoc_plugin/protozero_plugin.cc
@@ -393,8 +393,9 @@
     for (int i = 0; i < source_->enum_type_count(); ++i)
       enums_.push_back(source_->enum_type(i));
 
-    if (source_->extension_count() > 0)
-      Abort("top-level extension blocks are not supported");
+    if (source_->extension_count() > 0) {
+      // TODO(b/336524288): emit field numbers
+    }
 
     for (const Descriptor* message : messages_) {
       for (int i = 0; i < message->enum_type_count(); ++i) {
@@ -763,8 +764,9 @@
     }
     // Iterate over all fields in "extend" blocks.
     for (int i = 0; i < message->extension_range_count(); ++i) {
-      const Descriptor::ExtensionRange* range = message->extension_range(i);
-      int candidate = range->end - 1;
+      Descriptor::ExtensionRange::Proto range;
+      message->extension_range(i)->CopyTo(&range);
+      int candidate = range.end() - 1;
       if (candidate > kMaxDecoderFieldId)
         continue;
       max_field_id = std::max(max_field_id, candidate);
diff --git a/src/trace_processor/containers/BUILD.gn b/src/trace_processor/containers/BUILD.gn
index 43e9603..c724df8 100644
--- a/src/trace_processor/containers/BUILD.gn
+++ b/src/trace_processor/containers/BUILD.gn
@@ -22,6 +22,7 @@
 perfetto_component("containers") {
   public = [
     "bit_vector.h",
+    "implicit_segment_forest.h",
     "null_term_string_view.h",
     "row_map.h",
     "row_map_algorithms.h",
@@ -44,6 +45,7 @@
   testonly = true
   sources = [
     "bit_vector_unittest.cc",
+    "implicit_segment_forest_unittest.cc",
     "null_term_string_view_unittest.cc",
     "row_map_unittest.cc",
     "string_pool_unittest.cc",
diff --git a/src/trace_processor/containers/implicit_segment_forest.h b/src/trace_processor/containers/implicit_segment_forest.h
new file mode 100644
index 0000000..5b58cb4
--- /dev/null
+++ b/src/trace_processor/containers/implicit_segment_forest.h
@@ -0,0 +1,137 @@
+/*
+ * 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.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_CONTAINERS_IMPLICIT_SEGMENT_FOREST_H_
+#define SRC_TRACE_PROCESSOR_CONTAINERS_IMPLICIT_SEGMENT_FOREST_H_
+
+#include <cstddef>
+#include <cstdint>
+#include <vector>
+
+#include "perfetto/base/logging.h"
+
+namespace perfetto::trace_processor {
+
+// An implementation of a segment tree data structure [1] with:
+// 1) parent-child relationships are implicit, saving memory.
+// 2) the requirement for the number of values being a power of two, turning
+//    the tree into a forest.
+//
+// Segment trees are a very powerful data structure allowing O(log(n)) aggregate
+// queries to be performed on an arbitrary range of elements in an array.
+// Specifically, for `T x[n]`, and an associative and commutative operation
+// AggOp (e.g. +, *, min, max, etc.), segment trees can compute
+// ```
+//   T y = AggOp()(x[i], x[i + 1], x[i + 2], ..., x[j])
+// ```
+// in O(log(n)) time.
+//
+// Practically, in trace processor, this is useful for computing aggregations
+// over events in a trace. For example:
+// ```
+// struct Slice { int64_t ts; int64_t dur; };
+// struct MaxDurSlice {
+//   Slice operator()(const Slice& a, const Slice& b) {
+//     return a.dur < b.dur ? b : a;
+//   }
+// }
+// using MipMap = ImplicitSegmentForest<Slice, MaxDurSlice>;
+// ```
+// allows building a "mipmap" [2] of a track in a trace in a UI. The UI can show
+// a representation of the items in the track when very zoomed out while
+// skipping the rendering slices which are smaller than one pixel.
+//
+// The design and implementation of this class takes heavy inspiration from
+// Tristan Hume's "IForestIndex" data structure [3] as described in his blog
+// post [4].
+//
+// [1] https://en.algorithmica.org/hpc/data-structures/segment-trees/
+// [2] https://en.wikipedia.org/wiki/Mipmap
+// [3]
+// https://github.com/trishume/gigatrace/blob/dfde0d7244f356bdc9aeefb387d904dd8b09d94a/src/iforest.rs
+// [4] https://thume.ca/2021/03/14/iforests/
+template <typename T, typename AggOp>
+class ImplicitSegmentForest {
+ public:
+  // Computes the aggregation (as specified by operator() in AggOp) over all
+  // elements in the tree between the indices [start, end). Requires that
+  // start < end.
+  //
+  // Complexity:
+  // This function performs O(log(n)) operations (n = end - start).
+  //
+  // Returns:
+  //  1) values[start]: if start + 1 == end
+  //  2) AggOp()(values[start], ..., values[end - 1]) otherwise
+  T Query(uint32_t start, uint32_t end) const {
+    PERFETTO_DCHECK(start < end);
+
+    const uint32_t in_start = start * 2;
+    const uint32_t in_end = end * 2;
+
+    uint32_t first_skip = LargestPrefixInsideSkip(in_start, in_end);
+    T aggregated = values_[AggNode(in_start, first_skip)];
+    for (uint32_t i = in_start + first_skip; i < in_end;) {
+      uint32_t skip = LargestPrefixInsideSkip(i, in_end);
+      aggregated = AggOp()(aggregated, values_[AggNode(i, skip)]);
+      i += skip;
+    }
+    return aggregated;
+  }
+
+  // Pushes a new element to right-most part of the tree. This index of this
+  // element can be used in future calls to |Query|.
+  void Push(T v) {
+    values_.emplace_back(std::move(v));
+
+    size_t len = values_.size();
+    auto levels_to_index = static_cast<uint32_t>(__builtin_ctzl(~len)) - 1;
+
+    size_t cur = len - 1;
+    for (uint32_t level = 0; level < levels_to_index; ++level) {
+      size_t prev_higher_level = cur - (1 << level);
+      values_[prev_higher_level] =
+          AggOp()(values_[prev_higher_level], values_[cur]);
+      cur = prev_higher_level;
+    }
+    values_.emplace_back(values_[len - (1 << levels_to_index)]);
+  }
+
+  // Returns the value at |n| in the tree: this corresponds to the |n|th
+  // element |Push|-ed into the tree.
+  const T& operator[](uint32_t n) { return values_[n * 2]; }
+
+  // Returns the number of elements pushed into the forest.
+  uint32_t size() const { return static_cast<uint32_t>(values_.size() / 2); }
+
+ private:
+  static uint32_t Lsp(uint32_t x) { return x & -x; }
+  static uint32_t Msp(uint32_t x) {
+    return (1u << (sizeof(x) * 8 - 1)) >> __builtin_clz(x);
+  }
+  static uint32_t LargestPrefixInsideSkip(uint32_t min, uint32_t max) {
+    return Lsp(min | Msp(max - min));
+  }
+  static uint32_t AggNode(uint32_t i, uint32_t offset) {
+    return i + (offset >> 1) - 1;
+  }
+
+  std::vector<T> values_;
+};
+
+}  // namespace perfetto::trace_processor
+
+#endif  // SRC_TRACE_PROCESSOR_CONTAINERS_IMPLICIT_SEGMENT_FOREST_H_
diff --git a/src/trace_processor/containers/implicit_segment_forest_unittest.cc b/src/trace_processor/containers/implicit_segment_forest_unittest.cc
new file mode 100644
index 0000000..16dd262
--- /dev/null
+++ b/src/trace_processor/containers/implicit_segment_forest_unittest.cc
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#include "src/trace_processor/containers/implicit_segment_forest.h"
+
+#include <cstddef>
+#include <cstdint>
+#include <numeric>
+#include <random>
+#include <vector>
+
+#include "test/gtest_and_gmock.h"
+
+namespace perfetto::trace_processor {
+namespace {
+
+struct Value {
+  uint32_t value;
+};
+
+struct Sum {
+  Value operator()(const Value& a, const Value& b) {
+    return Value{a.value + b.value};
+  }
+};
+
+TEST(ImplicitSegmentTree, SimpleSum) {
+  std::vector<uint32_t> res = {209, 330, 901, 3, 10, 0, 3903, 309, 490};
+
+  ImplicitSegmentForest<Value, Sum> forest;
+  for (uint32_t x : res) {
+    forest.Push(Value{x});
+  }
+
+  for (uint32_t i = 0; i < res.size(); ++i) {
+    for (uint32_t j = i + 1; j < res.size(); ++j) {
+      ASSERT_EQ(forest.Query(i, j).value,
+                std::accumulate(res.begin() + i, res.begin() + j, 0u));
+    }
+  }
+}
+
+TEST(ImplicitSegmentTree, Stress) {
+  static constexpr size_t kCount = 9249;
+  std::minstd_rand0 rng(42);
+
+  std::vector<uint32_t> res;
+  ImplicitSegmentForest<Value, Sum> forest;
+  for (uint32_t i = 0; i < kCount; ++i) {
+    res.push_back(static_cast<uint32_t>(rng()));
+    forest.Push(Value{res.back()});
+  }
+
+  for (uint32_t i = 0; i < 10000; ++i) {
+    uint32_t s = rng() % kCount;
+    uint32_t e = s + 1 + (rng() % (kCount - s));
+    ASSERT_EQ(forest.Query(s, e).value,
+              std::accumulate(res.begin() + s, res.begin() + e, 0u));
+  }
+}
+
+}  // namespace
+}  // namespace perfetto::trace_processor
diff --git a/src/trace_processor/db/column/types.h b/src/trace_processor/db/column/types.h
index b59084b..6ec11fa 100644
--- a/src/trace_processor/db/column/types.h
+++ b/src/trace_processor/db/column/types.h
@@ -96,6 +96,15 @@
   bool desc;
 };
 
+// Structured data used to determine what Trace Processor will query using
+// CEngine.
+struct Query {
+  // Query constraints.
+  std::vector<Constraint> constraints;
+  // Query order bys.
+  std::vector<Order> orders;
+};
+
 // The enum type of the column.
 // Public only to stop GCC complaining about templates being defined in a
 // non-namespace scope (see ColumnTypeHelper below).
diff --git a/src/trace_processor/db/query_executor_benchmark.cc b/src/trace_processor/db/query_executor_benchmark.cc
index 8502e04..35f743a 100644
--- a/src/trace_processor/db/query_executor_benchmark.cc
+++ b/src/trace_processor/db/query_executor_benchmark.cc
@@ -234,15 +234,17 @@
 void BenchmarkSliceTableFilter(benchmark::State& state,
                                SliceTableForBenchmark& table,
                                std::initializer_list<Constraint> c) {
+  Query q;
+  q.constraints = c;
   for (auto _ : state) {
-    benchmark::DoNotOptimize(table.table_.QueryToRowMap(c, {}));
+    benchmark::DoNotOptimize(table.table_.QueryToRowMap(q));
   }
   state.counters["s/row"] =
       benchmark::Counter(static_cast<double>(table.table_.row_count()),
                          benchmark::Counter::kIsIterationInvariantRate |
                              benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap(c, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -263,15 +265,17 @@
     benchmark::State& state,
     ExpectedFrameTimelineTableForBenchmark& table,
     Constraint c) {
+  Query q;
+  q.constraints = {c};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(table.table_.QueryToRowMap({c}, {}));
+    benchmark::DoNotOptimize(table.table_.QueryToRowMap(q));
   }
   state.counters["s/row"] =
       benchmark::Counter(static_cast<double>(table.table_.row_count()),
                          benchmark::Counter::kIsIterationInvariantRate |
                              benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -279,15 +283,17 @@
 void BenchmarkFtraceEventTableFilter(benchmark::State& state,
                                      FtraceEventTableForBenchmark& table,
                                      std::initializer_list<Constraint> c) {
+  Query q;
+  q.constraints = c;
   for (auto _ : state) {
-    benchmark::DoNotOptimize(table.table_.QueryToRowMap(c, {}));
+    benchmark::DoNotOptimize(table.table_.QueryToRowMap(q));
   }
   state.counters["s/row"] =
       benchmark::Counter(static_cast<double>(table.table_.row_count()),
                          benchmark::Counter::kIsIterationInvariantRate |
                              benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -424,15 +430,17 @@
 
   Constraint c{table.table_.track_id().index_in_table(), FilterOp::kGt,
                SqlValue::Long(10)};
+  Query q;
+  q.constraints = {c};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(slice_sorted_with_duration.QueryToRowMap({c}, {}));
+    benchmark::DoNotOptimize(slice_sorted_with_duration.QueryToRowMap(q));
   }
   state.counters["s/row"] = benchmark::Counter(
       static_cast<double>(slice_sorted_with_duration.row_count()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -443,15 +451,17 @@
   HeapGraphObjectTableForBenchmark table(state);
   Constraint c{table.table_.reference_set_id().index_in_table(), FilterOp::kGt,
                SqlValue::Long(1000)};
+  Query q;
+  q.constraints = {c};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(table.table_.QueryToRowMap({c}, {}));
+    benchmark::DoNotOptimize(table.table_.QueryToRowMap(q));
   }
   state.counters["s/row"] =
       benchmark::Counter(static_cast<double>(table.table_.row_count()),
                          benchmark::Counter::kIsIterationInvariantRate |
                              benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -461,15 +471,17 @@
   HeapGraphObjectTableForBenchmark table(state);
   Constraint c{table.table_.reference_set_id().index_in_table(),
                FilterOp::kIsNull, SqlValue()};
+  Query q;
+  q.constraints = {c};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(table.table_.QueryToRowMap({c}, {}));
+    benchmark::DoNotOptimize(table.table_.QueryToRowMap(q));
   }
   state.counters["s/row"] =
       benchmark::Counter(static_cast<double>(table.table_.row_count()),
                          benchmark::Counter::kIsIterationInvariantRate |
                              benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
@@ -500,15 +512,17 @@
 
   Constraint c{table.table_.dur().index_in_table(), FilterOp::kGt,
                SqlValue::Long(10)};
+  Query q;
+  q.constraints = {c};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(slice_sorted_with_duration.QueryToRowMap({c}, {}));
+    benchmark::DoNotOptimize(slice_sorted_with_duration.QueryToRowMap(q));
   }
   state.counters["s/row"] = benchmark::Counter(
       static_cast<double>(slice_sorted_with_duration.row_count()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
   state.counters["s/out"] = benchmark::Counter(
-      static_cast<double>(table.table_.QueryToRowMap({c}, {}).size()),
+      static_cast<double>(table.table_.QueryToRowMap(q).size()),
       benchmark::Counter::kIsIterationInvariantRate |
           benchmark::Counter::kInvert);
 }
diff --git a/src/trace_processor/db/table.cc b/src/trace_processor/db/table.cc
index 641c745..0505bf4 100644
--- a/src/trace_processor/db/table.cc
+++ b/src/trace_processor/db/table.cc
@@ -87,8 +87,9 @@
   return {string_pool_, row_count_, std::move(cols), {}};
 }
 
-RowMap Table::QueryToRowMap(const std::vector<Constraint>& cs,
-                            const std::vector<Order>& ob) const {
+RowMap Table::QueryToRowMap(const Query& q) const {
+  const auto& cs = q.constraints;
+  const auto& ob = q.orders;
   // We need to delay creation of the chains to this point because of Chrome
   // does not want the binary size overhead of including the chain
   // implementations. As they also don't query tables (instead just iterating)
@@ -134,7 +135,9 @@
   // Return a copy of this table with the RowMaps using the computed ordered
   // RowMap.
   Table table = CopyExceptOverlays();
-  RowMap rm = QueryToRowMap({}, ob);
+  Query q;
+  q.orders = ob;
+  RowMap rm = QueryToRowMap(q);
   for (const ColumnStorageOverlay& overlay : overlays_) {
     table.overlays_.emplace_back(overlay.SelectRows(rm));
     PERFETTO_DCHECK(table.overlays_.back().size() == table.row_count());
diff --git a/src/trace_processor/db/table.h b/src/trace_processor/db/table.h
index 7d53106..655fa73 100644
--- a/src/trace_processor/db/table.h
+++ b/src/trace_processor/db/table.h
@@ -130,8 +130,7 @@
 
   // Filters and sorts the tables with the arguments specified, returning the
   // result as a RowMap.
-  RowMap QueryToRowMap(const std::vector<Constraint>&,
-                       const std::vector<Order>&) const;
+  RowMap QueryToRowMap(const Query&) const;
 
   // Applies the RowMap |rm| onto this table and returns an iterator over the
   // resulting rows.
diff --git a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
index 3b846f4..0955a25 100644
--- a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
@@ -24,7 +24,7 @@
 namespace trace_processor {
 namespace {
 
-std::array<FtraceMessageDescriptor, 498> descriptors{{
+std::array<FtraceMessageDescriptor, 502> descriptors{{
     {nullptr, 0, {}},
     {nullptr, 0, {}},
     {nullptr, 0, {}},
@@ -5501,6 +5501,52 @@
             {"prefree_seg", ProtoSchemaType::kUint32},
         },
     },
+    {
+        "fastrpc_dma_free",
+        3,
+        {
+            {},
+            {"cid", ProtoSchemaType::kInt32},
+            {"phys", ProtoSchemaType::kUint64},
+            {"size", ProtoSchemaType::kUint64},
+        },
+    },
+    {
+        "fastrpc_dma_alloc",
+        5,
+        {
+            {},
+            {"cid", ProtoSchemaType::kInt32},
+            {"phys", ProtoSchemaType::kUint64},
+            {"size", ProtoSchemaType::kUint64},
+            {"attr", ProtoSchemaType::kUint64},
+            {"mflags", ProtoSchemaType::kInt32},
+        },
+    },
+    {
+        "fastrpc_dma_unmap",
+        3,
+        {
+            {},
+            {"cid", ProtoSchemaType::kInt32},
+            {"phys", ProtoSchemaType::kUint64},
+            {"size", ProtoSchemaType::kUint64},
+        },
+    },
+    {
+        "fastrpc_dma_map",
+        7,
+        {
+            {},
+            {"cid", ProtoSchemaType::kInt32},
+            {"fd", ProtoSchemaType::kInt32},
+            {"phys", ProtoSchemaType::kUint64},
+            {"size", ProtoSchemaType::kUint64},
+            {"len", ProtoSchemaType::kUint64},
+            {"attr", ProtoSchemaType::kUint32},
+            {"mflags", ProtoSchemaType::kInt32},
+        },
+    },
 }};
 
 }  // namespace
diff --git a/src/trace_processor/importers/proto/default_modules.cc b/src/trace_processor/importers/proto/default_modules.cc
index b1cfc93..f7611d7 100644
--- a/src/trace_processor/importers/proto/default_modules.cc
+++ b/src/trace_processor/importers/proto/default_modules.cc
@@ -28,13 +28,13 @@
 namespace trace_processor {
 
 void RegisterDefaultModules(TraceProcessorContext* context) {
-  context->modules.emplace_back(new FtraceModule());
-  context->modules.emplace_back(new EtwModule());
   // Ftrace and Etw modules are special, because they have an extra method for
   // parsing the ftrace/etw packets. So we need to store a pointer to it
   // separately.
+  context->modules.emplace_back(new FtraceModule());
   context->ftrace_module =
       static_cast<FtraceModule*>(context->modules.back().get());
+  context->modules.emplace_back(new EtwModule());
   context->etw_module = static_cast<EtwModule*>(context->modules.back().get());
 
   context->modules.emplace_back(new TrackEventModule(context));
diff --git a/src/trace_processor/importers/proto/heap_graph_tracker.cc b/src/trace_processor/importers/proto/heap_graph_tracker.cc
index 72c0f33..097f398 100644
--- a/src/trace_processor/importers/proto/heap_graph_tracker.cc
+++ b/src/trace_processor/importers/proto/heap_graph_tracker.cc
@@ -62,8 +62,9 @@
     return;
 
   auto* ref = storage->mutable_heap_graph_reference_table();
-  auto it =
-      ref->FilterToIterator({ref->reference_set_id().eq(*reference_set_id)});
+  Query q;
+  q.constraints = {ref->reference_set_id().eq(*reference_set_id)};
+  auto it = ref->FilterToIterator(q);
 
   for (; it; ++it) {
     if (!fn(it.row_reference()))
@@ -92,10 +93,10 @@
                                               uint32_t ref_set_id,
                                               const std::string& field_name) {
   const auto& refs_tbl = storage.heap_graph_reference_table();
-
-  auto refs_it = refs_tbl.FilterToIterator(
-      {refs_tbl.reference_set_id().eq(ref_set_id),
-       refs_tbl.field_name().eq(NullTermStringView(field_name))});
+  Query q;
+  q.constraints = {refs_tbl.reference_set_id().eq(ref_set_id),
+                   refs_tbl.field_name().eq(NullTermStringView(field_name))};
+  auto refs_it = refs_tbl.FilterToIterator(q);
   if (!refs_it) {
     return std::nullopt;
   }
@@ -110,8 +111,10 @@
   // Resolve superclasses by iterating heap graph objects and identifying the
   // superClass field.
   const auto& objects_tbl = storage->heap_graph_object_table();
-  auto obj_it = objects_tbl.FilterToIterator(
-      {objects_tbl.upid().eq(upid), objects_tbl.graph_sample_ts().eq(ts)});
+  Query q;
+  q.constraints = {objects_tbl.upid().eq(upid),
+                   objects_tbl.graph_sample_ts().eq(ts)};
+  auto obj_it = objects_tbl.FilterToIterator(q);
   for (; obj_it; ++obj_it) {
     auto obj_id = obj_it.id();
     auto class_descriptor = GetClassDescriptor(*storage, obj_id);
@@ -673,14 +676,16 @@
   };
   std::vector<Cleaner> cleaners;
 
-  auto class_it =
-      class_tbl.FilterToIterator({class_tbl.name().eq("sun.misc.Cleaner")});
+  Query q;
+  q.constraints = {class_tbl.name().eq("sun.misc.Cleaner")};
+  auto class_it = class_tbl.FilterToIterator(q);
   for (; class_it; ++class_it) {
     auto class_id = class_it.id();
-    auto obj_it = objects_tbl.FilterToIterator(
-        {objects_tbl.type_id().eq(class_id.value),
-         objects_tbl.upid().eq(seq.current_upid),
-         objects_tbl.graph_sample_ts().eq(seq.current_ts)});
+    Query query;
+    query.constraints = {objects_tbl.type_id().eq(class_id.value),
+                         objects_tbl.upid().eq(seq.current_upid),
+                         objects_tbl.graph_sample_ts().eq(seq.current_ts)};
+    auto obj_it = objects_tbl.FilterToIterator(query);
     for (; obj_it; ++obj_it) {
       ObjectTable::Id cleaner_obj_id = obj_it.id();
       std::optional<ObjectTable::Id> referent_id =
diff --git a/src/trace_processor/importers/proto/network_trace_module_unittest.cc b/src/trace_processor/importers/proto/network_trace_module_unittest.cc
index 79ba5de..0d9f53c 100644
--- a/src/trace_processor/importers/proto/network_trace_module_unittest.cc
+++ b/src/trace_processor/importers/proto/network_trace_module_unittest.cc
@@ -70,7 +70,9 @@
   bool HasArg(ArgSetId sid, base::StringView key, Variadic value) {
     StringId key_id = storage_->InternString(key);
     const auto& a = storage_->arg_table();
-    for (auto it = a.FilterToIterator({a.arg_set_id().eq(sid)}); it; ++it) {
+    Query q;
+    q.constraints = {a.arg_set_id().eq(sid)};
+    for (auto it = a.FilterToIterator(q); it; ++it) {
       if (it.key() == key_id) {
         EXPECT_EQ(it.flat_key(), key_id);
         if (storage_->GetArgValue(it.row_number().row_number()) == value) {
diff --git a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
index 545418f..20e0085 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
@@ -298,7 +298,9 @@
 
   bool HasArg(ArgSetId set_id, StringId key_id, Variadic value) {
     const auto& args = storage_->arg_table();
-    RowMap rm = args.QueryToRowMap({args.arg_set_id().eq(set_id)}, {});
+    Query q;
+    q.constraints = {args.arg_set_id().eq(set_id)};
+    RowMap rm = args.QueryToRowMap(q);
     bool found = false;
     for (auto it = rm.IterateRows(); it; it.Next()) {
       if (args.key()[it.index()] == key_id) {
@@ -448,7 +450,9 @@
   auto set_id = raw.arg_set_id()[raw.row_count() - 1];
 
   const auto& args = storage_->arg_table();
-  RowMap rm = args.QueryToRowMap({args.arg_set_id().eq(set_id)}, {});
+  Query q;
+  q.constraints = {args.arg_set_id().eq(set_id)};
+  RowMap rm = args.QueryToRowMap(q);
 
   auto row = rm.Get(0);
 
diff --git a/src/trace_processor/importers/proto/winscope/BUILD.gn b/src/trace_processor/importers/proto/winscope/BUILD.gn
index 47e5cb4..93f9d1b 100644
--- a/src/trace_processor/importers/proto/winscope/BUILD.gn
+++ b/src/trace_processor/importers/proto/winscope/BUILD.gn
@@ -41,6 +41,8 @@
     "../../../../../protos/perfetto/trace/android:zero",
     "../../../../../protos/perfetto/trace/interned_data:zero",
     "../../../../../protos/perfetto/trace/profiling:zero",
+    "../../../../protozero",
+    "../../../containers",
     "../../../storage",
     "../../../tables",
     "../../../types",
diff --git a/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.cc b/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.cc
index caf481d..1cfd530 100644
--- a/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.cc
+++ b/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.cc
@@ -14,16 +14,15 @@
  * limitations under the License.
  */
 
-#include "protolog_messages_tracker.h"
-#include "perfetto/ext/base/crash_keys.h"
-#include "src/trace_processor/importers/common/process_tracker.h"
-#include "src/trace_processor/storage/metadata.h"
-#include "src/trace_processor/types/trace_processor_context.h"
+#include "src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h"
 
-namespace perfetto {
-namespace trace_processor {
-ProtoLogMessagesTracker::ProtoLogMessagesTracker() {}
+#include <cstdint>
+#include <optional>
+#include <vector>
 
+namespace perfetto::trace_processor {
+
+ProtoLogMessagesTracker::ProtoLogMessagesTracker() = default;
 ProtoLogMessagesTracker::~ProtoLogMessagesTracker() = default;
 
 void ProtoLogMessagesTracker::TrackMessage(
@@ -34,18 +33,14 @@
       .first->emplace_back(tracked_protolog_message);
 }
 
-const std::optional<
-    std::vector<ProtoLogMessagesTracker::TrackedProtoLogMessage>*>
+std::optional<std::vector<ProtoLogMessagesTracker::TrackedProtoLogMessage>*>
 ProtoLogMessagesTracker::GetTrackedMessagesByMessageId(uint64_t message_id) {
-  auto tracked_messages = tracked_protolog_messages.Find(message_id);
-
+  auto* tracked_messages = tracked_protolog_messages.Find(message_id);
   if (tracked_messages == nullptr) {
     // No tracked messages found for this id
     return std::nullopt;
   }
-
   return tracked_messages;
 }
 
-}  // namespace trace_processor
-}  // namespace perfetto
+}  // namespace perfetto::trace_processor
diff --git a/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h b/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h
index 0f47c32..de0285f 100644
--- a/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h
+++ b/src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h
@@ -17,12 +17,18 @@
 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_MESSAGES_TRACKER_H_
 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_MESSAGES_TRACKER_H_
 
-#include "perfetto/trace_processor/basic_types.h"
+#include <cstdint>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "perfetto/ext/base/flat_hash_map.h"
 #include "src/trace_processor/storage/trace_storage.h"
+#include "src/trace_processor/tables/winscope_tables_py.h"
+#include "src/trace_processor/types/destructible.h"
 #include "src/trace_processor/types/trace_processor_context.h"
 
-namespace perfetto {
-namespace trace_processor {
+namespace perfetto::trace_processor {
 
 class ProtoLogMessagesTracker : public Destructible {
  public:
@@ -41,16 +47,15 @@
   };
 
   static ProtoLogMessagesTracker* GetOrCreate(TraceProcessorContext* context) {
-    if (!context->shell_transitions_tracker) {
-      context->shell_transitions_tracker.reset(new ProtoLogMessagesTracker());
+    if (!context->protolog_messages_tracker) {
+      context->protolog_messages_tracker.reset(new ProtoLogMessagesTracker());
     }
     return static_cast<ProtoLogMessagesTracker*>(
-        context->shell_transitions_tracker.get());
+        context->protolog_messages_tracker.get());
   }
 
   void TrackMessage(TrackedProtoLogMessage tracked_protolog_message);
-  const std::optional<
-      std::vector<ProtoLogMessagesTracker::TrackedProtoLogMessage>*>
+  std::optional<std::vector<ProtoLogMessagesTracker::TrackedProtoLogMessage>*>
   GetTrackedMessagesByMessageId(uint64_t message_id);
 
  private:
@@ -58,7 +63,6 @@
       tracked_protolog_messages;
 };
 
-}  // namespace trace_processor
-}  // namespace perfetto
+}  // namespace perfetto::trace_processor
 
 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_MESSAGES_TRACKER_H_
diff --git a/src/trace_processor/importers/proto/winscope/protolog_parser.cc b/src/trace_processor/importers/proto/winscope/protolog_parser.cc
index 15c19ac..a95777d 100644
--- a/src/trace_processor/importers/proto/winscope/protolog_parser.cc
+++ b/src/trace_processor/importers/proto/winscope/protolog_parser.cc
@@ -15,23 +15,33 @@
  */
 
 #include "src/trace_processor/importers/proto/winscope/protolog_parser.h"
-#include "src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h"
 
+#include <cinttypes>
+#include <cstddef>
+#include <cstdint>
+#include <optional>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "perfetto/ext/base/flat_hash_map.h"
 #include "perfetto/ext/base/string_utils.h"
+#include "perfetto/ext/base/string_view.h"
+#include "perfetto/protozero/field.h"
 #include "protos/perfetto/trace/android/protolog.pbzero.h"
 #include "protos/perfetto/trace/interned_data/interned_data.pbzero.h"
 #include "protos/perfetto/trace/profiling/profile_common.pbzero.h"
 #include "protos/perfetto/trace/profiling/profile_packet.pbzero.h"
-#include "src/trace_processor/importers/common/args_tracker.h"
+#include "src/trace_processor/containers/string_pool.h"
 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
+#include "src/trace_processor/importers/proto/winscope/protolog_messages_tracker.h"
 #include "src/trace_processor/importers/proto/winscope/winscope.descriptor.h"
-#include "src/trace_processor/importers/proto/winscope/winscope_args_parser.h"
+#include "src/trace_processor/storage/stats.h"
 #include "src/trace_processor/storage/trace_storage.h"
+#include "src/trace_processor/tables/winscope_tables_py.h"
 #include "src/trace_processor/types/trace_processor_context.h"
 
-#include <sstream>
-namespace perfetto {
-namespace trace_processor {
+namespace perfetto::trace_processor {
 
 enum ProtoLogLevel : int32_t {
   DEBUG = 1,
@@ -79,44 +89,27 @@
 
   std::vector<std::string> string_params;
   if (protolog_message.has_str_param_iids()) {
-    if (sequence_state->state()->IsIncrementalStateValid()) {
-      for (auto it = protolog_message.str_param_iids(); it; ++it) {
-        auto decoder =
-            sequence_state->state()
-                ->current_generation()
-                ->LookupInternedMessage<protos::pbzero::InternedData::
-                                            kProtologStringArgsFieldNumber,
-                                        protos::pbzero::InternedString>(
-                    it.field().as_uint32());
-
-        if (!decoder) {
-          // This shouldn't happen since we already checked the incremental
-          // state is valid.
-          string_params.emplace_back("<ERROR>");
-          context_->storage->IncrementStats(
-              stats::winscope_protolog_missing_interned_arg_parse_errors);
-          continue;
-        }
-
-        string_params.emplace_back(decoder->str().ToStdString());
+    for (auto it = protolog_message.str_param_iids(); it; ++it) {
+      auto* decoder = sequence_state->LookupInternedMessage<
+          protos::pbzero::InternedData::kProtologStringArgsFieldNumber,
+          protos::pbzero::InternedString>(it.field().as_uint32());
+      if (!decoder) {
+        // This shouldn't happen since we already checked the incremental
+        // state is valid.
+        string_params.emplace_back("<ERROR>");
+        context_->storage->IncrementStats(
+            stats::winscope_protolog_missing_interned_arg_parse_errors);
+        continue;
       }
-    } else {
-      // If the incremental state is not valid we will not be able to decode
-      // the interned strings correctly with 100% certainty so we will provide
-      // string parameters that are not decoded.
-      string_params.emplace_back("<MISSING_STR_ARG>");
+      string_params.emplace_back(decoder->str().ToStdString());
     }
   }
 
   std::optional<StringId> stacktrace = std::nullopt;
   if (protolog_message.has_stacktrace_iid()) {
-    auto stacktrace_decoder =
-        sequence_state->state()
-            ->current_generation()
-            ->LookupInternedMessage<
-                protos::pbzero::InternedData::kProtologStacktraceFieldNumber,
-                protos::pbzero::InternedString>(
-                protolog_message.stacktrace_iid());
+    auto* stacktrace_decoder = sequence_state->LookupInternedMessage<
+        protos::pbzero::InternedData::kProtologStacktraceFieldNumber,
+        protos::pbzero::InternedString>(protolog_message.stacktrace_iid());
 
     if (!stacktrace_decoder) {
       // This shouldn't happen since we already checked the incremental
@@ -135,7 +128,7 @@
   tables::ProtoLogTable::Row row;
   auto row_id = protolog_table->Insert(row).id;
 
-  auto protolog_message_tracker =
+  auto* protolog_message_tracker =
       ProtoLogMessagesTracker::GetOrCreate(context_);
   struct ProtoLogMessagesTracker::TrackedProtoLogMessage tracked_message = {
       protolog_message.message_id(),
@@ -154,13 +147,13 @@
 
   protos::pbzero::ProtoLogViewerConfig::Decoder protolog_viewer_config(blob);
 
-  std::unordered_map<uint32_t, std::string> group_tags;
+  base::FlatHashMap<uint32_t, std::string> group_tags;
   for (auto it = protolog_viewer_config.groups(); it; ++it) {
     protos::pbzero::ProtoLogViewerConfig::Group::Decoder group(*it);
-    group_tags.insert({group.id(), group.tag().ToStdString()});
+    group_tags.Insert(group.id(), group.tag().ToStdString());
   }
 
-  auto protolog_message_tracker =
+  auto* protolog_message_tracker =
       ProtoLogMessagesTracker::GetOrCreate(context_);
 
   for (auto it = protolog_viewer_config.messages(); it; ++it) {
@@ -172,7 +165,7 @@
             message_data.message_id());
 
     if (tracked_messages_opt.has_value()) {
-      auto group_tag = group_tags.find(message_data.group_id())->second;
+      auto* group_tag = group_tags.Find(message_data.group_id());
 
       for (const auto& tracked_message : *tracked_messages_opt.value()) {
         auto formatted_message = FormatMessage(
@@ -211,7 +204,8 @@
         }
         row.set_level(level);
 
-        auto tag = context_->storage->InternString(base::StringView(group_tag));
+        auto tag =
+            context_->storage->InternString(base::StringView(*group_tag));
         row.set_tag(tag);
 
         auto message = context_->storage->InternString(
@@ -227,7 +221,7 @@
 }
 
 std::string ProtoLogParser::FormatMessage(
-    const std::string message,
+    const std::string& message,
     const std::vector<int64_t>& sint64_params,
     const std::vector<double>& double_params,
     const std::vector<bool>& boolean_params,
@@ -282,13 +276,14 @@
           break;
         }
         case 's': {
-          formatted_message.append(str_params_itr->c_str());
+          formatted_message.append(*str_params_itr);
           ++str_params_itr;
           break;
-          case 'b':
-            formatted_message.append(*boolean_params_itr ? "true" : "false");
-            ++boolean_params_itr;
-            break;
+        }
+        case 'b': {
+          formatted_message.append(*boolean_params_itr ? "true" : "false");
+          ++boolean_params_itr;
+          break;
         }
         default:
           // Should never happen
@@ -306,5 +301,4 @@
   return formatted_message;
 }
 
-}  // namespace trace_processor
-}  // namespace perfetto
+}  // namespace perfetto::trace_processor
diff --git a/src/trace_processor/importers/proto/winscope/protolog_parser.h b/src/trace_processor/importers/proto/winscope/protolog_parser.h
index 97d9183..4c0db6f 100644
--- a/src/trace_processor/importers/proto/winscope/protolog_parser.h
+++ b/src/trace_processor/importers/proto/winscope/protolog_parser.h
@@ -17,15 +17,15 @@
 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_PARSER_H_
 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_PARSER_H_
 
-#include "protos/perfetto/trace/android/protolog.pbzero.h"
-#include "src/trace_processor/importers/proto/packet_sequence_state.h"
+#include <cstdint>
+#include <string>
+#include <vector>
+
 #include "src/trace_processor/storage/trace_storage.h"
 #include "src/trace_processor/util/descriptors.h"
 #include "src/trace_processor/util/proto_to_args_parser.h"
 
-namespace perfetto {
-
-namespace trace_processor {
+namespace perfetto::trace_processor {
 
 class TraceProcessorContext;
 
@@ -38,15 +38,12 @@
   void ParseProtoLogViewerConfig(protozero::ConstBytes);
 
  private:
-  std::string FormatMessage(const std::string message,
+  std::string FormatMessage(const std::string& message,
                             const std::vector<int64_t>& sint64_params,
                             const std::vector<double>& double_params,
                             const std::vector<bool>& boolean_params,
                             const std::vector<std::string>& string_params);
 
-  static constexpr auto* kProtoLogMessageProtoName =
-      "perfetto.protos.ProtoLogMessage";
-
   TraceProcessorContext* const context_;
   DescriptorPool pool_;
   util::ProtoToArgsParser args_parser_;
@@ -59,7 +56,6 @@
   const StringId log_level_wtf_string_id_;
   const StringId log_level_unknown_string_id_;
 };
-}  // namespace trace_processor
-}  // namespace perfetto
+}  // namespace perfetto::trace_processor
 
 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_PARSER_H_
diff --git a/src/trace_processor/metrics/sql/android/BUILD.gn b/src/trace_processor/metrics/sql/android/BUILD.gn
index bd77d0a..7de8cf6 100644
--- a/src/trace_processor/metrics/sql/android/BUILD.gn
+++ b/src/trace_processor/metrics/sql/android/BUILD.gn
@@ -56,6 +56,7 @@
     "android_multiuser.sql",
     "android_multiuser_populator.sql",
     "android_netperf.sql",
+    "android_oom_adjuster.sql",
     "android_other_traces.sql",
     "android_package_list.sql",
     "android_powrails.sql",
diff --git a/src/trace_processor/metrics/sql/android/android_boot.sql b/src/trace_processor/metrics/sql/android/android_boot.sql
index 34d1c40..9140387 100644
--- a/src/trace_processor/metrics/sql/android/android_boot.sql
+++ b/src/trace_processor/metrics/sql/android/android_boot.sql
@@ -17,6 +17,7 @@
 INCLUDE PERFETTO MODULE android.process_metadata;
 INCLUDE PERFETTO MODULE android.app_process_starts;
 INCLUDE PERFETTO MODULE android.garbage_collection;
+INCLUDE PERFETTO MODULE android.oom_adjuster;
 
 CREATE OR REPLACE PERFETTO FUNCTION get_durations(process_name STRING)
 RETURNS TABLE(uint_sleep_dur LONG, total_dur LONG) AS
@@ -27,6 +28,55 @@
 INNER JOIN thread ON thread.upid=android_process_metadata.upid
 INNER JOIN thread_state ON thread.utid=thread_state.utid WHERE android_process_metadata.process_name=$process_name;
 
+CREATE OR REPLACE PERFETTO FUNCTION first_user_unlocked() RETURNS INT AS
+SELECT COALESCE(MIN(ts), 0) FROM thread_slice
+WHERE name GLOB "*android.intent.action.USER_UNLOCKED*";
+
+DROP TABLE IF EXISTS _oom_adj_events_with_src_bucket;
+CREATE PERFETTO TABLE _oom_adj_events_with_src_bucket
+AS
+SELECT
+  LAG(bucket) OVER (PARTITION BY upid ORDER BY ts) AS src_bucket,
+  ts,
+  bucket,
+  process_name,
+  oom_adj_reason
+FROM android_oom_adj_intervals;
+
+DROP VIEW IF EXISTS oom_adj_events_by_process_name;
+CREATE PERFETTO VIEW oom_adj_events_by_process_name AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  process_name
+FROM _oom_adj_events_with_src_bucket
+  WHERE ts > first_user_unlocked()
+GROUP BY process_name, bucket, src_bucket;
+
+DROP VIEW IF EXISTS oom_adj_events_global_by_bucket;
+CREATE PERFETTO VIEW oom_adj_events_global_by_bucket AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  NULL as name
+FROM _oom_adj_events_with_src_bucket
+WHERE
+  ts > first_user_unlocked()
+GROUP BY bucket, src_bucket;
+
+DROP VIEW IF EXISTS oom_adj_events_by_oom_adj_reason;
+CREATE PERFETTO VIEW oom_adj_events_by_oom_adj_reason AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  oom_adj_reason as name
+FROM _oom_adj_events_with_src_bucket
+WHERE ts > first_user_unlocked()
+GROUP BY bucket, src_bucket, oom_adj_reason;
+
 DROP VIEW IF EXISTS android_boot_output;
 CREATE PERFETTO VIEW android_boot_output AS
 SELECT AndroidBootMetric(
@@ -59,23 +109,23 @@
             'total_start_sum', (SELECT SUM(total_dur) FROM android_app_process_starts),
             'num_of_processes', (SELECT COUNT(*) FROM android_app_process_starts),
             'average_start_time', (SELECT AVG(total_dur) FROM android_app_process_starts)))
-            FROM android_app_process_starts),
+          FROM android_app_process_starts),
     'post_boot_process_start_aggregation', (
         SELECT NULL_IF_EMPTY(AndroidBootMetric_ProcessStartAggregation(
-            'total_start_sum', (SELECT SUM(total_dur) FROM android_app_process_starts
-              WHERE proc_start_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
+            'total_start_sum', (
+              SELECT SUM(total_dur)
+              FROM android_app_process_starts
+              WHERE proc_start_ts > first_user_unlocked()
             ),
-            'num_of_processes', (SELECT COUNT(*) FROM android_app_process_starts
-              WHERE proc_start_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+            'num_of_processes', (
+              SELECT COUNT(*)
+              FROM android_app_process_starts
+              WHERE proc_start_ts > first_user_unlocked()
             ),
-            'average_start_time', (SELECT AVG(total_dur) FROM android_app_process_starts
-              WHERE proc_start_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+            'average_start_time', (
+              SELECT AVG(total_dur)
+              FROM android_app_process_starts
+              WHERE proc_start_ts > first_user_unlocked()
             )
         ))
     ),
@@ -85,16 +135,23 @@
             ),
             'num_of_processes_with_gc', (SELECT COUNT(process_name) FROM android_garbage_collection_events
             ),
-            'num_of_threads_with_gc', (SELECT SUM(cnt) FROM (SELECT COUNT(*) AS cnt
-              FROM android_garbage_collection_events
-              GROUP by thread_name, process_name)
+            'num_of_threads_with_gc', (
+              SELECT SUM(cnt) FROM (
+                SELECT COUNT(*) AS cnt
+                FROM android_garbage_collection_events
+                GROUP by thread_name, process_name
+              )
             ),
             'avg_gc_duration', (SELECT AVG(gc_dur) FROM android_garbage_collection_events),
             'avg_running_gc_duration', (SELECT AVG(gc_running_dur) FROM android_garbage_collection_events),
-            'full_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
+            'full_gc_count', (
+              SELECT COUNT(*)
+              FROM android_garbage_collection_events
               WHERE gc_type = "full"
             ),
-            'collector_transition_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
+            'collector_transition_gc_count', (
+              SELECT COUNT(*)
+              FROM android_garbage_collection_events
               WHERE gc_type = "collector_transition"
             ),
             'young_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
@@ -117,68 +174,153 @@
     'post_boot_gc_aggregation', (
         SELECT NULL_IF_EMPTY(AndroidBootMetric_GarbageCollectionAggregation(
             'total_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
+              WHERE gc_ts > first_user_unlocked()
             ),
             'num_of_processes_with_gc', (SELECT COUNT(process_name) FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
+              WHERE gc_ts > first_user_unlocked()
             ),
             'num_of_threads_with_gc', (SELECT SUM(cnt) FROM (SELECT COUNT(*) AS cnt
               FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+              WHERE gc_ts > first_user_unlocked()
               GROUP by thread_name, process_name)
             ),
             'avg_gc_duration', (SELECT AVG(gc_dur) FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+              WHERE gc_ts > first_user_unlocked()
             ),
             'avg_running_gc_duration', (SELECT AVG(gc_running_dur) FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+              WHERE gc_ts > first_user_unlocked()
             ),
             'full_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "full" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
+              WHERE gc_type = "full" AND gc_ts > first_user_unlocked()
             ),
             'collector_transition_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "collector_transition" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
+              WHERE gc_type = "collector_transition" AND gc_ts > (
+                SELECT COALESCE(MIN(ts), 0)
+                FROM thread_slice
+                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
+                ORDER BY ts ASC LIMIT 1
+              )
             ),
-            'young_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "young" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
-            ),
-            'native_alloc_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "native_alloc" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
-            ),
-            'explicit_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "explicit_gc" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
-            ),
-            'alloc_gc_count', (SELECT COUNT(*) FROM android_garbage_collection_events
-              WHERE gc_type = "alloc_gc" AND gc_ts > (SELECT COALESCE(MIN(ts), 0)
-                FROM thread_slice WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
-                ORDER BY ts ASC LIMIT 1 )
-            ),
-            'mb_per_ms_of_gc', (SELECT SUM(reclaimed_mb)/SUM(gc_running_dur/1e6) AS mb_per_ms_dur
+            'young_gc_count', (
+              SELECT COUNT(*)
               FROM android_garbage_collection_events
-              WHERE gc_ts > (SELECT COALESCE(MIN(ts), 0) FROM thread_slice
-                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*" ORDER BY ts
-                ASC LIMIT 1 )
+              WHERE gc_type = "young" AND gc_ts > (
+                SELECT COALESCE(MIN(ts), 0)
+                FROM thread_slice
+                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
+                ORDER BY ts ASC LIMIT 1
+              )
+            ),
+            'native_alloc_gc_count', (
+              SELECT COUNT(*)
+              FROM android_garbage_collection_events
+              WHERE gc_type = "native_alloc" AND gc_ts > first_user_unlocked()
+            ),
+            'explicit_gc_count', (
+              SELECT COUNT(*) FROM android_garbage_collection_events
+              WHERE gc_type = "explicit_gc" AND gc_ts > (
+                SELECT COALESCE(MIN(ts), 0)
+                FROM thread_slice
+                WHERE name GLOB "*android.intent.action.USER_UNLOCKED*"
+                ORDER BY ts ASC LIMIT 1
+              )
+            ),
+            'alloc_gc_count', (
+              SELECT COUNT(*) FROM android_garbage_collection_events
+              WHERE gc_type = "alloc_gc" AND gc_ts > first_user_unlocked()
+            ),
+            'mb_per_ms_of_gc', (
+              SELECT
+                SUM(reclaimed_mb)/SUM(gc_running_dur/1e6) AS mb_per_ms_dur
+              FROM android_garbage_collection_events
+              WHERE gc_ts > first_user_unlocked()
             )
         ))
+    ),
+    'post_boot_oom_adjuster_transition_counts_by_process', (
+      SELECT RepeatedField(
+        AndroidBootMetric_OomAdjusterTransitionCounts(
+          'name', process_name,
+          'src_bucket', src_bucket,
+          'dest_bucket', bucket,
+          'count', count
+        )
+      ) FROM oom_adj_events_by_process_name
+    ),
+    'post_boot_oom_adjuster_transition_counts_global', (
+      SELECT RepeatedField(
+        AndroidBootMetric_OomAdjusterTransitionCounts(
+          'name', name,
+          'src_bucket', src_bucket,
+          'dest_bucket', bucket,
+          'count', count
+        )
+      )
+      FROM oom_adj_events_global_by_bucket
+    ),
+    'post_boot_oom_adjuster_transition_counts_by_oom_adj_reason',(
+      SELECT RepeatedField(
+        AndroidBootMetric_OomAdjusterTransitionCounts(
+          'name', name,
+          'src_bucket', src_bucket,
+          'dest_bucket', bucket,
+          'count', count
+        )
+      )
+      FROM oom_adj_events_by_oom_adj_reason
+    ),
+    'post_boot_oom_adj_bucket_duration_agg_global',(SELECT RepeatedField(
+      AndroidBootMetric_OomAdjBucketDurationAggregation(
+            'name', name,
+            'bucket', bucket,
+            'total_dur', total_dur
+      ))
+      FROM (
+        SELECT
+          NULL as name,
+          bucket,
+          SUM(dur) as total_dur
+        FROM android_oom_adj_intervals
+          WHERE ts > first_user_unlocked()
+        GROUP BY bucket)
+    ),
+    'post_boot_oom_adj_bucket_duration_agg_by_process',(SELECT RepeatedField(
+        AndroidBootMetric_OomAdjBucketDurationAggregation(
+            'name', name,
+            'bucket', bucket,
+            'total_dur', total_dur
+        )
     )
+    FROM (
+      SELECT
+        process_name as name,
+        bucket,
+        SUM(dur) as total_dur
+      FROM android_oom_adj_intervals
+      WHERE ts > first_user_unlocked()
+      AND process_name IS NOT NULL
+      GROUP BY process_name, bucket)
+    ),
+    'post_boot_oom_adj_duration_agg',
+    (SELECT RepeatedField(
+        AndroidBootMetric_OomAdjDurationAggregation(
+            'min_oom_adj_dur', min_oom_adj_dur,
+            'max_oom_adj_dur', max_oom_adj_dur,
+            'avg_oom_adj_dur', avg_oom_adj_dur,
+            'oom_adj_event_count', oom_adj_event_count,
+            'oom_adj_reason', oom_adj_reason
+        )
+    )
+    FROM (
+      SELECT
+        MIN(oom_adj_dur) as min_oom_adj_dur,
+        MAX(oom_adj_dur) as max_oom_adj_dur,
+        AVG(oom_adj_dur) as avg_oom_adj_dur,
+        COUNT(DISTINCT(oom_adj_id)) oom_adj_event_count,
+        oom_adj_reason
+      FROM android_oom_adj_intervals
+      WHERE ts > first_user_unlocked()
+      GROUP BY oom_adj_reason
+    )
+  )
 );
diff --git a/src/trace_processor/metrics/sql/android/android_oom_adjuster.sql b/src/trace_processor/metrics/sql/android/android_oom_adjuster.sql
new file mode 100644
index 0000000..7b752a8
--- /dev/null
+++ b/src/trace_processor/metrics/sql/android/android_oom_adjuster.sql
@@ -0,0 +1,139 @@
+--
+-- 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;
+
+DROP TABLE IF EXISTS _oom_adj_events_with_src_bucket;
+CREATE PERFETTO TABLE _oom_adj_events_with_src_bucket
+AS
+SELECT
+  LAG(bucket) OVER (PARTITION BY upid ORDER BY ts) AS src_bucket,
+  ts,
+  bucket,
+  process_name,
+  oom_adj_reason
+FROM android_oom_adj_intervals;
+
+DROP VIEW IF EXISTS oom_adj_events_by_process_name;
+CREATE PERFETTO VIEW oom_adj_events_by_process_name AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  process_name
+FROM _oom_adj_events_with_src_bucket
+GROUP BY process_name, bucket, src_bucket;
+
+DROP VIEW IF EXISTS oom_adj_events_global_by_bucket;
+CREATE PERFETTO VIEW oom_adj_events_global_by_bucket AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  NULL as name
+FROM _oom_adj_events_with_src_bucket
+GROUP BY bucket, src_bucket;
+
+DROP VIEW IF EXISTS oom_adj_events_by_oom_adj_reason;
+CREATE PERFETTO VIEW oom_adj_events_by_oom_adj_reason AS
+SELECT
+  src_bucket,
+  bucket,
+  count(ts) as count,
+  oom_adj_reason as name
+FROM _oom_adj_events_with_src_bucket
+GROUP BY bucket, src_bucket, oom_adj_reason;
+
+DROP VIEW IF EXISTS android_oom_adjuster_output;
+CREATE PERFETTO VIEW android_oom_adjuster_output AS
+SELECT AndroidOomAdjusterMetric(
+  'oom_adjuster_transition_counts_by_process', (
+    SELECT RepeatedField(
+      AndroidOomAdjusterMetric_OomAdjusterTransitionCounts(
+        'name', process_name,
+        'src_bucket', src_bucket,
+        'dest_bucket', bucket,
+        'count', count
+      )
+    ) FROM oom_adj_events_by_process_name
+  ),
+  'oom_adjuster_transition_counts_global', (
+    SELECT RepeatedField(
+      AndroidOomAdjusterMetric_OomAdjusterTransitionCounts(
+        'name', name,
+        'src_bucket', src_bucket,
+        'dest_bucket', bucket,
+        'count', count
+      )
+    )
+    FROM oom_adj_events_global_by_bucket
+  ),
+  'oom_adjuster_transition_counts_by_oom_adj_reason',(
+    SELECT RepeatedField(
+      AndroidOomAdjusterMetric_OomAdjusterTransitionCounts(
+        'name', name,
+        'src_bucket', src_bucket,
+        'dest_bucket', bucket,
+        'count', count
+      )
+    )
+    FROM oom_adj_events_by_oom_adj_reason
+  ),
+  'oom_adj_bucket_duration_agg_global',(SELECT RepeatedField(
+    AndroidOomAdjusterMetric_OomAdjBucketDurationAggregation(
+          'name', name,
+          'bucket', bucket,
+          'total_dur', total_dur
+        )
+    )
+    FROM (
+        SELECT NULL as name, bucket, SUM(dur) as total_dur
+        FROM android_oom_adj_intervals GROUP BY bucket
+    )
+  ),
+  'oom_adj_bucket_duration_agg_by_process',(SELECT RepeatedField(
+      AndroidOomAdjusterMetric_OomAdjBucketDurationAggregation(
+          'name', name,
+          'bucket', bucket,
+          'total_dur', total_dur
+      )
+    )
+    FROM (
+      SELECT process_name as name, bucket, SUM(dur) as total_dur
+      FROM android_oom_adj_intervals
+      WHERE process_name IS NOT NULL
+      GROUP BY process_name, bucket
+    )
+  ),
+  'oom_adj_duration_agg', (SELECT RepeatedField(
+      AndroidOomAdjusterMetric_OomAdjDurationAggregation(
+          'min_oom_adj_dur', min_oom_adj_dur,
+          'max_oom_adj_dur', max_oom_adj_dur,
+          'avg_oom_adj_dur', avg_oom_adj_dur,
+          'oom_adj_event_count', oom_adj_event_count,
+          'oom_adj_reason', oom_adj_reason
+      )
+    )
+    FROM (
+      SELECT
+        MIN(oom_adj_dur) as min_oom_adj_dur,
+        MAX(oom_adj_dur) as max_oom_adj_dur,
+        AVG(oom_adj_dur) as avg_oom_adj_dur,
+        COUNT(DISTINCT(oom_adj_id)) oom_adj_event_count,
+        oom_adj_reason
+      FROM android_oom_adj_intervals GROUP BY oom_adj_reason
+    )
+  )
+);
diff --git a/src/trace_processor/metrics/sql/chrome/chrome_scroll_inputs_per_frame.sql b/src/trace_processor/metrics/sql/chrome/chrome_scroll_inputs_per_frame.sql
index c9d69ca..94d2794 100644
--- a/src/trace_processor/metrics/sql/chrome/chrome_scroll_inputs_per_frame.sql
+++ b/src/trace_processor/metrics/sql/chrome/chrome_scroll_inputs_per_frame.sql
@@ -20,18 +20,23 @@
 -- 1 input per frame as flings are generated once per vsync.
 -- The numbers mentioned above are estimates in the ideal case scenario.
 
+INCLUDE PERFETTO MODULE chrome.scroll_jank.utils;
+INCLUDE PERFETTO MODULE common.slices;
+
 -- Grab all GestureScrollUpdate slices.
 DROP VIEW IF EXISTS chrome_all_scroll_updates;
 CREATE PERFETTO VIEW chrome_all_scroll_updates AS
 SELECT
-  id,
-  EXTRACT_ARG(arg_set_id, 'chrome_latency_info.gesture_scroll_id') AS scroll_id,
-  EXTRACT_ARG(arg_set_id, 'chrome_latency_info.is_coalesced') AS is_coalesced,
+  S.id,
+  chrome_get_most_recent_scroll_begin_id(ts) AS scroll_id,
+  has_descendant_slice_with_name(S.id, "SubmitCompositorFrameToPresentationCompositorFrame")
+  AS is_presented,
   ts,
   dur,
   track_id
-FROM slice
-WHERE name = "InputLatency::GestureScrollUpdate";
+FROM slice S JOIN args USING(arg_set_id)
+WHERE NAME = "EventLatency"
+AND args.string_value GLOB "*GESTURE_SCROLL_UPDATE";
 
 -- Count number of input GestureScrollUpdates per scroll.
 DROP VIEW IF EXISTS chrome_update_count_per_scroll;
@@ -46,26 +51,26 @@
 
 -- Count the number of input GestureScrollUpdates that were converted
 -- frames per scroll.
-DROP VIEW IF EXISTS chrome_non_coalesced_update_count_per_scroll;
-CREATE PERFETTO VIEW chrome_non_coalesced_update_count_per_scroll AS
+DROP VIEW IF EXISTS chrome_presented_update_count_per_scroll;
+CREATE PERFETTO VIEW chrome_presented_update_count_per_scroll AS
 SELECT
-  CAST(COUNT() AS FLOAT) AS non_coalesced_count,
+  CAST(COUNT() AS FLOAT) AS presented_count,
   scroll_id,
   id,
   track_id,
   dur
 FROM chrome_all_scroll_updates
-WHERE NOT is_coalesced
+WHERE is_presented
 GROUP BY scroll_id;
 
 -- Get the average number of inputs per frame per scroll.
 DROP VIEW IF EXISTS chrome_avg_scroll_inputs_per_frame;
 CREATE PERFETTO VIEW chrome_avg_scroll_inputs_per_frame AS
 SELECT
-  count / non_coalesced_count AS avg_inputs_per_frame_per_scroll,
+  count / presented_count AS avg_inputs_per_frame_per_scroll,
   scroll_id,
-  non_coalesced_count
-FROM chrome_non_coalesced_update_count_per_scroll
+  presented_count
+FROM chrome_presented_update_count_per_scroll
 JOIN chrome_update_count_per_scroll USING(scroll_id);
 
 -- Get the last scroll update event that wasn't coalesced before the
@@ -75,14 +80,14 @@
 SELECT
   id,
   scroll_id,
-  is_coalesced,
+  is_presented,
   ts,
   dur,
   track_id,
   (SELECT
     MAX(id)
     FROM chrome_all_scroll_updates parent_scrolls
-    WHERE NOT is_coalesced
+    WHERE is_presented
       AND parent_scrolls.ts <= scrolls.ts) AS presented_scroll_id
 FROM chrome_all_scroll_updates scrolls;
 
diff --git a/src/trace_processor/perfetto_sql/intrinsics/functions/to_ftrace.cc b/src/trace_processor/perfetto_sql/intrinsics/functions/to_ftrace.cc
index 59e571f..387664e 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/functions/to_ftrace.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/functions/to_ftrace.cc
@@ -157,7 +157,9 @@
 
   // We assume that the row map is a contiguous range (which is always the case
   // because arg_set_ids are contiguous by definition).
-  row_map_ = args.QueryToRowMap({set_ids.eq(arg_set_id_)}, {});
+  Query q;
+  q.constraints = {set_ids.eq(arg_set_id_)};
+  row_map_ = args.QueryToRowMap(q);
   start_row_ = row_map_.empty() ? 0 : row_map_.Get(0);
 
   // If the vector already has entries, we've previously cached the mapping
diff --git a/src/trace_processor/perfetto_sql/intrinsics/operators/BUILD.gn b/src/trace_processor/perfetto_sql/intrinsics/operators/BUILD.gn
index bbcb771..49a4a81 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/operators/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/intrinsics/operators/BUILD.gn
@@ -18,6 +18,10 @@
 
 source_set("operators") {
   sources = [
+    "counter_mipmap_operator.cc",
+    "counter_mipmap_operator.h",
+    "slice_mipmap_operator.cc",
+    "slice_mipmap_operator.h",
     "span_join_operator.cc",
     "span_join_operator.h",
     "window_operator.cc",
@@ -30,6 +34,7 @@
     "../../../../../include/perfetto/trace_processor",
     "../../../../../protos/perfetto/trace_processor:zero",
     "../../../../base",
+    "../../../containers",
     "../../../sqlite",
     "../../../util",
     "../../engine",
diff --git a/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.cc b/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.cc
new file mode 100644
index 0000000..83321ce
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.cc
@@ -0,0 +1,265 @@
+/*
+ * 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.
+ */
+
+#include "src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h"
+
+#include <sqlite3.h>
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <functional>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "perfetto/base/logging.h"
+#include "perfetto/base/status.h"
+#include "perfetto/ext/base/status_or.h"
+#include "src/trace_processor/containers/implicit_segment_forest.h"
+#include "src/trace_processor/sqlite/bindings/sqlite_result.h"
+#include "src/trace_processor/sqlite/module_lifecycle_manager.h"
+#include "src/trace_processor/sqlite/sql_source.h"
+#include "src/trace_processor/sqlite/sqlite_utils.h"
+
+namespace perfetto::trace_processor {
+namespace {
+
+constexpr char kSchema[] = R"(
+  CREATE TABLE x(
+    in_window_start BIGINT HIDDEN,
+    in_window_end BIGINT HIDDEN,
+    in_window_step BIGINT HIDDEN,
+    min_value DOUBLE,
+    max_value DOUBLE,
+    last_ts BIGINT,
+    last_value DOUBLE,
+    PRIMARY KEY(last_ts)
+  ) WITHOUT ROWID
+)";
+
+enum ColumnIndex : size_t {
+  kInWindowStart = 0,
+  kInWindowEnd,
+  kInWindowStep,
+
+  kMinValue,
+  kMaxValue,
+  kLastTs,
+  kLastValue,
+};
+
+constexpr size_t kArgCount = kInWindowStep + 1;
+
+bool IsArgColumn(size_t index) {
+  return index < kArgCount;
+}
+
+using Counter = CounterMipmapOperator::Counter;
+using Agg = CounterMipmapOperator::Agg;
+using Forest = ImplicitSegmentForest<Counter, Agg>;
+
+}  // namespace
+
+int CounterMipmapOperator::Create(sqlite3* db,
+                                  void* raw_ctx,
+                                  int argc,
+                                  const char* const* argv,
+                                  sqlite3_vtab** vtab,
+                                  char** zErr) {
+  if (argc != 4) {
+    *zErr = sqlite3_mprintf("counter_mipmap: wrong number of arguments");
+    return SQLITE_ERROR;
+  }
+
+  if (int ret = sqlite3_declare_vtab(db, kSchema); ret != SQLITE_OK) {
+    return ret;
+  }
+
+  auto* ctx = GetContext(raw_ctx);
+  auto state = std::make_unique<State>();
+
+  std::string sql = "SELECT ts, value FROM ";
+  sql.append(argv[3]);
+  auto res = ctx->engine->ExecuteUntilLastStatement(
+      SqlSource::FromTraceProcessorImplementation(std::move(sql)));
+  if (!res.ok()) {
+    *zErr = sqlite3_mprintf("%s", res.status().c_message());
+    return SQLITE_ERROR;
+  }
+  do {
+    int64_t ts = sqlite3_column_int64(res->stmt.sqlite_stmt(), 0);
+    auto value =
+        static_cast<float>(sqlite3_column_double(res->stmt.sqlite_stmt(), 1));
+    state->timestamps.push_back(ts);
+    state->forest.Push(Counter{value, value});
+  } while (res->stmt.Step());
+  if (!res->stmt.status().ok()) {
+    *zErr = sqlite3_mprintf("%s", res->stmt.status().c_message());
+    return SQLITE_ERROR;
+  }
+
+  std::unique_ptr<Vtab> vtab_res = std::make_unique<Vtab>();
+  vtab_res->state = ctx->manager.OnCreate(argv, std::move(state));
+  *vtab = vtab_res.release();
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Destroy(sqlite3_vtab* vtab) {
+  std::unique_ptr<Vtab> tab(GetVtab(vtab));
+  sqlite::ModuleStateManager<CounterMipmapOperator>::OnDestroy(tab->state);
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Connect(sqlite3* db,
+                                   void* raw_ctx,
+                                   int argc,
+                                   const char* const* argv,
+                                   sqlite3_vtab** vtab,
+                                   char**) {
+  PERFETTO_CHECK(argc == 4);
+  if (int ret = sqlite3_declare_vtab(db, kSchema); ret != SQLITE_OK) {
+    return ret;
+  }
+  auto* ctx = GetContext(raw_ctx);
+  std::unique_ptr<Vtab> res = std::make_unique<Vtab>();
+  res->state = ctx->manager.OnConnect(argv);
+  *vtab = res.release();
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Disconnect(sqlite3_vtab* vtab) {
+  std::unique_ptr<Vtab> tab(GetVtab(vtab));
+  sqlite::ModuleStateManager<CounterMipmapOperator>::OnDisconnect(tab->state);
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::BestIndex(sqlite3_vtab*, sqlite3_index_info* info) {
+  base::Status status =
+      sqlite::utils::ValidateFunctionArguments(info, kArgCount, IsArgColumn);
+  if (!status.ok()) {
+    return SQLITE_CONSTRAINT;
+  }
+  if (info->nConstraint != kArgCount) {
+    return SQLITE_CONSTRAINT;
+  }
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Open(sqlite3_vtab*, sqlite3_vtab_cursor** cursor) {
+  std::unique_ptr<Cursor> c = std::make_unique<Cursor>();
+  *cursor = c.release();
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Close(sqlite3_vtab_cursor* cursor) {
+  std::unique_ptr<Cursor> c(GetCursor(cursor));
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Filter(sqlite3_vtab_cursor* cursor,
+                                  int,
+                                  const char*,
+                                  int argc,
+                                  sqlite3_value** argv) {
+  auto* c = GetCursor(cursor);
+  auto* t = GetVtab(c->pVtab);
+  auto* state =
+      sqlite::ModuleStateManager<CounterMipmapOperator>::GetState(t->state);
+  PERFETTO_CHECK(argc == kArgCount);
+
+  int64_t start_ts = sqlite3_value_int64(argv[0]);
+  int64_t end_ts = sqlite3_value_int64(argv[1]);
+  int64_t step_ts = sqlite3_value_int64(argv[2]);
+  if (start_ts == end_ts) {
+    return sqlite::utils::SetError(t, "counter_mipmap: empty range provided");
+  }
+
+  c->index = 0;
+  c->counters.clear();
+
+  // If there is a counter value before the start of this window, include it in
+  // the aggregation as well becaue it contributes to what should be rendered
+  // here.
+  auto ts_lb = std::lower_bound(state->timestamps.begin(),
+                                state->timestamps.end(), start_ts);
+  if (ts_lb != state->timestamps.begin() &&
+      (ts_lb == state->timestamps.end() || *ts_lb != start_ts)) {
+    --ts_lb;
+  }
+  int64_t start_idx = std::distance(state->timestamps.begin(), ts_lb);
+  for (int64_t s = start_ts; s < end_ts; s += step_ts) {
+    int64_t end_idx =
+        std::distance(state->timestamps.begin(),
+                      std::lower_bound(state->timestamps.begin() +
+                                           static_cast<int64_t>(start_idx),
+                                       state->timestamps.end(), s + step_ts));
+    if (start_idx == end_idx) {
+      continue;
+    }
+    c->counters.emplace_back(Cursor::Result{
+        state->forest.Query(static_cast<uint32_t>(start_idx),
+                            static_cast<uint32_t>(end_idx)),
+        state->forest[static_cast<uint32_t>(end_idx) - 1],
+        state->timestamps[static_cast<uint32_t>(end_idx) - 1],
+    });
+    start_idx = end_idx;
+  }
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Next(sqlite3_vtab_cursor* cursor) {
+  GetCursor(cursor)->index++;
+  return SQLITE_OK;
+}
+
+int CounterMipmapOperator::Eof(sqlite3_vtab_cursor* cursor) {
+  auto* c = GetCursor(cursor);
+  return c->index >= c->counters.size();
+}
+
+int CounterMipmapOperator::Column(sqlite3_vtab_cursor* cursor,
+                                  sqlite3_context* ctx,
+                                  int N) {
+  auto* t = GetVtab(cursor->pVtab);
+  auto* c = GetCursor(cursor);
+  const auto& res = c->counters[c->index];
+  switch (N) {
+    case ColumnIndex::kMinValue:
+      sqlite::result::Double(ctx, static_cast<double>(res.min_max_counter.min));
+      return SQLITE_OK;
+    case ColumnIndex::kMaxValue:
+      sqlite::result::Double(ctx, static_cast<double>(res.min_max_counter.max));
+      return SQLITE_OK;
+    case ColumnIndex::kLastTs:
+      sqlite::result::Long(ctx, res.last_ts);
+      return SQLITE_OK;
+    case ColumnIndex::kLastValue:
+      PERFETTO_DCHECK(
+          std::equal_to<>()(res.last_counter.min, res.last_counter.max));
+      sqlite::result::Double(ctx, static_cast<double>(res.last_counter.min));
+      return SQLITE_OK;
+    default:
+      return sqlite::utils::SetError(t, "Bad column");
+  }
+  PERFETTO_FATAL("For GCC");
+}
+
+int CounterMipmapOperator::Rowid(sqlite3_vtab_cursor*, sqlite_int64*) {
+  return SQLITE_ERROR;
+}
+
+}  // namespace perfetto::trace_processor
diff --git a/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h b/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h
new file mode 100644
index 0000000..1b0897c
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_COUNTER_MIPMAP_OPERATOR_H_
+#define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_COUNTER_MIPMAP_OPERATOR_H_
+
+#include <sqlite3.h>
+#include <cstdint>
+#include <vector>
+
+#include "src/trace_processor/containers/implicit_segment_forest.h"
+#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_engine.h"
+#include "src/trace_processor/sqlite/bindings/sqlite_module.h"
+#include "src/trace_processor/sqlite/module_lifecycle_manager.h"
+
+namespace perfetto::trace_processor {
+
+// Operator for building "mipmaps" [1] over the counter-like tracks.
+//
+// In the context of trace data, mipmap really means aggregating the counter
+// values in a given time period into the {min, max, last} value for that
+// period, allowing UIs to efficiently display the contents of a counter track
+// when very zoomed out.
+//
+// Specifically, we are computing the query:
+// ```
+//   select
+//     last_value(ts),
+//     min(value),
+//     max(value),
+//     last_value(value)
+//   from $input in
+//   where in.ts_end >= $window_start and in.ts <= $window_end
+//   group by ts / $window_resolution
+//   order by ts
+// ```
+// but in O(logn) time by using a segment-tree like data structure (see
+// ImplicitSegmentForest).
+//
+// [1] https://en.wikipedia.org/wiki/Mipmap
+struct CounterMipmapOperator : sqlite::Module<CounterMipmapOperator> {
+  struct Counter {
+    float min;
+    float max;
+  };
+  struct Agg {
+    Counter operator()(const Counter& a, const Counter& b) {
+      Counter res;
+      res.min = b.min < a.min ? b.min : a.min;
+      res.max = b.max > a.max ? b.max : a.max;
+      return res;
+    }
+  };
+  struct State {
+    ImplicitSegmentForest<Counter, Agg> forest;
+    std::vector<int64_t> timestamps;
+  };
+  struct Context {
+    explicit Context(PerfettoSqlEngine* _engine) : engine(_engine) {}
+    PerfettoSqlEngine* engine;
+    sqlite::ModuleStateManager<CounterMipmapOperator> manager;
+  };
+  struct Vtab : sqlite::Module<CounterMipmapOperator>::Vtab {
+    sqlite::ModuleStateManager<CounterMipmapOperator>::PerVtabState* state;
+  };
+  struct Cursor : sqlite::Module<CounterMipmapOperator>::Cursor {
+    struct Result {
+      Counter min_max_counter;
+      Counter last_counter;
+      int64_t last_ts;
+    };
+    std::vector<Result> counters;
+    uint32_t index;
+  };
+
+  static constexpr auto kType = kCreateOnly;
+  static constexpr bool kSupportsWrites = false;
+  static constexpr bool kDoesOverloadFunctions = false;
+
+  static int Create(sqlite3*,
+                    void*,
+                    int,
+                    const char* const*,
+                    sqlite3_vtab**,
+                    char**);
+  static int Destroy(sqlite3_vtab*);
+
+  static int Connect(sqlite3*,
+                     void*,
+                     int,
+                     const char* const*,
+                     sqlite3_vtab**,
+                     char**);
+  static int Disconnect(sqlite3_vtab*);
+
+  static int BestIndex(sqlite3_vtab*, sqlite3_index_info*);
+
+  static int Open(sqlite3_vtab*, sqlite3_vtab_cursor**);
+  static int Close(sqlite3_vtab_cursor*);
+
+  static int Filter(sqlite3_vtab_cursor*,
+                    int,
+                    const char*,
+                    int,
+                    sqlite3_value**);
+  static int Next(sqlite3_vtab_cursor*);
+  static int Eof(sqlite3_vtab_cursor*);
+  static int Column(sqlite3_vtab_cursor*, sqlite3_context*, int);
+  static int Rowid(sqlite3_vtab_cursor*, sqlite_int64*);
+};
+
+}  // namespace perfetto::trace_processor
+
+#endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_COUNTER_MIPMAP_OPERATOR_H_
diff --git a/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.cc b/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.cc
new file mode 100644
index 0000000..6fe6956
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.cc
@@ -0,0 +1,275 @@
+/*
+ * 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.
+ */
+
+#include "src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h"
+
+#include <sqlite3.h>
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "perfetto/base/logging.h"
+#include "perfetto/base/status.h"
+#include "perfetto/ext/base/status_or.h"
+#include "perfetto/public/compiler.h"
+#include "src/trace_processor/containers/implicit_segment_forest.h"
+#include "src/trace_processor/sqlite/bindings/sqlite_result.h"
+#include "src/trace_processor/sqlite/module_lifecycle_manager.h"
+#include "src/trace_processor/sqlite/sql_source.h"
+#include "src/trace_processor/sqlite/sqlite_utils.h"
+
+namespace perfetto::trace_processor {
+namespace {
+
+constexpr char kSliceSchema[] = R"(
+  CREATE TABLE x(
+    in_window_start BIGINT HIDDEN,
+    in_window_end BIGINT HIDDEN,
+    in_window_step BIGINT HIDDEN,
+    ts BIGINT,
+    id BIGINT,
+    dur BIGINT,
+    depth INTEGER,
+    PRIMARY KEY(id)
+  ) WITHOUT ROWID
+)";
+
+enum ColumnIndex : size_t {
+  kInWindowStart = 0,
+  kInWindowEnd,
+  kInWindowStep,
+
+  kTs,
+  kId,
+  kDur,
+  kDepth,
+};
+
+constexpr size_t kArgCount = kInWindowStep + 1;
+
+bool IsArgColumn(size_t index) {
+  return index < kArgCount;
+}
+
+}  // namespace
+
+int SliceMipmapOperator::Create(sqlite3* db,
+                                void* raw_ctx,
+                                int argc,
+                                const char* const* argv,
+                                sqlite3_vtab** vtab,
+                                char** zErr) {
+  if (argc != 4) {
+    *zErr = sqlite3_mprintf("zoom_index_operator: wrong number of arguments");
+    return SQLITE_ERROR;
+  }
+
+  if (int ret = sqlite3_declare_vtab(db, kSliceSchema); ret != SQLITE_OK) {
+    return ret;
+  }
+
+  auto* ctx = GetContext(raw_ctx);
+  auto state = std::make_unique<State>();
+
+  std::string sql = "SELECT * FROM ";
+  sql.append(argv[3]);
+  auto res = ctx->engine->ExecuteUntilLastStatement(
+      SqlSource::FromTraceProcessorImplementation(std::move(sql)));
+  if (!res.ok()) {
+    *zErr =
+        sqlite3_mprintf("zoom_index_operator: %s", res.status().c_message());
+    return SQLITE_ERROR;
+  }
+  do {
+    auto id =
+        static_cast<uint32_t>(sqlite3_column_int64(res->stmt.sqlite_stmt(), 0));
+    int64_t ts = sqlite3_column_int64(res->stmt.sqlite_stmt(), 1);
+    int64_t dur = sqlite3_column_int64(res->stmt.sqlite_stmt(), 2);
+    auto depth =
+        static_cast<uint32_t>(sqlite3_column_int64(res->stmt.sqlite_stmt(), 3));
+    if (PERFETTO_UNLIKELY(depth >= state->by_depth.size())) {
+      state->by_depth.resize(depth + 1);
+    }
+    auto& by_depth = state->by_depth[depth];
+    by_depth.forest.Push(
+        Slice{dur, id, static_cast<uint32_t>(by_depth.forest.size())});
+    by_depth.timestamps.push_back(ts);
+  } while (res->stmt.Step());
+  if (!res->stmt.status().ok()) {
+    *zErr = sqlite3_mprintf("zoom_index_operator: %s",
+                            res->stmt.status().c_message());
+    return SQLITE_ERROR;
+  }
+
+  std::unique_ptr<Vtab> vtab_res = std::make_unique<Vtab>();
+  vtab_res->state = ctx->manager.OnCreate(argv, std::move(state));
+  *vtab = vtab_res.release();
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Destroy(sqlite3_vtab* vtab) {
+  std::unique_ptr<Vtab> tab(GetVtab(vtab));
+  sqlite::ModuleStateManager<SliceMipmapOperator>::OnDestroy(tab->state);
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Connect(sqlite3* db,
+                                 void* raw_ctx,
+                                 int argc,
+                                 const char* const* argv,
+                                 sqlite3_vtab** vtab,
+                                 char**) {
+  PERFETTO_CHECK(argc == 4);
+  if (int ret = sqlite3_declare_vtab(db, kSliceSchema); ret != SQLITE_OK) {
+    return ret;
+  }
+  auto* ctx = GetContext(raw_ctx);
+  std::unique_ptr<Vtab> res = std::make_unique<Vtab>();
+  res->state = ctx->manager.OnConnect(argv);
+  *vtab = res.release();
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Disconnect(sqlite3_vtab* vtab) {
+  std::unique_ptr<Vtab> tab(GetVtab(vtab));
+  sqlite::ModuleStateManager<SliceMipmapOperator>::OnDisconnect(tab->state);
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::BestIndex(sqlite3_vtab*, sqlite3_index_info* info) {
+  base::Status status =
+      sqlite::utils::ValidateFunctionArguments(info, kArgCount, IsArgColumn);
+  if (!status.ok()) {
+    return SQLITE_CONSTRAINT;
+  }
+  if (info->nConstraint != kArgCount) {
+    return SQLITE_CONSTRAINT;
+  }
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Open(sqlite3_vtab*, sqlite3_vtab_cursor** cursor) {
+  std::unique_ptr<Cursor> c = std::make_unique<Cursor>();
+  *cursor = c.release();
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Close(sqlite3_vtab_cursor* cursor) {
+  std::unique_ptr<Cursor> c(GetCursor(cursor));
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Filter(sqlite3_vtab_cursor* cursor,
+                                int,
+                                const char*,
+                                int argc,
+                                sqlite3_value** argv) {
+  auto* c = GetCursor(cursor);
+  auto* t = GetVtab(c->pVtab);
+  auto* state =
+      sqlite::ModuleStateManager<SliceMipmapOperator>::GetState(t->state);
+  PERFETTO_CHECK(argc == kArgCount);
+
+  c->results.clear();
+  c->index = 0;
+
+  int64_t start = sqlite3_value_int64(argv[0]);
+  int64_t end = sqlite3_value_int64(argv[1]);
+  int64_t step = sqlite3_value_int64(argv[2]);
+
+  if (start == end) {
+    return sqlite::utils::SetError(t, "slice_mipmap: empty range provided");
+  }
+
+  for (uint32_t depth = 0; depth < state->by_depth.size(); ++depth) {
+    auto& by_depth = state->by_depth[depth];
+    const auto& tses = by_depth.timestamps;
+
+    // If the slice before this window overlaps with the current window, move
+    // the iterator back one to consider it as well.
+    auto start_idx = static_cast<uint32_t>(std::distance(
+        tses.begin(), std::lower_bound(tses.begin(), tses.end(), start)));
+    if (start_idx != 0 &&
+        (static_cast<size_t>(start_idx) == tses.size() ||
+         tses[start_idx] != start) &&
+        (tses[start_idx] + by_depth.forest[start_idx].dur > start)) {
+      --start_idx;
+    }
+
+    for (int64_t s = start; s < end; s += step) {
+      auto end_idx = static_cast<uint32_t>(std::distance(
+          tses.begin(),
+          std::lower_bound(tses.begin() + static_cast<int64_t>(start_idx),
+                           tses.end(), s + step)));
+      if (start_idx == end_idx) {
+        continue;
+      }
+      auto res = by_depth.forest.Query(start_idx, end_idx);
+      c->results.emplace_back(Cursor::Result{
+          tses[res.idx],
+          res.dur,
+          res.id,
+          depth,
+      });
+      start_idx = end_idx;
+    }
+  }
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Next(sqlite3_vtab_cursor* cursor) {
+  GetCursor(cursor)->index++;
+  return SQLITE_OK;
+}
+
+int SliceMipmapOperator::Eof(sqlite3_vtab_cursor* cursor) {
+  auto* c = GetCursor(cursor);
+  return c->index >= c->results.size();
+}
+
+int SliceMipmapOperator::Column(sqlite3_vtab_cursor* cursor,
+                                sqlite3_context* ctx,
+                                int N) {
+  auto* t = GetVtab(cursor->pVtab);
+  auto* c = GetCursor(cursor);
+  switch (N) {
+    case ColumnIndex::kTs:
+      sqlite::result::Long(ctx, c->results[c->index].timestamp);
+      return SQLITE_OK;
+    case ColumnIndex::kId:
+      sqlite::result::Long(ctx, c->results[c->index].id);
+      return SQLITE_OK;
+    case ColumnIndex::kDur:
+      sqlite::result::Long(ctx, c->results[c->index].dur);
+      return SQLITE_OK;
+    case ColumnIndex::kDepth:
+      sqlite::result::Long(ctx, c->results[c->index].depth);
+      return SQLITE_OK;
+    default:
+      return sqlite::utils::SetError(t, "Bad column");
+  }
+  PERFETTO_FATAL("For GCC");
+}
+
+int SliceMipmapOperator::Rowid(sqlite3_vtab_cursor*, sqlite_int64*) {
+  return SQLITE_ERROR;
+}
+
+}  // namespace perfetto::trace_processor
diff --git a/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h b/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h
new file mode 100644
index 0000000..3291225
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_SLICE_MIPMAP_OPERATOR_H_
+#define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_SLICE_MIPMAP_OPERATOR_H_
+
+#include <sqlite3.h>
+#include <cstdint>
+#include <vector>
+
+#include "src/trace_processor/containers/implicit_segment_forest.h"
+#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_engine.h"
+#include "src/trace_processor/sqlite/bindings/sqlite_module.h"
+#include "src/trace_processor/sqlite/module_lifecycle_manager.h"
+
+namespace perfetto::trace_processor {
+
+// Operator for building "mipmaps"  [1] over the slices in the trace.
+//
+// In this context mipmap really means aggregating the slices in a given
+// time period by max(dur) for that period, allowing UIs to efficiently display
+// the contents of slice tracks when very zoomed out.
+//
+// Specifically, we are computing the query:
+// ```
+//   select
+//     depth,
+//     max(dur) as dur,
+//     id,
+//     ts
+//   from $input in
+//   where in.ts_end >= $window_start and in.ts <= $window_end
+//   group by depth, ts / $window_resolution
+//   order by ts
+// ```
+// but in O(logn) time by using a segment-tree like data structure (see
+// ImplicitSegmentForest).
+//
+// [1] https://en.wikipedia.org/wiki/Mipmap
+struct SliceMipmapOperator : sqlite::Module<SliceMipmapOperator> {
+  struct Slice {
+    int64_t dur;
+    uint32_t id;
+    uint32_t idx;
+  };
+  struct Agg {
+    Slice operator()(const Slice& a, const Slice& b) {
+      return a.dur < b.dur ? b : a;
+    }
+  };
+  struct PerDepth {
+    ImplicitSegmentForest<Slice, Agg> forest;
+    std::vector<int64_t> timestamps;
+  };
+  struct State {
+    std::vector<PerDepth> by_depth;
+  };
+  struct Context {
+    explicit Context(PerfettoSqlEngine* _engine) : engine(_engine) {}
+    PerfettoSqlEngine* engine;
+    sqlite::ModuleStateManager<SliceMipmapOperator> manager;
+  };
+  struct Vtab : sqlite::Module<SliceMipmapOperator>::Vtab {
+    sqlite::ModuleStateManager<SliceMipmapOperator>::PerVtabState* state;
+  };
+  struct Cursor : sqlite::Module<SliceMipmapOperator>::Cursor {
+    struct Result {
+      int64_t timestamp;
+      int64_t dur;
+      uint32_t id;
+      uint32_t depth;
+    };
+    std::vector<Result> results;
+    uint32_t index = 0;
+  };
+
+  static constexpr auto kType = kCreateOnly;
+  static constexpr bool kSupportsWrites = false;
+  static constexpr bool kDoesOverloadFunctions = false;
+
+  static int Create(sqlite3*,
+                    void*,
+                    int,
+                    const char* const*,
+                    sqlite3_vtab**,
+                    char**);
+  static int Destroy(sqlite3_vtab*);
+
+  static int Connect(sqlite3*,
+                     void*,
+                     int,
+                     const char* const*,
+                     sqlite3_vtab**,
+                     char**);
+  static int Disconnect(sqlite3_vtab*);
+
+  static int BestIndex(sqlite3_vtab*, sqlite3_index_info*);
+
+  static int Open(sqlite3_vtab*, sqlite3_vtab_cursor**);
+  static int Close(sqlite3_vtab_cursor*);
+
+  static int Filter(sqlite3_vtab_cursor*,
+                    int,
+                    const char*,
+                    int,
+                    sqlite3_value**);
+  static int Next(sqlite3_vtab_cursor*);
+  static int Eof(sqlite3_vtab_cursor*);
+  static int Column(sqlite3_vtab_cursor*, sqlite3_context*, int);
+  static int Rowid(sqlite3_vtab_cursor*, sqlite_int64*);
+};
+
+}  // namespace perfetto::trace_processor
+
+#endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_OPERATORS_SLICE_MIPMAP_OPERATOR_H_
diff --git a/src/trace_processor/perfetto_sql/intrinsics/table_functions/ancestor.cc b/src/trace_processor/perfetto_sql/intrinsics/table_functions/ancestor.cc
index f102b1f..ab9ea14 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/table_functions/ancestor.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/table_functions/ancestor.cc
@@ -142,8 +142,9 @@
       // Find the all slice ids that have the stack id and find all the
       // ancestors of the slice ids.
       const auto& slice_table = storage_->slice_table();
-      auto it =
-          slice_table.FilterToIterator({slice_table.stack_id().eq(start_id)});
+      Query q;
+      q.constraints = {slice_table.stack_id().eq(start_id)};
+      auto it = slice_table.FilterToIterator(q);
       std::vector<tables::SliceTable::RowNumber> ancestors;
       for (; it; ++it) {
         RETURN_IF_ERROR(GetAncestors(slice_table, it.id(), ancestors));
diff --git a/src/trace_processor/perfetto_sql/intrinsics/table_functions/connected_flow.cc b/src/trace_processor/perfetto_sql/intrinsics/table_functions/connected_flow.cc
index 1e4f10e..4089036 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/table_functions/connected_flow.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/table_functions/connected_flow.cc
@@ -159,7 +159,9 @@
     const TypedColumn<SliceId>& start_col =
         flow_direction == FlowDirection::OUTGOING ? flow.slice_out()
                                                   : flow.slice_in();
-    auto it = flow.FilterToIterator({start_col.eq(slice_id.value)});
+    Query q;
+    q.constraints = {start_col.eq(slice_id.value)};
+    auto it = flow.FilterToIterator(q);
     for (; it; ++it) {
       flow_rows_.push_back(it.row_number());
 
diff --git a/src/trace_processor/perfetto_sql/intrinsics/table_functions/descendant.cc b/src/trace_processor/perfetto_sql/intrinsics/table_functions/descendant.cc
index 8f3ec43..d1b965f 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/table_functions/descendant.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/table_functions/descendant.cc
@@ -77,21 +77,23 @@
   // track are always perfectly stacked).
   // For unfinshed slices (i.e. -1 dur), we need to consider until the end of
   // the trace so we cannot add any similar constraint.
-  std::vector<Constraint> cs;
+  Query q;
   if (start_ref->dur() >= 0) {
-    cs.emplace_back(slices.ts().le(start_ref->ts() + start_ref->dur()));
+    q.constraints.emplace_back(
+        slices.ts().le(start_ref->ts() + start_ref->dur()));
   }
 
   // All nested descendents must be on the same track, with a ts greater than
   // |start_ref.ts| and whose depth is larger than |start_ref|'s.
-  cs.emplace_back(slices.ts().ge(start_ref->ts()));
-  cs.emplace_back(slices.track_id().eq(start_ref->track_id().value));
-  cs.emplace_back(slices.depth().gt(start_ref->depth()));
+  q.constraints.emplace_back(slices.ts().ge(start_ref->ts()));
+  q.constraints.emplace_back(slices.track_id().eq(start_ref->track_id().value));
+  q.constraints.emplace_back(slices.depth().gt(start_ref->depth()));
 
   // It's important we insert directly into |row_numbers_accumulator| and not
   // overwrite it because we expect the existing elements in
   // |row_numbers_accumulator| to be preserved.
-  for (auto it = slices.FilterToIterator(cs); it; ++it) {
+
+  for (auto it = slices.FilterToIterator(q); it; ++it) {
     row_numbers_accumulator.emplace_back(it.row_number());
   }
   return base::OkStatus();
@@ -136,7 +138,7 @@
     }
     case Type::kSliceByStack: {
       auto sbs_cs = {slices.stack_id().eq(start_id)};
-      for (auto it = slices.FilterToIterator(sbs_cs); it; ++it) {
+      for (auto it = slices.FilterToIterator(Query{sbs_cs, {}}); it; ++it) {
         RETURN_IF_ERROR(GetDescendants(slices, it.id(), descendants));
       }
       return ExtendWithStartId<tables::DescendantSliceByStackTable>(
diff --git a/src/trace_processor/perfetto_sql/intrinsics/table_functions/experimental_flat_slice_unittest.cc b/src/trace_processor/perfetto_sql/intrinsics/table_functions/experimental_flat_slice_unittest.cc
index c22362d..3a107d2 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/table_functions/experimental_flat_slice_unittest.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/table_functions/experimental_flat_slice_unittest.cc
@@ -100,8 +100,9 @@
   inserter.Populate(table);
 
   auto out = ExperimentalFlatSlice::ComputeFlatSliceTable(table, &pool, 0, 400);
-  auto it = out->ApplyAndIterateRows(out->QueryToRowMap(
-      {}, {out->track_id().ascending(), out->ts().ascending()}));
+  Query q;
+  q.orders = {out->track_id().ascending(), out->ts().ascending()};
+  auto it = out->ApplyAndIterateRows(out->QueryToRowMap(q));
 
   TableAsserter asserter(std::move(it));
 
@@ -183,8 +184,9 @@
 
   auto out =
       ExperimentalFlatSlice::ComputeFlatSliceTable(table, &pool, start, end);
-  auto it = out->ApplyAndIterateRows(out->QueryToRowMap(
-      {}, {out->track_id().ascending(), out->ts().ascending()}));
+  Query q;
+  q.orders = {out->track_id().ascending(), out->ts().ascending()};
+  auto it = out->ApplyAndIterateRows(out->QueryToRowMap(q));
 
   TableAsserter asserter(std::move(it));
 
diff --git a/src/trace_processor/perfetto_sql/intrinsics/table_functions/flamegraph_construction_algorithms.cc b/src/trace_processor/perfetto_sql/intrinsics/table_functions/flamegraph_construction_algorithms.cc
index 56c3bf8..4ad0b9a 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/table_functions/flamegraph_construction_algorithms.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/table_functions/flamegraph_construction_algorithms.cc
@@ -330,8 +330,10 @@
       storage->heap_profile_allocation_table();
   // PASS OVER ALLOCATIONS:
   // Aggregate allocations into the newly built tree.
-  auto it = allocation_tbl.FilterToIterator(
-      {allocation_tbl.ts().le(timestamp), allocation_tbl.upid().eq(upid)});
+  Query q;
+  q.constraints = {allocation_tbl.ts().le(timestamp),
+                   allocation_tbl.upid().eq(upid)};
+  auto it = allocation_tbl.FilterToIterator(q);
   if (!it) {
     return nullptr;
   }
@@ -367,7 +369,7 @@
   std::unordered_set<UniqueTid> utids;
   {
     auto it = storage->thread_table().FilterToIterator(
-        {storage->thread_table().upid().is_not_null()});
+        Query{{storage->thread_table().upid().is_not_null()}, {}});
     for (; it; ++it) {
       if (upids.count(*it.upid())) {
         utids.emplace(it.id().value);
@@ -391,7 +393,7 @@
   }
   std::vector<uint32_t> cs_rows;
   {
-    auto it = storage->perf_sample_table().FilterToIterator(cs);
+    auto it = storage->perf_sample_table().FilterToIterator(Query{cs, {}});
     for (; it; ++it) {
       if (utids.find(it.utid()) != utids.end()) {
         cs_rows.push_back(it.row_number().row_number());
@@ -404,10 +406,10 @@
   }
 
   // The logic underneath is selecting a default timestamp to be used by all
-  // frames which do not have a timestamp. The timestamp is taken from the query
-  // value and it's not meaningful for the row. It prevents however the rows
-  // with no timestamp from being filtered out by Sqlite, after we create the
-  // table ExperimentalFlamegraphTable in this class.
+  // frames which do not have a timestamp. The timestamp is taken from the
+  // query value and it's not meaningful for the row. It prevents however the
+  // rows with no timestamp from being filtered out by Sqlite, after we create
+  // the table ExperimentalFlamegraphTable in this class.
   int64_t default_timestamp = 0;
   if (!time_constraints.empty()) {
     auto& tc = time_constraints[0];
diff --git a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
index 4c492d1..349e2f6 100644
--- a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
@@ -36,6 +36,7 @@
     "stack_trace",
     "time",
     "v8",
+    "viz/summary",
     "wattson",
   ]
   generated_header = "stdlib.h"
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/frames/timeline.sql b/src/trace_processor/perfetto_sql/stdlib/android/frames/timeline.sql
index 3d29281..3a036e3 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/frames/timeline.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/android/frames/timeline.sql
@@ -28,15 +28,18 @@
     -- Parsed frame id.
     frame_id INT,
     -- Utid.
-    utid INT
+    utid INT,
+    -- Upid.
+    upid INT
 ) AS
 WITH all_found AS (
     SELECT
         id,
         cast_int!(STR_SPLIT(name, ' ', 1)) AS frame_id,
-        utid
+        utid,
+        upid
     FROM thread_slice
-    WHERE name GLOB $glob_str
+    WHERE name GLOB $glob_str AND depth = 0
 )
 SELECT *
 FROM all_found
@@ -50,12 +53,17 @@
     -- Frame id
     frame_id INT,
     -- Utid of the UI thread
-    ui_thread_utid INT
+    ui_thread_utid INT,
+    -- Upid of application process
+    upid INT
 ) AS
 SELECT
     id,
     frame_id,
-    utid AS ui_thread_utid
+    utid AS ui_thread_utid,
+    upid
+-- Some OEMs have customized `doFrame` to add more information, but we've only
+-- observed it added after the frame ID (b/303823815).
 FROM _get_frame_table_with_id('Choreographer#doFrame*');
 
 -- All of the `DrawFrame` slices with their frame id and render thread.
@@ -68,12 +76,15 @@
     -- Frame id
     frame_id INT,
     -- Utid of the render thread
-    render_thread_utid INT
+    render_thread_utid INT,
+    -- Upid of application process
+    upid INT
 ) AS
 SELECT
     id,
     frame_id,
-    utid AS render_thread_utid
+    utid AS render_thread_utid,
+    upid
 FROM _get_frame_table_with_id('DrawFrame*');
 
 -- `actual_frame_timeline_slice` returns the same slice on different tracks.
@@ -105,10 +116,11 @@
     frame_id INT,
     -- Timestamp of the frame. Start of the frame as defined by the start of
     -- "Choreographer#doFrame" slice and the same as the start of the frame in
-    -- `actual_frame_timeline_slice .
+    -- `actual_frame_timeline_slice if present.
     ts INT,
     -- Duration of the frame, as defined by the duration of the corresponding
-    -- `actual_frame_timeline_slice` duration.
+    -- `actual_frame_timeline_slice` or, if not present the time between the
+    -- `ts` and the end of the final `DrawFrame`.
     dur INT,
     -- `slice.id` of "Choreographer#doFrame" slice.
     do_frame_id INT,
@@ -123,11 +135,22 @@
     -- `utid` of the UI thread.
     ui_thread_utid INT
 ) AS
-WITH frames_sdk_after_28 AS (
+WITH fallback AS MATERIALIZED (
+    SELECT
+        frame_id,
+        do_frame_slice.ts AS ts,
+        MAX(draw_frame_slice.ts + draw_frame_slice.dur) - do_frame_slice.ts AS dur
+    FROM android_frames_choreographer_do_frame do_frame
+    JOIN android_frames_draw_frame draw_frame USING (frame_id, upid)
+    JOIN slice do_frame_slice ON (do_frame.id = do_frame_slice.id)
+    JOIN slice draw_frame_slice ON (draw_frame.id = draw_frame_slice.id)
+GROUP BY 1
+),
+frames_sdk_after_28 AS (
 SELECT
     frame_id,
-    ts,
-    dur,
+    COALESCE(act.ts, fallback.ts) AS ts,
+    COALESCE(act.dur, fallback.dur) AS dur,
     do_frame.id AS do_frame_id,
     draw_frame.id AS draw_frame_id,
     draw_frame.render_thread_utid,
@@ -136,9 +159,10 @@
     act.id AS actual_frame_timeline_id,
     exp.id AS expected_frame_timeline_id
 FROM android_frames_choreographer_do_frame do_frame
-JOIN android_frames_draw_frame draw_frame USING (frame_id)
-JOIN _distinct_from_actual_timeline_slice act USING (frame_id)
-JOIN _distinct_from_expected_timeline_slice exp USING (frame_id)
+JOIN android_frames_draw_frame draw_frame USING (frame_id, upid)
+JOIN fallback USING (frame_id)
+LEFT JOIN _distinct_from_actual_timeline_slice act USING (frame_id)
+LEFT JOIN _distinct_from_expected_timeline_slice exp USING (frame_id)
 ORDER BY frame_id
 ),
 all_frames AS (
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/process_metadata.sql b/src/trace_processor/perfetto_sql/stdlib/android/process_metadata.sql
index 86c099b..a50b033 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/process_metadata.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/android/process_metadata.sql
@@ -70,8 +70,8 @@
     )
     OR
     (
-      -- isolated processes can only be matched based on the name prefix
+      -- isolated processes can only be matched based on the name
       process.android_appid >= 90000 AND process.android_appid < 100000
-      AND STR_SPLIT(process.name, ':', 0) GLOB plist.package_name || '*'
+      AND STR_SPLIT(process.name, ':', 0) = plist.package_name
     )
   );
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/startup/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/android/startup/BUILD.gn
index 8206b4a..c495f08 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/startup/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/android/startup/BUILD.gn
@@ -21,5 +21,6 @@
     "startups_maxsdk28.sql",
     "startups_minsdk29.sql",
     "startups_minsdk33.sql",
+    "time_to_display.sql",
   ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql b/src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql
index 5188b63..3faf091 100644
--- a/src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/android/startup/startups_maxsdk28.sql
@@ -23,7 +23,8 @@
   SELECT
     le.ts,
     le.ts_end AS ts_end,
-    package_name AS package
+    package_name AS package,
+    NULL AS startup_type
   FROM _startup_events le
 ),
 -- Hot starts don’t have a launching slice so we use activityResume as a
@@ -36,13 +37,18 @@
     sl.ts,
     rs.ts + rs.dur AS ts_end,
     -- We use the process name as the package as we have no better option.
-    process_name AS package
+    process_name AS package,
+    "hot" AS startup_type
   FROM thread_slice sl
   JOIN android_first_frame_after(sl.ts) rs
   WHERE name = 'activityResume'
   -- Remove any launches here where the activityResume slices happens during
   -- a warm/cold startup.
-  AND sl.ts NOT IN (SELECT ts FROM warm_and_cold)
+  AND NOT EXISTS (
+    SELECT 1
+    FROM warm_and_cold wac
+    WHERE sl.ts BETWEEN wac.ts AND wac.ts_end
+    LIMIT 1)
 ),
 cold_warm_hot AS (
   SELECT * FROM warm_and_cold
@@ -57,7 +63,7 @@
   ts_end,
   ts_end - ts AS dur,
   package,
-  NULL AS startup_type
+  startup_type
 FROM cold_warm_hot;
 
 
diff --git a/src/trace_processor/perfetto_sql/stdlib/android/startup/time_to_display.sql b/src/trace_processor/perfetto_sql/stdlib/android/startup/time_to_display.sql
new file mode 100644
index 0000000..7264bb7
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/android/startup/time_to_display.sql
@@ -0,0 +1,164 @@
+--
+-- 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.startup.startups;
+INCLUDE PERFETTO MODULE android.frames.timeline;
+INCLUDE PERFETTO MODULE slices.with_context;
+
+CREATE PERFETTO VIEW _startups_with_upid AS
+WITH joined_with_processes AS (
+  SELECT
+    s.*,
+    p.upid
+  FROM android_startups s
+  LEFT JOIN android_startup_processes p USING (startup_id)
+),
+fallback AS (
+  SELECT
+    s.*,
+    upid FROM android_startups s
+  JOIN process p ON (p.name glob s.package)
+)
+  SELECT
+    j.startup_id,
+    j.ts,
+    j.ts_end,
+    j.dur,
+    j.package,
+    j.startup_type,
+    COALESCE(j.upid, f.upid) AS upid
+  FROM joined_with_processes j
+  LEFT JOIN fallback f ON (j.upid IS NULL AND j.startup_id = f.startup_id);
+
+-- Get Time To Initial Display of the startup calculated as time between the
+-- startup started and the first frame that was started by Choreographer on the
+-- UI thread of the startup finished drawing.
+-- TTID (https://developer.android.com/topic/performance/vitals/launch-time#time-initial)
+-- Googlers: see go/android-performance-metrics-glossary for details.
+CREATE PERFETTO TABLE _ttid AS
+WITH frames_with_upid AS (
+  SELECT
+  f.*,
+  upid
+  FROM android_frames f
+  JOIN thread t ON (f.ui_thread_utid = t.utid)
+),
+  -- First `DrawFrame` on Render Thread after the startup.
+first_frame_for_startup AS (
+  SELECT
+    startup_id,
+    frame_id,
+    s.ts AS startup_ts,
+    draw_frame_id,
+    s.upid
+  FROM _startups_with_upid s
+  JOIN frames_with_upid f ON (s.upid = f.upid AND s.ts <= f.ts)
+  GROUP BY startup_id
+  ORDER BY startup_id, f.ts)
+SELECT
+  startup_id,
+  frame_id,
+  draw_frame_id,
+  ts + dur - startup_ts AS ttid,
+  upid
+FROM first_frame_for_startup
+JOIN slice ON (slice.id = draw_frame_id);
+
+-- Get Time To Full Display of the startup calculated as time between the
+-- startup started and the first frame that was started by Choreographer after
+-- or containing the `reportFullyDrawn()` slice on the UI thread of the startup
+-- finished drawing.
+-- TTFD (https://developer.android.com/topic/performance/vitals/launch-time#retrieve-TTFD)
+-- Googlers: see go/android-performance-metrics-glossary for details.
+CREATE PERFETTO TABLE _ttfd AS
+-- First `reportFullyDrawn` slice for each startup.
+WITH first_report_fully_drawn_for_startup AS (
+  SELECT
+  startup_id,
+  s.ts AS startup_ts,
+  t.ts AS report_fully_drawn_ts,
+  t.utid,
+  s.upid
+FROM _startups_with_upid s
+JOIN thread_slice t ON (s.upid = t.upid AND t.ts >= s.ts)
+WHERE name GLOB "reportFullyDrawn*" AND t.is_main_thread = 1
+GROUP BY startup_id
+ORDER BY startup_id, t.ts),
+-- After the first `reportFullyDrawn` find the first `Choreographer#DoFrame` on
+-- the UI thread and it's first `DrawFrame` on Render Thread.
+first_frame_after_report_for_startup AS (
+  SELECT
+    startup_id,
+    frame_id,
+    startup_ts,
+    draw_frame_id,
+    s.upid
+  FROM first_report_fully_drawn_for_startup s
+  JOIN android_frames f ON (
+    s.utid = f.ui_thread_utid
+    -- We are looking for the first DrawFrame that was started by the first
+    -- "Choreographer#DoFrame" on UI thread after or containing
+    -- reportFullyDrawn. In Android UIs, it's common to have UI code happen
+    -- either before a frame, or during it, and generally non-trivial amounts
+    -- of "update UI model" code doesn't try to differentiate these. We account
+    -- for both of these by looking for the first UI slice that ends after the
+    -- "reportFullyDrawnSlice" begins.
+    AND report_fully_drawn_ts < (f.ts + f.dur))
+  GROUP BY startup_id
+  ORDER BY startup_id, f.ts
+)
+-- Get TTFD as the difference between the start of the startup and the end of
+-- `DrawFrame` slice we previously found.
+SELECT
+  startup_id,
+  frame_id,
+  draw_frame_id,
+  ts + dur - startup_ts AS ttfd,
+  upid
+FROM first_frame_after_report_for_startup
+JOIN slice ON (slice.id = draw_frame_id);
+
+-- Startup metric defintions, which focus on the observable time range:
+-- TTID - Time To Initial Display
+-- * https://developer.android.com/topic/performance/vitals/launch-time#time-initial
+-- * end of first RenderThread.DrawFrame - bindApplication
+-- TTFD - Time To Full Display
+-- * https://developer.android.com/topic/performance/vitals/launch-time#retrieve-TTFD
+-- * end of next RT.DrawFrame, after reportFullyDrawn called - bindApplication
+-- Googlers: see go/android-performance-metrics-glossary for details.
+CREATE PERFETTO TABLE android_startup_time_to_display(
+  -- Startup id.
+  startup_id INT,
+  -- Time to initial display (TTID)
+  time_to_inital_display INT,
+  -- Time to full display (TTFD)
+  time_to_full_display INT,
+  -- `android_frames.frame_id` of frame for initial display
+  ttid_frame_id INT,
+  -- `android_frames.frame_id` of frame for full display
+  ttfd_frame_id INT,
+  -- `process.upid` of the startup
+  upid INT
+) AS
+SELECT
+  startup_id,
+  ttid AS time_to_inital_display,
+  ttfd AS time_to_full_display,
+  _ttid.frame_id AS ttid_frame_id,
+  _ttfd.frame_id AS ttfd_frame_id,
+  _ttid.upid
+FROM android_startups
+LEFT JOIN _ttid USING (startup_id)
+LEFT JOIN _ttfd USING (startup_id);
diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_offsets.sql b/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_offsets.sql
index 8df0937..f1bfd37 100644
--- a/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_offsets.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_offsets.sql
@@ -29,189 +29,104 @@
 -- various stages of input processing, and are unified by a single
 -- scroll_update_id value, recorded as scroll_deltas.trace_id in each event.
 
+INCLUDE PERFETTO MODULE chrome.chrome_scrolls;
 INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_jank_v3;
 
--- Non-coalesced scroll update events and their timestamps.
-CREATE PERFETTO VIEW _non_coalesced_scrolls AS
-SELECT
-  scroll_update_id,
-  ts
-FROM chrome_gesture_scroll_updates
-WHERE is_coalesced = False;
-
 -- All (coalesced and non-coalesced) vertical scrolling deltas and their
 -- associated scroll ids. Delta values are recorded after being scaled to the
 -- device's screen size in the TranslateAndScaleWebInputEvent trace event. In
 -- this trace event, the deltas recorded represent the true (read "original")
 -- values that the Browser receives from Android, and the only processing is
 -- scaling and translation.
-CREATE PERFETTO TABLE _scroll_deltas AS
+CREATE PERFETTO TABLE _translate_and_scale_scroll_deltas AS
 SELECT
   EXTRACT_ARG(arg_set_id, 'scroll_deltas.trace_id') AS scroll_update_id,
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.original_delta_y') AS delta_y,
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.original_delta_y') IS NOT NULL AS is_coalesced
+  EXTRACT_ARG(arg_set_id, 'scroll_deltas.original_delta_y') AS delta_y
 FROM slice
-WHERE name = "TranslateAndScaleWebInputEvent";
+WHERE slice.name = 'TranslateAndScaleWebInputEvent';
 
--- Associate the raw (original) deltas (_scroll_deltas) with the
--- corresponding non-coalesced scroll updates
--- (_non_coalesced_scroll_updates) to get the timestamp of the event
--- those deltas. This allows for ordering delta recordings to track them over
--- time.
-CREATE PERFETTO VIEW _non_coalesced_deltas AS
+-- Associate the gesture scroll update OS timestamp with the delta.
+CREATE PERFETTO TABLE _scroll_deltas_with_timestamp AS
 SELECT
-  scroll_update_id,
-  ts,
-  delta_y
-FROM _non_coalesced_scrolls
-INNER JOIN _scroll_deltas
-  USING (scroll_update_id);
+  slice.ts AS input_ts,
+  data.scroll_update_id,
+  data.delta_y
+FROM _translate_and_scale_scroll_deltas data
+  JOIN slice ON slice.name = 'EventLatency'
+    AND data.scroll_update_id = EXTRACT_ARG(arg_set_id,
+        'event_latency.event_latency_id');
 
--- Selecting information scroll update events that have been coalesced,
--- including timestamp and the specific event (scroll update id) it was
--- coalesced into. Recordings of deltas will need to be associated with the
--- timestamp of the scroll update they were coalesced into.
-CREATE PERFETTO TABLE _scroll_update_coalesce_info AS
+-- Associate the scroll update/delta with the correct scroll.
+CREATE PERFETTO TABLE _scroll_deltas_with_scroll_id AS
 SELECT
-  ts,
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.coalesced_to_trace_id') AS coalesced_to_scroll_update_id,
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.trace_id') AS scroll_update_id
-FROM slice
-WHERE name = "WebCoalescedInputEvent::CoalesceWith" AND
-  coalesced_to_scroll_update_id IS NOT NULL;
+  scrolls.id AS scroll_id,
+  deltas.input_ts,
+  deltas.scroll_update_id,
+  deltas.delta_y
+FROM _scroll_deltas_with_timestamp deltas
+  LEFT JOIN chrome_scrolls scrolls
+    ON deltas.input_ts >= scrolls.ts
+      AND deltas.input_ts <= scrolls.ts + scrolls.dur;
 
--- Associate the raw (original) deltas (_scroll_deltas) with the
--- corresponding coalesced scroll updates (_scroll_update_coalesce_info)
--- to get the timestamp of the event those deltas were coalesced into. This
--- allows us to get the scaled coordinates for all of the input events
--- (original input coordinates can't be used due to scaling).
-CREATE PERFETTO VIEW _coalesced_deltas AS
+-- Associate the presentation timestamp/deltas with the user deltas.
+CREATE PERFETTO TABLE _scroll_deltas_with_delays AS
 SELECT
-  _scroll_update_coalesce_info.coalesced_to_scroll_update_id AS scroll_update_id,
-  ts,
-  _scroll_deltas.delta_y AS delta_y,
-  TRUE AS is_coalesced
-FROM _scroll_update_coalesce_info
-LEFT JOIN _scroll_deltas
-  USING (scroll_update_id);
-
--- All of the presented frame scroll update ids.
-CREATE PERFETTO VIEW chrome_deltas_presented_frame_scroll_update_ids(
-  -- A scroll update id that was included in the presented frame.
-  -- There may be zero, one, or more.
-  scroll_update_id INT,
-  -- Slice id
-  id INT
-) AS
-SELECT
-  args.int_value AS scroll_update_id,
-  slice.id
-FROM args
-LEFT JOIN slice
-  USING (arg_set_id)
-WHERE slice.name = 'PresentedFrameInformation'
-AND args.flat_key GLOB 'scroll_deltas.trace_ids_in_gpu_frame*';;
-
--- When every GestureScrollUpdate event is processed, the offset set by the
--- compositor is recorded. This offset is scaled to the device screen size, and
--- can be used to calculate deltas.
-CREATE PERFETTO VIEW _presented_frame_offsets AS
-SELECT
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.trace_id') AS scroll_update_id,
-  EXTRACT_ARG(arg_set_id, 'scroll_deltas.visual_offset_y') AS visual_offset_y
-FROM slice
-WHERE name = 'InputHandlerProxy::HandleGestureScrollUpdate_Result';
+  deltas.scroll_id,
+  delay.total_delta,
+  delay.scroll_update_id,
+  delay.presentation_timestamp AS presentation_timestamp,
+  deltas.input_ts,
+  deltas.delta_y
+FROM _scroll_deltas_with_scroll_id AS deltas
+  LEFT JOIN chrome_frame_info_with_delay AS delay USING(scroll_update_id);
 
 -- The raw coordinates and pixel offsets for all input events which were part of
--- a scroll. This includes input events that were converted to scroll events
--- which were presented (_non_coalesced_scrolls) and scroll events which
--- were coalesced (_coalesced_deltas).
+-- a scroll.
 CREATE PERFETTO TABLE chrome_scroll_input_offsets(
   -- Trace id associated with the scroll.
+  scroll_id INT,
+  -- Trace id associated with the scroll.
   scroll_update_id INT,
   -- Timestamp the of the scroll input event.
   ts INT,
-  -- The delta in raw coordinates between this scroll update event and the previous.
+  -- The delta in raw coordinates between this scroll update event and the
+  -- previous.
   delta_y INT,
-  -- The pixel offset of this scroll update event compared to the previous one.
-  offset_y INT
+  -- The pixel offset of this scroll update event compared to the initial one.
+  relative_offset_y INT
 ) AS
--- First collect all coalesced and non-coalesced deltas so that the offsets
--- can be calculated from them in order of timestamp.
-WITH all_deltas AS (
-  SELECT
-    scroll_update_id,
-    ts,
-    delta_y
-  FROM _non_coalesced_deltas
-  WHERE delta_y IS NOT NULL
-  UNION
-  SELECT
-    scroll_update_id,
-    ts,
-    delta_y
-  FROM _coalesced_deltas
-  WHERE delta_y IS NOT NULL
-  ORDER BY scroll_update_id, ts)
 SELECT
+  scroll_id,
   scroll_update_id,
-  ts,
+  input_ts AS ts,
   delta_y,
-  SUM(IFNULL(delta_y, 0)) OVER (
-    ORDER BY scroll_update_id, ts
-    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS offset_y
-FROM all_deltas;
-
--- Calculate the total visual offset for all presented frames (non-coalesced
--- scroll updates) that have raw deltas recorded. These visual offsets
--- correspond with the inverse of the deltas for the presented frame.
-CREATE PERFETTO VIEW _preprocessed_presented_frame_offsets AS
-SELECT
-  chrome_full_frame_view.scroll_update_id,
-  chrome_full_frame_view.presentation_timestamp AS ts,
-  chrome_deltas_presented_frame_scroll_update_ids.id,
-  _presented_frame_offsets.visual_offset_y -
-    LAG(_presented_frame_offsets.visual_offset_y)
-    OVER (ORDER BY chrome_full_frame_view.presentation_timestamp)
-      AS presented_frame_visual_offset_y
-FROM chrome_full_frame_view
-LEFT JOIN _scroll_deltas
-  USING (scroll_update_id)
-LEFT JOIN chrome_deltas_presented_frame_scroll_update_ids
-  USING (scroll_update_id)
-LEFT JOIN _presented_frame_offsets
-  USING (scroll_update_id)
-WHERE _scroll_deltas.delta_y IS NOT NULL;
+  SUM(IFNULL(delta_y, 0)) OVER ( PARTITION BY scroll_id
+    ORDER BY scroll_update_id, input_ts
+    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS relative_offset_y
+FROM _scroll_deltas_with_delays;
 
 -- The scrolling offsets for the actual (applied) scroll events. These are not
 -- necessarily inclusive of all user scroll events, rather those scroll events
 -- that are actually processed.
 CREATE PERFETTO TABLE chrome_presented_scroll_offsets(
-  -- Trace Id associated with the scroll.
+  -- Trace id associated with the scroll.
+  scroll_id INT,
+  -- Trace id associated with the scroll update event.
   scroll_update_id INT,
   -- Presentation timestamp.
   ts INT,
-  -- The delta in coordinates as processed by Chrome between this scroll update
-  -- event and the previous.
+  -- The delta in raw coordinates between this scroll update event and the
+  -- previous.
   delta_y INT,
-  -- The pixel offset of this scroll update (the presented frame) compared to
-  -- the previous one.
-  offset_y INT
+  -- The pixel offset of this scroll update event compared to the initial one.
+  relative_offset_y INT
 ) AS
-WITH all_deltas AS (
-  SELECT
-    scroll_update_id,
-    id,
-    MAX(ts) AS ts,
-    SUM(presented_frame_visual_offset_y) * -1 AS delta_y
-  FROM _preprocessed_presented_frame_offsets
-  GROUP BY id
-  ORDER BY ts)
 SELECT
+  scroll_id,
   scroll_update_id,
-  ts,
-  delta_y,
-  SUM(IFNULL(delta_y, 0)) OVER (
-    ORDER BY scroll_update_id, ts
-    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS offset_y
-FROM all_deltas;
+  presentation_timestamp AS ts,
+  total_delta AS delta_y,
+  SUM(IFNULL(total_delta, 0)) OVER ( PARTITION BY scroll_id
+    ORDER BY scroll_update_id, presentation_timestamp
+    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS relative_offset_y
+FROM _scroll_deltas_with_delays;
\ No newline at end of file
diff --git a/src/trace_processor/perfetto_sql/stdlib/memory/heap_graph_dominator_tree.sql b/src/trace_processor/perfetto_sql/stdlib/memory/heap_graph_dominator_tree.sql
index 28edf7f..f0cfae1 100644
--- a/src/trace_processor/perfetto_sql/stdlib/memory/heap_graph_dominator_tree.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/memory/heap_graph_dominator_tree.sql
@@ -18,20 +18,21 @@
 -- Excluding following types from the graph as they share objects' ownership
 -- with their real (more interesting) owners and will mask their idom to be the
 -- "super root".
-CREATE PERFETTO TABLE _excluded_type_ids AS
-WITH RECURSIVE class_visitor(type_id) AS (
-  SELECT id AS type_id
-  FROM heap_graph_class
-  WHERE name IN (
-    'java.lang.ref.PhantomReference',
-    'java.lang.ref.FinalizerReference'
-  )
-  UNION ALL
-  SELECT child.id AS type_id
-  FROM heap_graph_class child
-  JOIN class_visitor parent ON parent.type_id = child.superclass_id
-)
-SELECT * FROM class_visitor;
+CREATE PERFETTO TABLE _ref_type_ids AS
+SELECT id AS type_id FROM heap_graph_class
+WHERE kind IN (
+  'KIND_FINALIZER_REFERENCE',
+  'KIND_PHANTOM_REFERENCE',
+  'KIND_SOFT_REFERENCE',
+  'KIND_WEAK_REFERENCE');
+
+CREATE PERFETTO TABLE _excluded_refs AS
+SELECT ref.id
+  FROM _ref_type_ids
+  JOIN heap_graph_object robj USING (type_id)
+  JOIN heap_graph_reference ref USING (reference_set_id)
+WHERE ref.field_name = 'java.lang.ref.Reference.referent'
+ORDER BY ref.id;
 
 -- The assigned id of the "super root".
 -- Since a Java heap graph is a "forest" structure, we need to add a imaginary
@@ -48,7 +49,8 @@
   ref.owned_id AS dest_node_id
 FROM heap_graph_reference ref
 JOIN heap_graph_object source_node ON ref.owner_id = source_node.id
-WHERE source_node.reachable AND source_node.type_id NOT IN _excluded_type_ids
+WHERE source_node.reachable
+  AND ref.id NOT IN _excluded_refs
   AND ref.owned_id IS NOT NULL
 UNION ALL
 SELECT
diff --git a/src/trace_processor/perfetto_sql/stdlib/viz/summary/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/viz/summary/BUILD.gn
new file mode 100644
index 0000000..3f664bd
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/viz/summary/BUILD.gn
@@ -0,0 +1,24 @@
+# Copyright (C) 2023 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("summary") {
+  sources = [
+    "processes.sql",
+    "slices.sql",
+    "threads.sql",
+    "tracks.sql",
+  ]
+}
diff --git a/src/trace_processor/perfetto_sql/stdlib/viz/summary/processes.sql b/src/trace_processor/perfetto_sql/stdlib/viz/summary/processes.sql
new file mode 100644
index 0000000..18aa202
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/viz/summary/processes.sql
@@ -0,0 +1,93 @@
+--
+-- 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 viz.summary.slices;
+INCLUDE PERFETTO MODULE viz.summary.threads;
+
+CREATE PERFETTO TABLE _process_track_summary AS
+SELECT upid, SUM(cnt) AS slice_count
+FROM process_track
+JOIN _slice_track_summary USING (id)
+GROUP BY upid;
+
+CREATE PERFETTO TABLE _heap_profile_allocation_summary AS
+SELECT upid, COUNT() AS allocation_count
+FROM heap_profile_allocation
+GROUP BY upid;
+
+CREATE PERFETTO TABLE _heap_profile_graph_summary AS
+SELECT upid, COUNT() AS graph_object_count
+FROM heap_graph_object;
+
+CREATE PERFETTO TABLE _thread_process_grouped_summary AS
+SELECT
+  upid,
+  MAX(max_running_dur) AS max_running_dur,
+  SUM(sum_running_dur) AS sum_running_dur,
+  SUM(running_count) AS running_count,
+  SUM(slice_count) AS slice_count,
+  SUM(perf_sample_count) AS perf_sample_count
+FROM _thread_available_info_summary
+JOIN thread USING (utid)
+WHERE upid IS NOT NULL
+GROUP BY upid;
+
+CREATE PERFETTO TABLE _process_available_info_summary AS
+WITH r AS (
+  SELECT
+    upid,
+    t_summary.upid as summary_upid,
+    t_summary.max_running_dur AS max_running_dur,
+    t_summary.sum_running_dur,
+    t_summary.running_count,
+    t_summary.slice_count AS thread_slice_count,
+    t_summary.perf_sample_count AS perf_sample_count,
+    (
+      SELECT slice_count
+      FROM _process_track_summary
+      WHERE upid = p.upid
+    ) AS process_slice_count,
+    (
+      SELECT allocation_count
+      FROM _heap_profile_allocation_summary
+      WHERE upid = p.upid
+    ) AS allocation_count,
+    (
+      SELECT graph_object_count
+      FROM _heap_profile_graph_summary
+      WHERE upid = p.upid
+    ) AS graph_object_count
+  FROM process p
+  LEFT JOIN _thread_process_grouped_summary t_summary USING (upid)
+)
+SELECT
+  upid,
+  IFNULL(max_running_dur, 0) AS max_running_dur,
+  IFNULL(sum_running_dur, 0) AS sum_running_dur,
+  IFNULL(running_count, 0) AS running_count,
+  IFNULL(thread_slice_count, 0) AS thread_slice_count,
+  IFNULL(perf_sample_count, 0) AS perf_sample_count,
+  IFNULL(process_slice_count, 0) AS process_slice_count,
+  IFNULL(allocation_count, 0) AS allocation_count,
+  IFNULL(graph_object_count, 0) AS graph_object_count
+FROM r
+WHERE
+  NOT(
+    r.summary_upid IS NULL
+    AND process_slice_count IS NULL
+    AND allocation_count IS NULL
+    AND graph_object_count IS NULL
+  )
+  OR upid IN (SELECT upid FROM process_counter_track);
diff --git a/src/trace_processor/perfetto_sql/stdlib/viz/summary/slices.sql b/src/trace_processor/perfetto_sql/stdlib/viz/summary/slices.sql
new file mode 100644
index 0000000..c698859
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/viz/summary/slices.sql
@@ -0,0 +1,24 @@
+--
+-- 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.
+
+CREATE PERFETTO TABLE _slice_track_summary AS
+SELECT
+  track_id as id,
+  COUNT() AS cnt,
+  MIN(dur) AS min_dur,
+  MAX(dur) AS max_dur,
+  MAX(depth) AS max_depth
+FROM slice
+GROUP BY track_id;
diff --git a/src/trace_processor/perfetto_sql/stdlib/viz/summary/threads.sql b/src/trace_processor/perfetto_sql/stdlib/viz/summary/threads.sql
new file mode 100644
index 0000000..ed74acf
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/viz/summary/threads.sql
@@ -0,0 +1,77 @@
+--
+-- 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 viz.summary.slices;
+
+CREATE PERFETTO TABLE _sched_summary AS
+SELECT
+  utid,
+  MAX(dur) AS max_running_dur,
+  SUM(dur) AS sum_running_dur,
+  COUNT() AS running_count
+FROM sched
+WHERE utid != 0 AND dur != -1
+GROUP BY utid;
+
+CREATE PERFETTO TABLE _thread_track_summary AS
+SELECT utid, SUM(cnt) AS slice_count
+FROM thread_track
+JOIN _slice_track_summary USING (id)
+GROUP BY utid;
+
+CREATE PERFETTO TABLE _perf_sample_summary AS
+SELECT utid, count() AS perf_sample_cnt
+FROM perf_sample
+WHERE callsite_id IS NOT NULL
+GROUP BY utid;
+
+CREATE PERFETTO TABLE _thread_available_info_summary AS
+WITH raw AS (
+  SELECT
+    utid,
+    ss.max_running_dur,
+    ss.sum_running_dur,
+    ss.running_count,
+    (
+      SELECT slice_count
+      FROM _thread_track_summary
+      WHERE utid = t.utid
+    ) AS slice_count,
+    (
+      SELECT perf_sample_cnt
+      FROM _perf_sample_summary
+      WHERE utid = t.utid
+    ) AS perf_sample_count
+  FROM thread t
+  LEFT JOIN _sched_summary ss USING (utid)
+)
+SELECT
+  utid,
+  IFNULL(max_running_dur, 0) AS max_running_dur,
+  IFNULL(sum_running_dur, 0) AS sum_running_dur,
+  IFNULL(running_count, 0) AS running_count,
+  IFNULL(slice_count, 0) AS slice_count,
+  IFNULL(perf_sample_count, 0) AS perf_sample_count
+FROM raw r
+WHERE
+  NOT (
+    r.max_running_dur IS NULL
+    AND r.sum_running_dur IS NULL
+    AND r.running_count IS NULL
+    AND r.slice_count IS NULL
+    AND r.perf_sample_count IS NULL
+  )
+  OR utid IN (SELECT utid FROM cpu_profile_stack_sample)
+  OR utid IN (SELECT utid FROM thread_counter_track);
diff --git a/src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql b/src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql
new file mode 100644
index 0000000..7a1d5d0
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql
@@ -0,0 +1,36 @@
+--
+-- 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 viz.summary.slices;
+
+CREATE PERFETTO TABLE _process_track_summary_by_upid_and_name AS
+SELECT
+  upid,
+  name,
+  GROUP_CONCAT(id) AS track_ids,
+  COUNT() AS track_count
+FROM process_track
+JOIN _slice_track_summary USING (id)
+GROUP BY upid, name;
+
+CREATE PERFETTO TABLE _uid_track_track_summary_by_uid_and_name AS
+SELECT
+  uid,
+  name,
+  GROUP_CONCAT(id) AS track_ids,
+  COUNT() AS track_count
+FROM uid_track
+JOIN _slice_track_summary USING (id)
+GROUP BY uid, name;
diff --git a/src/trace_processor/sqlite/db_sqlite_table.cc b/src/trace_processor/sqlite/db_sqlite_table.cc
index eb61280..dc64f34 100644
--- a/src/trace_processor/sqlite/db_sqlite_table.cc
+++ b/src/trace_processor/sqlite/db_sqlite_table.cc
@@ -138,20 +138,22 @@
   return stmt;
 }
 
-base::StatusOr<SqlValue> SqliteValueToSqlValueChecked(sqlite3_value* value,
-                                                      const Constraint& cs) {
-  SqlValue v = sqlite::utils::SqliteValueToSqlValue(value);
+int SqliteValueToSqlValueChecked(SqlValue* sql_val,
+                                 sqlite3_value* value,
+                                 const Constraint& cs,
+                                 sqlite3_vtab* vtab) {
+  *sql_val = sqlite::utils::SqliteValueToSqlValue(value);
   if constexpr (regex::IsRegexSupported()) {
     if (cs.op == FilterOp::kRegex) {
       if (cs.value.type != SqlValue::kString) {
-        return base::ErrStatus("Value has to be a string");
+        return sqlite::utils::SetError(vtab, "Value has to be a string");
       }
       if (auto st = regex::Regex::Create(cs.value.AsString()); !st.ok()) {
-        return st.status();
+        return sqlite::utils::SetError(vtab, st.status().c_message());
       }
     }
   }
-  return v;
+  return SQLITE_OK;
 }
 
 int UpdateConstraintsAndOrderByFromIndex(DbSqliteModule::Cursor* c,
@@ -166,18 +168,18 @@
 
   // We reuse this vector to reduce memory allocations on nested subqueries.
   uint32_t c_offset = 0;
-  c->constraints.resize(cs_count);
-  for (auto& cs : c->constraints) {
+  c->query.constraints.resize(cs_count);
+  for (auto& cs : c->query.constraints) {
     PERFETTO_CHECK(splitter.Next());
     cs.col_idx = *base::CStringToUInt32(splitter.cur_token());
     PERFETTO_CHECK(splitter.Next());
     cs.op = static_cast<FilterOp>(*base::CStringToUInt32(splitter.cur_token()));
 
-    auto value_or = SqliteValueToSqlValueChecked(argv[c_offset++], cs);
-    if (!value_or.ok()) {
-      return sqlite::utils::SetError(c->pVtab, value_or.status().c_message());
+    if (int ret = SqliteValueToSqlValueChecked(&cs.value, argv[c_offset++], cs,
+                                               c->pVtab);
+        ret != SQLITE_OK) {
+      return ret;
     }
-    cs.value = *value_or;
   }
 
   PERFETTO_CHECK(splitter.Next());
@@ -187,8 +189,8 @@
   uint32_t ob_count = *base::CStringToUInt32(splitter.cur_token() + 1);
 
   // We reuse this vector to reduce memory allocations on nested subqueries.
-  c->orders.resize(ob_count);
-  for (auto& ob : c->orders) {
+  c->query.orders.resize(ob_count);
+  for (auto& ob : c->query.orders) {
     PERFETTO_CHECK(splitter.Next());
     ob.col_idx = *base::CStringToUInt32(splitter.cur_token());
     PERFETTO_CHECK(splitter.Next());
@@ -216,13 +218,13 @@
 
   // If we have more than one constraint, we can't cache the table using
   // this method.
-  if (cursor->constraints.size() != 1) {
+  if (cursor->query.constraints.size() != 1) {
     return;
   }
 
   // If the constraing is not an equality constraint, there's little
   // benefit to caching
-  const auto& c = cursor->constraints.front();
+  const auto& c = cursor->query.constraints.front();
   if (c.op != FilterOp::kEq) {
     return;
   }
@@ -242,7 +244,7 @@
                             DbSqliteModule::Cursor* cursor,
                             metatrace::Record* r) {
   r->AddArg("Table", table_name);
-  for (const Constraint& c : cursor->constraints) {
+  for (const Constraint& c : cursor->query.constraints) {
     SafeStringWriter writer;
     writer.AppendString(schema.columns[c.col_idx].name);
 
@@ -303,7 +305,7 @@
     r->AddArg("Constraint", writer.GetStringView());
   }
 
-  for (const auto& o : cursor->orders) {
+  for (const auto& o : cursor->query.orders) {
     SafeStringWriter writer;
     writer.AppendString(schema.columns[o.col_idx].name);
     if (o.desc)
@@ -571,12 +573,12 @@
   size_t offset = c->table_function_arguments.size();
   bool is_same_idx = idx_num == c->last_idx_num;
   if (PERFETTO_LIKELY(is_same_idx)) {
-    for (auto& cs : c->constraints) {
-      auto value_or = SqliteValueToSqlValueChecked(argv[offset++], cs);
-      if (!value_or.ok()) {
-        return sqlite::utils::SetError(c->pVtab, value_or.status().c_message());
+    for (auto& cs : c->query.constraints) {
+      if (int ret = SqliteValueToSqlValueChecked(&cs.value, argv[offset++], cs,
+                                                 c->pVtab);
+          ret != SQLITE_OK) {
+        return ret;
       }
-      cs.value = *value_or;
     }
   } else {
     if (int r = UpdateConstraintsAndOrderByFromIndex(c, idx_str, argv + offset);
@@ -623,7 +625,7 @@
 
   const auto* source_table =
       c->sorted_cache_table ? &*c->sorted_cache_table : c->upstream_table;
-  RowMap filter_map = source_table->QueryToRowMap(c->constraints, c->orders);
+  RowMap filter_map = source_table->QueryToRowMap(c->query);
   if (filter_map.IsRange() && filter_map.size() <= 1) {
     // Currently, our criteria where we have a special fast path is if it's
     // a single ranged row. We have this fast path for joins on id columns
diff --git a/src/trace_processor/sqlite/db_sqlite_table.h b/src/trace_processor/sqlite/db_sqlite_table.h
index 401c370..a94cbe6 100644
--- a/src/trace_processor/sqlite/db_sqlite_table.h
+++ b/src/trace_processor/sqlite/db_sqlite_table.h
@@ -109,8 +109,8 @@
     Mode mode = Mode::kSingleRow;
 
     int last_idx_num = -1;
-    std::vector<Constraint> constraints;
-    std::vector<Order> orders;
+    Query query;
+
     std::vector<SqlValue> table_function_arguments;
   };
   struct QueryCost {
diff --git a/src/trace_processor/storage/trace_storage.h b/src/trace_processor/storage/trace_storage.h
index 21b6090..792ad4f 100644
--- a/src/trace_processor/storage/trace_storage.h
+++ b/src/trace_processor/storage/trace_storage.h
@@ -885,8 +885,9 @@
                           const char* key,
                           std::optional<Variadic>* result) const {
     const auto& args = arg_table();
-    RowMap filtered = args.QueryToRowMap(
-        {args.arg_set_id().eq(arg_set_id), args.key().eq(key)}, {});
+    Query q;
+    q.constraints = {args.arg_set_id().eq(arg_set_id), args.key().eq(key)};
+    RowMap filtered = args.QueryToRowMap(q);
     if (filtered.empty()) {
       *result = std::nullopt;
       return util::OkStatus();
diff --git a/src/trace_processor/tables/BUILD.gn b/src/trace_processor/tables/BUILD.gn
index 8339d95..7cf8bb0 100644
--- a/src/trace_processor/tables/BUILD.gn
+++ b/src/trace_processor/tables/BUILD.gn
@@ -77,6 +77,7 @@
       "../../../include/perfetto/trace_processor",
       "../containers",
       "../db",
+      "../db/column",
     ]
     sources = [ "py_tables_benchmark.cc" ]
   }
diff --git a/src/trace_processor/tables/py_tables_benchmark.cc b/src/trace_processor/tables/py_tables_benchmark.cc
index 6aea3d5..ed19da1 100644
--- a/src/trace_processor/tables/py_tables_benchmark.cc
+++ b/src/trace_processor/tables/py_tables_benchmark.cc
@@ -22,6 +22,7 @@
 #include "perfetto/trace_processor/basic_types.h"
 #include "src/trace_processor/containers/row_map.h"
 #include "src/trace_processor/containers/string_pool.h"
+#include "src/trace_processor/db/column/types.h"
 #include "src/trace_processor/db/table.h"
 #include "src/trace_processor/tables/py_tables_benchmark_py.h"
 
@@ -56,6 +57,7 @@
 
 }  // namespace
 
+using perfetto::trace_processor::Query;
 using perfetto::trace_processor::RowMap;
 using perfetto::trace_processor::SqlValue;
 using perfetto::trace_processor::StringPool;
@@ -98,14 +100,15 @@
 static void BM_TableFilterRootId(benchmark::State& state) {
   StringPool pool;
   RootTestTable root(&pool);
+  Query q;
+  q.constraints = {root.id().eq(30)};
 
   uint32_t size = static_cast<uint32_t>(state.range(0));
   for (uint32_t i = 0; i < size; ++i)
     root.Insert({});
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(
-        root.ApplyAndIterateRows(root.QueryToRowMap({root.id().eq(30)}, {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterRootId)->Apply(TableFilterArgs);
@@ -113,6 +116,9 @@
 static void BM_TableFilterRootIdAndOther(benchmark::State& state) {
   StringPool pool;
   RootTestTable root(&pool);
+  Query q;
+  q.constraints = {root.id().eq(root.row_count() - 1),
+                   root.root_non_null().gt(100)};
 
   uint32_t size = static_cast<uint32_t>(state.range(0));
 
@@ -123,9 +129,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(
-        {root.id().eq(root.row_count() - 1), root.root_non_null().gt(100)},
-        {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterRootIdAndOther)->Apply(TableFilterArgs);
@@ -134,6 +138,8 @@
   StringPool pool;
   RootTestTable root(&pool);
   ChildTestTable child(&pool, &root);
+  Query q;
+  q.constraints = {child.id().eq(30)};
 
   uint32_t size = static_cast<uint32_t>(state.range(0));
   for (uint32_t i = 0; i < size; ++i) {
@@ -142,8 +148,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.id().eq(30)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildId)->Apply(TableFilterArgs);
@@ -152,6 +157,8 @@
   StringPool pool;
   RootTestTable root(&pool);
   ChildTestTable child(&pool, &root);
+  Query q;
+  q.constraints = {child.id().eq(30), child.root_sorted().gt(1024)};
 
   uint32_t size = static_cast<uint32_t>(state.range(0));
   for (uint32_t i = 0; i < size; ++i) {
@@ -165,8 +172,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(
-        {child.id().eq(30), child.root_sorted().gt(1024)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildIdAndSortedInRoot)->Apply(TableFilterArgs);
@@ -174,6 +180,8 @@
 static void BM_TableFilterRootNonNullEqMatchMany(benchmark::State& state) {
   StringPool pool;
   RootTestTable root(&pool);
+  Query q;
+  q.constraints = {root.root_non_null().eq(0)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 1024;
@@ -185,8 +193,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(
-        root.QueryToRowMap({root.root_non_null().eq(0)}, {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterRootNonNullEqMatchMany)->Apply(TableFilterArgs);
@@ -194,6 +201,8 @@
 static void BM_TableFilterRootMultipleNonNull(benchmark::State& state) {
   StringPool pool;
   RootTestTable root(&pool);
+  Query q;
+  q.constraints = {root.root_non_null().lt(4), root.root_non_null_2().lt(10)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 512;
@@ -207,8 +216,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(
-        {root.root_non_null().lt(4), root.root_non_null_2().lt(10)}, {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterRootMultipleNonNull)->Apply(TableFilterArgs);
@@ -216,6 +224,8 @@
 static void BM_TableFilterRootNullableEqMatchMany(benchmark::State& state) {
   StringPool pool;
   RootTestTable root(&pool);
+  Query q;
+  q.constraints = {root.root_nullable().eq(1)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 512;
@@ -231,8 +241,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(
-        root.QueryToRowMap({root.root_nullable().eq(1)}, {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterRootNullableEqMatchMany)->Apply(TableFilterArgs);
@@ -241,6 +250,8 @@
   StringPool pool;
   RootTestTable root(&pool);
   ChildTestTable child(&pool, &root);
+  Query q;
+  q.constraints = {child.child_non_null().eq(0)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 1024;
@@ -254,8 +265,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.child_non_null().eq(0)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildNonNullEqMatchMany)->Apply(TableFilterArgs);
@@ -264,6 +274,8 @@
   StringPool pool;
   RootTestTable root(&pool);
   ChildTestTable child(&pool, &root);
+  Query q;
+  q.constraints = {child.child_nullable().eq(1)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 512;
@@ -280,8 +292,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.child_nullable().eq(1)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildNullableEqMatchMany)->Apply(TableFilterArgs);
@@ -291,6 +302,8 @@
   StringPool pool;
   RootTestTable root(&pool);
   ChildTestTable child(&pool, &root);
+  Query q;
+  q.constraints = {child.root_non_null().eq(0)};
 
   auto size = static_cast<uint32_t>(state.range(0));
   uint32_t partitions = size / 1024;
@@ -304,8 +317,7 @@
   }
 
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.root_non_null().eq(0)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildNonNullEqMatchManyInParent)
@@ -328,9 +340,10 @@
     child.Insert(row);
   }
 
+  Query q;
+  q.constraints = {child.root_nullable().eq(1)};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.root_nullable().eq(1)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildNullableEqMatchManyInParent)
@@ -348,9 +361,10 @@
     root.Insert(row);
   }
 
+  Query q;
+  q.constraints = {root.root_sorted().eq(22)};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(
-        root.QueryToRowMap({root.root_sorted().eq(22)}, {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterParentSortedEq)->Apply(TableFilterArgs);
@@ -373,10 +387,11 @@
   // We choose to search for the last group as if there is O(n^2), it will
   // be more easily visible.
   uint32_t last_group = ((size - 1) / 10) * 10;
+  Query q;
+  q.constraints = {root.root_sorted().eq(last_group),
+                   root.root_non_null().eq(size - 1)};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(
-        {root.root_sorted().eq(last_group), root.root_non_null().eq(size - 1)},
-        {})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterParentSortedAndOther)->Apply(TableFilterArgs);
@@ -395,9 +410,10 @@
     child.Insert(row);
   }
 
+  Query q;
+  q.constraints = {child.child_sorted().eq(22)};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.child_sorted().eq(22)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildSortedEq)->Apply(TableFilterArgs);
@@ -419,9 +435,10 @@
     child.Insert(row);
   }
 
+  Query q;
+  q.constraints = {child.root_sorted().eq(22)};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({child.root_sorted().eq(22)}, {})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableFilterChildSortedEqInParent)->Apply(TableFilterArgs);
@@ -441,9 +458,10 @@
     root.Insert(row);
   }
 
+  Query q;
+  q.orders = {root.root_non_null().ascending()};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(
-        root.QueryToRowMap({}, {root.root_non_null().ascending()})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableSortRootNonNull)->Apply(TableSortArgs);
@@ -464,9 +482,10 @@
     root.Insert(row);
   }
 
+  Query q;
+  q.orders = {root.root_nullable().ascending()};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(root.ApplyAndIterateRows(
-        root.QueryToRowMap({}, {root.root_nullable().ascending()})));
+    benchmark::DoNotOptimize(root.ApplyAndIterateRows(root.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableSortRootNullable)->Apply(TableSortArgs);
@@ -493,9 +512,10 @@
     child.Insert(child_row);
   }
 
+  Query q;
+  q.orders = {child.root_non_null().ascending()};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({}, {child.root_non_null().ascending()})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableSortChildNonNullInParent)->Apply(TableSortArgs);
@@ -524,9 +544,10 @@
     child.Insert(child_row);
   }
 
+  Query q;
+  q.orders = {child.root_nullable().ascending()};
   for (auto _ : state) {
-    benchmark::DoNotOptimize(child.ApplyAndIterateRows(
-        child.QueryToRowMap({}, {child.root_nullable().ascending()})));
+    benchmark::DoNotOptimize(child.ApplyAndIterateRows(child.QueryToRowMap(q)));
   }
 }
 BENCHMARK(BM_TableSortChildNullableInParent)->Apply(TableSortArgs);
diff --git a/src/trace_processor/tables/py_tables_unittest.cc b/src/trace_processor/tables/py_tables_unittest.cc
index 09056d8..1f4a4ef 100644
--- a/src/trace_processor/tables/py_tables_unittest.cc
+++ b/src/trace_processor/tables/py_tables_unittest.cc
@@ -243,14 +243,16 @@
   // Verify that not-present ids are not returned.
   {
     static constexpr uint32_t kFilterArgSetId = 1;
-    auto res =
-        table.QueryToRowMap({table.arg_set_id().eq(kFilterArgSetId)}, {});
+    Query q;
+    q.constraints = {table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_TRUE(res.empty());
   }
   {
     static constexpr uint32_t kFilterArgSetId = 9;
-    auto res =
-        table.QueryToRowMap({table.arg_set_id().eq(kFilterArgSetId)}, {});
+    Query q;
+    q.constraints = {table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_TRUE(res.empty());
   }
 
@@ -260,8 +262,9 @@
   // Verify that filtering equality for real arg set ids works as expected.
   {
     static constexpr uint32_t kFilterArgSetId = 4;
-    auto res =
-        table.QueryToRowMap({table.arg_set_id().eq(kFilterArgSetId)}, {});
+    Query q;
+    q.constraints = {table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_EQ(res.size(), 4u);
     for (auto it = table.ApplyAndIterateRows(std::move(res)); it; ++it) {
       auto arg_set_id =
@@ -271,8 +274,9 @@
   }
   {
     static constexpr uint32_t kFilterArgSetId = 0;
-    auto res =
-        table.QueryToRowMap({table.arg_set_id().eq(kFilterArgSetId)}, {});
+    Query q;
+    q.constraints = {table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_EQ(res.size(), 2u);
     for (auto it = table.ApplyAndIterateRows(std::move(res)); it; ++it) {
       auto arg_set_id =
@@ -282,8 +286,9 @@
   }
   {
     static constexpr uint32_t kFilterArgSetId = 8;
-    auto res =
-        table.QueryToRowMap({table.arg_set_id().eq(kFilterArgSetId)}, {});
+    Query q;
+    q.constraints = {table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_EQ(res.size(), 1u);
     for (auto it = table.ApplyAndIterateRows(std::move(res)); it; ++it) {
       auto arg_set_id =
@@ -296,9 +301,10 @@
   // column works.
   {
     static constexpr uint32_t kFilterArgSetId = 4;
-    auto res = table.QueryToRowMap(
-        {table.int_value().eq(200), table.arg_set_id().eq(kFilterArgSetId)},
-        {});
+    Query q;
+    q.constraints = {table.int_value().eq(200),
+                     table.arg_set_id().eq(kFilterArgSetId)};
+    auto res = table.QueryToRowMap(q);
     ASSERT_EQ(res.size(), 2u);
     for (auto it = table.ApplyAndIterateRows(std::move(res)); it; ++it) {
       uint32_t arg_set_id =
diff --git a/src/trace_processor/trace_processor_impl.cc b/src/trace_processor/trace_processor_impl.cc
index b36a63a..30c83e6 100644
--- a/src/trace_processor/trace_processor_impl.cc
+++ b/src/trace_processor/trace_processor_impl.cc
@@ -81,6 +81,8 @@
 #include "src/trace_processor/perfetto_sql/intrinsics/functions/to_ftrace.h"
 #include "src/trace_processor/perfetto_sql/intrinsics/functions/utils.h"
 #include "src/trace_processor/perfetto_sql/intrinsics/functions/window_functions.h"
+#include "src/trace_processor/perfetto_sql/intrinsics/operators/counter_mipmap_operator.h"
+#include "src/trace_processor/perfetto_sql/intrinsics/operators/slice_mipmap_operator.h"
 #include "src/trace_processor/perfetto_sql/intrinsics/operators/span_join_operator.h"
 #include "src/trace_processor/perfetto_sql/intrinsics/operators/window_operator.h"
 #include "src/trace_processor/perfetto_sql/intrinsics/table_functions/ancestor.h"
@@ -747,6 +749,12 @@
       std::make_unique<SpanJoinOperatorModule::Context>(engine_.get()));
   engine_->sqlite_engine()->RegisterVirtualTableModule<WindowOperatorModule>(
       "window", std::make_unique<WindowOperatorModule::Context>());
+  engine_->sqlite_engine()->RegisterVirtualTableModule<CounterMipmapOperator>(
+      "__intrinsic_counter_mipmap",
+      std::make_unique<CounterMipmapOperator::Context>(engine_.get()));
+  engine_->sqlite_engine()->RegisterVirtualTableModule<SliceMipmapOperator>(
+      "__intrinsic_slice_mipmap",
+      std::make_unique<SliceMipmapOperator::Context>(engine_.get()));
 
   // Initalize the tables and views in the prelude.
   InitializePreludeTablesViews(db);
diff --git a/src/trace_processor/types/trace_processor_context.h b/src/trace_processor/types/trace_processor_context.h
index af2837f..3136835 100644
--- a/src/trace_processor/types/trace_processor_context.h
+++ b/src/trace_processor/types/trace_processor_context.h
@@ -131,22 +131,23 @@
   // the GetOrCreate() method on their subclass type, e.g.
   // SyscallTracker::GetOrCreate(context)
   // clang-format off
-  std::unique_ptr<Destructible> android_probes_tracker;  // AndroidProbesTracker
-  std::unique_ptr<Destructible> binder_tracker;          // BinderTracker
-  std::unique_ptr<Destructible> heap_graph_tracker;      // HeapGraphTracker
-  std::unique_ptr<Destructible> syscall_tracker;         // SyscallTracker
-  std::unique_ptr<Destructible> system_info_tracker;     // SystemInfoTracker
-  std::unique_ptr<Destructible> v4l2_tracker;            // V4l2Tracker
-  std::unique_ptr<Destructible> virtio_video_tracker;    // VirtioVideoTracker
-  std::unique_ptr<Destructible> systrace_parser;         // SystraceParser
-  std::unique_ptr<Destructible> thread_state_tracker;    // ThreadStateTracker
-  std::unique_ptr<Destructible> i2c_tracker;             // I2CTracker
-  std::unique_ptr<Destructible> perf_data_tracker;       // PerfDataTracker
-  std::unique_ptr<Destructible> content_analyzer;        // ProtoContentAnalyzer
+  std::unique_ptr<Destructible> android_probes_tracker;    // AndroidProbesTracker
+  std::unique_ptr<Destructible> binder_tracker;            // BinderTracker
+  std::unique_ptr<Destructible> heap_graph_tracker;        // HeapGraphTracker
+  std::unique_ptr<Destructible> syscall_tracker;           // SyscallTracker
+  std::unique_ptr<Destructible> system_info_tracker;       // SystemInfoTracker
+  std::unique_ptr<Destructible> v4l2_tracker;              // V4l2Tracker
+  std::unique_ptr<Destructible> virtio_video_tracker;      // VirtioVideoTracker
+  std::unique_ptr<Destructible> systrace_parser;           // SystraceParser
+  std::unique_ptr<Destructible> thread_state_tracker;      // ThreadStateTracker
+  std::unique_ptr<Destructible> i2c_tracker;               // I2CTracker
+  std::unique_ptr<Destructible> perf_data_tracker;         // PerfDataTracker
+  std::unique_ptr<Destructible> content_analyzer;          // ProtoContentAnalyzer
   std::unique_ptr<Destructible> shell_transitions_tracker; // ShellTransitionsTracker
-  std::unique_ptr<Destructible> ftrace_sched_tracker;    // FtraceSchedEventTracker
-  std::unique_ptr<Destructible> v8_tracker;              // V8Tracker
-  std::unique_ptr<Destructible> jit_tracker;             // JitTracker
+  std::unique_ptr<Destructible> protolog_messages_tracker; // ProtoLogMessagesTracker
+  std::unique_ptr<Destructible> ftrace_sched_tracker;      // FtraceSchedEventTracker
+  std::unique_ptr<Destructible> v8_tracker;                // V8Tracker
+  std::unique_ptr<Destructible> jit_tracker;               // JitTracker
   // clang-format on
 
   // These fields are trace readers which will be called by |forwarding_parser|
diff --git a/src/trace_processor/util/profile_builder.cc b/src/trace_processor/util/profile_builder.cc
index 951472b..6948a8e 100644
--- a/src/trace_processor/util/profile_builder.cc
+++ b/src/trace_processor/util/profile_builder.cc
@@ -466,9 +466,9 @@
   using RowRef =
       perfetto::trace_processor::tables::SymbolTable::ConstRowReference;
   std::vector<RowRef> symbol_set;
-  for (auto it = symbols.FilterToIterator(
-           {symbols.symbol_set_id().eq(*symbol_set_id)});
-       it; ++it) {
+  Query q;
+  q.constraints = {symbols.symbol_set_id().eq(*symbol_set_id)};
+  for (auto it = symbols.FilterToIterator(q); it; ++it) {
     symbol_set.push_back(it.row_reference());
   }
 
diff --git a/src/trace_redaction/BUILD.gn b/src/trace_redaction/BUILD.gn
index be268d7..4f2fb5f 100644
--- a/src/trace_redaction/BUILD.gn
+++ b/src/trace_redaction/BUILD.gn
@@ -28,6 +28,8 @@
 
 source_set("trace_redaction") {
   sources = [
+    "collect_frame_cookies.cc",
+    "collect_frame_cookies.h",
     "collect_timeline_events.cc",
     "collect_timeline_events.h",
     "filter_ftrace_using_allowlist.cc",
@@ -42,6 +44,7 @@
     "filter_task_rename.h",
     "find_package_uid.cc",
     "find_package_uid.h",
+    "frame_cookie.h",
     "optimize_timeline.cc",
     "optimize_timeline.h",
     "populate_allow_lists.cc",
@@ -122,6 +125,7 @@
 perfetto_unittest_source_set("unittests") {
   testonly = true
   sources = [
+    "collect_frame_cookies_unittest.cc",
     "collect_timeline_events_unittest.cc",
     "filter_ftrace_using_allowlist_unittest.cc",
     "filter_packet_using_allowlist_unittest.cc",
@@ -147,6 +151,7 @@
     "../../protos/perfetto/trace:non_minimal_cpp",
     "../../protos/perfetto/trace:zero",
     "../../protos/perfetto/trace/android:cpp",
+    "../../protos/perfetto/trace/android:zero",
     "../../protos/perfetto/trace/ftrace:cpp",
     "../../protos/perfetto/trace/ftrace:zero",
     "../../protos/perfetto/trace/ps:cpp",
diff --git a/src/trace_redaction/collect_frame_cookies.cc b/src/trace_redaction/collect_frame_cookies.cc
new file mode 100644
index 0000000..13e5539
--- /dev/null
+++ b/src/trace_redaction/collect_frame_cookies.cc
@@ -0,0 +1,212 @@
+/*
+ * 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.
+ */
+
+#include "src/trace_redaction/collect_frame_cookies.h"
+
+#include "perfetto/base/status.h"
+#include "perfetto/protozero/field.h"
+#include "perfetto/protozero/proto_decoder.h"
+#include "src/trace_redaction/trace_redaction_framework.h"
+
+#include "protos/perfetto/trace/android/frame_timeline_event.pbzero.h"
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+
+namespace perfetto::trace_redaction {
+
+namespace {
+
+using FrameTimelineEvent = protos::pbzero::FrameTimelineEvent;
+
+struct Frame {
+  uint32_t id;
+  uint32_t pid;
+  uint32_t cookie;
+};
+
+constexpr Frame kActualDisplayFrameStart = {
+    FrameTimelineEvent::kActualDisplayFrameStartFieldNumber,
+    FrameTimelineEvent::ActualDisplayFrameStart::kPidFieldNumber,
+    FrameTimelineEvent::ActualDisplayFrameStart::kCookieFieldNumber,
+};
+
+constexpr Frame kExpectedDisplayFrameStart = {
+    FrameTimelineEvent::kExpectedDisplayFrameStartFieldNumber,
+    FrameTimelineEvent::ExpectedDisplayFrameStart::kPidFieldNumber,
+    FrameTimelineEvent::ExpectedDisplayFrameStart::kCookieFieldNumber,
+};
+
+constexpr Frame kActualSurfaceFrameStart = {
+    FrameTimelineEvent::kActualSurfaceFrameStartFieldNumber,
+    FrameTimelineEvent::ActualSurfaceFrameStart::kPidFieldNumber,
+    FrameTimelineEvent::ActualSurfaceFrameStart::kCookieFieldNumber,
+};
+
+constexpr Frame kExpectedSurfaceFrameStart = {
+    FrameTimelineEvent::kExpectedSurfaceFrameStartFieldNumber,
+    FrameTimelineEvent::ExpectedSurfaceFrameStart::kPidFieldNumber,
+    FrameTimelineEvent::ExpectedSurfaceFrameStart::kCookieFieldNumber,
+};
+
+// Do not use `pid` from `kFrameEnd`.
+constexpr Frame kFrameEnd = {
+    FrameTimelineEvent::kFrameEndFieldNumber,
+    0,
+    FrameTimelineEvent::FrameEnd::kCookieFieldNumber,
+};
+
+}  // namespace
+
+base::Status CollectFrameCookies::Begin(Context* context) const {
+  if (context->global_frame_cookies.empty()) {
+    return base::OkStatus();
+  }
+
+  return base::ErrStatus("FindFrameCookies: frame cookies already populated");
+}
+
+base::Status CollectFrameCookies::Collect(
+    const protos::pbzero::TracePacket::Decoder& packet,
+    Context* context) const {
+  // A frame cookie needs a time and pid for a timeline query. Ignore packets
+  // without a timestamp.
+  if (!packet.has_timestamp() || !packet.has_frame_timeline_event()) {
+    return base::OkStatus();
+  }
+
+  auto timestamp = packet.timestamp();
+
+  // Only use the start frames. They are the only ones with a pid. End events
+  // use the cookies to reference the pid in a start event.
+  auto handlers = {
+      kActualDisplayFrameStart,
+      kActualSurfaceFrameStart,
+      kExpectedDisplayFrameStart,
+      kExpectedSurfaceFrameStart,
+  };
+
+  // Timeline Event Decoder.
+  protozero::ProtoDecoder decoder(packet.frame_timeline_event());
+
+  // If no handler worked, cookie will not get added to the global cookie field.
+  for (const auto& handler : handlers) {
+    auto outer = decoder.FindField(handler.id);
+
+    if (!outer.valid()) {
+      continue;
+    }
+
+    protozero::ProtoDecoder inner(outer.as_bytes());
+
+    auto pid = inner.FindField(handler.pid);
+    auto cookie = inner.FindField(handler.cookie);
+
+    // This should be handled, but it is not valid. Drop the event by not adding
+    // it to the global_frame_cookies list.
+    if (!pid.valid() || !cookie.valid()) {
+      continue;
+    }
+
+    FrameCookie frame_cookie;
+    frame_cookie.pid = pid.as_int32();
+    frame_cookie.cookie = cookie.as_int64();
+    frame_cookie.ts = timestamp;
+
+    context->global_frame_cookies.push_back(frame_cookie);
+
+    break;
+  }
+
+  return base::OkStatus();
+}
+
+base::Status ReduceFrameCookies::Build(Context* context) const {
+  if (!context->package_uid.has_value()) {
+    return base::ErrStatus("ReduceFrameCookies: missing package uid.");
+  }
+
+  if (!context->timeline) {
+    return base::ErrStatus("ReduceFrameCookies: missing timeline.");
+  }
+
+  // Even though it is rare, it is possible for there to be no SurfaceFlinger
+  // frame cookies. Even through the main path handles this, we use this early
+  // exit to document this edge case.
+  if (context->global_frame_cookies.empty()) {
+    return base::OkStatus();
+  }
+
+  const auto* timeline = context->timeline.get();
+  auto uid = context->package_uid.value();
+
+  auto& package_frame_cookies = context->package_frame_cookies;
+
+  // Filter the global cookies down to cookies that belong to the target package
+  // (uid).
+  for (const auto& cookie : context->global_frame_cookies) {
+    auto cookie_slice = timeline->Search(cookie.ts, cookie.pid);
+
+    if (cookie_slice.uid == uid) {
+      package_frame_cookies.insert(cookie.cookie);
+    }
+  }
+
+  return base::OkStatus();
+}
+
+bool FilterFrameEvents::KeepField(const Context& context,
+                                  const protozero::Field& field) const {
+  // If this field is not a timeline event, then this primitive has no reason to
+  // reject this field.
+  //
+  // If it is a timeline event, the event's cookie must be in the package's
+  // cookies.
+  if (field.id() !=
+      protos::pbzero::TracePacket::kFrameTimelineEventFieldNumber) {
+    return true;
+  }
+
+  protozero::ProtoDecoder timeline_event_decoder(field.as_bytes());
+
+  auto handlers = {
+      kActualDisplayFrameStart,
+      kActualSurfaceFrameStart,
+      kExpectedDisplayFrameStart,
+      kExpectedSurfaceFrameStart,
+      kFrameEnd,
+  };
+
+  const auto& cookies = context.package_frame_cookies;
+
+  for (const auto& handler : handlers) {
+    auto event = timeline_event_decoder.FindField(handler.id);
+
+    if (!event.valid()) {
+      continue;
+    }
+
+    protozero::ProtoDecoder event_decoder(event.as_bytes());
+
+    auto cookie = event_decoder.FindField(handler.cookie);
+
+    if (cookie.valid() && cookies.count(cookie.as_int64())) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+}  // namespace perfetto::trace_redaction
diff --git a/src/trace_redaction/collect_frame_cookies.h b/src/trace_redaction/collect_frame_cookies.h
new file mode 100644
index 0000000..7463ff6
--- /dev/null
+++ b/src/trace_redaction/collect_frame_cookies.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+#ifndef SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
+#define SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
+
+#include "perfetto/protozero/field.h"
+#include "src/trace_redaction/scrub_trace_packet.h"
+#include "src/trace_redaction/trace_redaction_framework.h"
+
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+
+namespace perfetto::trace_redaction {
+
+// Populates Context::global_frame_cookies using FrameTimelineEvent messages.
+class CollectFrameCookies : public CollectPrimitive {
+ public:
+  base::Status Begin(Context* context) const override;
+
+  base::Status Collect(const protos::pbzero::TracePacket::Decoder& packet,
+                       Context* context) const override;
+
+ private:
+  void OnTimelineEvent(const protos::pbzero::TracePacket::Decoder& packet,
+                       protozero::ConstBytes bytes,
+                       Context* context) const;
+};
+
+// Moves cookies from Context::global_frame_cookies to
+// Context::package_frame_cookies using Cookies::timeline and
+// Cookies::package_uid.
+class ReduceFrameCookies : public BuildPrimitive {
+ public:
+  base::Status Build(Context* context) const override;
+};
+
+// Flags start-frame and end-frame events as keep/drop using
+// Context::package_frame_cookies.
+class FilterFrameEvents : public TracePacketFilter {
+ public:
+  bool KeepField(const Context& context,
+                 const protozero::Field& field) const override;
+};
+
+}  // namespace perfetto::trace_redaction
+
+#endif  // SRC_TRACE_REDACTION_COLLECT_FRAME_COOKIES_H_
diff --git a/src/trace_redaction/collect_frame_cookies_unittest.cc b/src/trace_redaction/collect_frame_cookies_unittest.cc
new file mode 100644
index 0000000..6e77231
--- /dev/null
+++ b/src/trace_redaction/collect_frame_cookies_unittest.cc
@@ -0,0 +1,346 @@
+
+/*
+ * 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.
+ */
+
+#include "src/trace_redaction/collect_frame_cookies.h"
+#include "src/base/test/status_matchers.h"
+#include "src/trace_redaction/collect_timeline_events.h"
+#include "test/gtest_and_gmock.h"
+
+#include "protos/perfetto/trace/android/frame_timeline_event.gen.h"
+#include "protos/perfetto/trace/android/frame_timeline_event.pbzero.h"
+#include "protos/perfetto/trace/trace_packet.gen.h"
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+
+namespace perfetto::trace_redaction {
+namespace {
+
+constexpr uint64_t kTimestampA = 0;
+constexpr uint64_t kTimestampB = 1000;
+constexpr uint64_t kTimestampC = 2000;
+constexpr uint64_t kTimestampD = 3000;
+constexpr uint64_t kTimestampE = 3000;
+
+constexpr int64_t kCookieA = 1234;
+
+// Start at 1, amd not zero, because zero hnas special meaning (system uid).
+constexpr uint64_t kUidA = 1;
+
+constexpr int32_t kPidNone = 10;
+constexpr int32_t kPidA = 11;
+
+}  // namespace
+
+class FrameCookieFixture {
+ protected:
+  std::string CreateStartEvent(int32_t field_id,
+                               uint64_t ts,
+                               int32_t pid,
+                               int64_t cookie) const {
+    protos::gen::TracePacket packet;
+    packet.set_timestamp(ts);
+
+    switch (field_id) {
+      case protos::pbzero::FrameTimelineEvent::
+          kExpectedSurfaceFrameStartFieldNumber:
+        CreateExpectedSurfaceFrameStart(pid, cookie,
+                                        packet.mutable_frame_timeline_event());
+        break;
+
+      case protos::pbzero::FrameTimelineEvent::
+          kActualSurfaceFrameStartFieldNumber:
+        CreateActualSurfaceFrameStart(pid, cookie,
+                                      packet.mutable_frame_timeline_event());
+        break;
+
+      case protos::pbzero::FrameTimelineEvent::
+          kExpectedDisplayFrameStartFieldNumber:
+        CreateExpectedDisplayFrameStart(pid, cookie,
+                                        packet.mutable_frame_timeline_event());
+        break;
+
+      case protos::pbzero::FrameTimelineEvent::
+          kActualDisplayFrameStartFieldNumber:
+        CreateActualDisplayFrameStart(pid, cookie,
+                                      packet.mutable_frame_timeline_event());
+        break;
+
+      default:
+        PERFETTO_FATAL("Invalid field id");
+        break;
+    }
+
+    return packet.SerializeAsString();
+  }
+
+  std::string CreateFrameEnd(uint64_t ts, int64_t cookie) const {
+    protos::gen::TracePacket packet;
+    packet.set_timestamp(ts);
+
+    auto* start = packet.mutable_frame_timeline_event()->mutable_frame_end();
+    start->set_cookie(cookie);
+
+    return packet.SerializeAsString();
+  }
+
+  void CollectEvents(std::initializer_list<ProcessThreadTimeline::Event> events,
+                     Context* context) const {
+    CollectTimelineEvents collect;
+    ASSERT_OK(collect.Begin(context));
+
+    for (const auto& event : events) {
+      context->timeline->Append(event);
+    }
+
+    ASSERT_OK(collect.End(context));
+  }
+
+  void CollectCookies(std::initializer_list<std::string> packets,
+                      Context* context) const {
+    CollectFrameCookies collect;
+    ASSERT_OK(collect.Begin(context));
+
+    for (const auto& packet : packets) {
+      protos::pbzero::TracePacket::Decoder decoder(packet);
+      ASSERT_OK(collect.Collect(decoder, context));
+    }
+
+    ASSERT_OK(collect.End(context));
+  }
+
+ private:
+  void CreateExpectedSurfaceFrameStart(
+      int32_t pid,
+      int64_t cookie,
+      protos::gen::FrameTimelineEvent* event) const {
+    auto* start = event->mutable_expected_surface_frame_start();
+    start->set_cookie(cookie);
+    start->set_pid(pid);
+  }
+
+  void CreateActualSurfaceFrameStart(
+      int32_t pid,
+      int64_t cookie,
+      protos::gen::FrameTimelineEvent* event) const {
+    auto* start = event->mutable_actual_surface_frame_start();
+    start->set_cookie(cookie);
+    start->set_pid(pid);
+  }
+
+  void CreateExpectedDisplayFrameStart(
+      int32_t pid,
+      int64_t cookie,
+      protos::gen::FrameTimelineEvent* event) const {
+    auto* start = event->mutable_expected_display_frame_start();
+    start->set_cookie(cookie);
+    start->set_pid(pid);
+  }
+
+  void CreateActualDisplayFrameStart(
+      int32_t pid,
+      int64_t cookie,
+      protos::gen::FrameTimelineEvent* event) const {
+    auto* start = event->mutable_actual_display_frame_start();
+    start->set_cookie(cookie);
+    start->set_pid(pid);
+  }
+};
+
+class CollectFrameCookiesTest : public testing::Test,
+                                protected FrameCookieFixture,
+                                public testing::WithParamInterface<int32_t> {
+ protected:
+  Context context_;
+};
+
+TEST_P(CollectFrameCookiesTest, ExtractsExpectedSurfaceFrameStart) {
+  auto field_id = GetParam();
+
+  auto packet = CreateStartEvent(field_id, kTimestampA, kPidA, kCookieA);
+
+  CollectCookies({packet}, &context_);
+
+  ASSERT_EQ(context_.global_frame_cookies.size(), 1u);
+
+  auto& cookie = context_.global_frame_cookies.back();
+  ASSERT_EQ(cookie.cookie, kCookieA);
+  ASSERT_EQ(cookie.pid, kPidA);
+  ASSERT_EQ(cookie.ts, kTimestampA);
+}
+
+INSTANTIATE_TEST_SUITE_P(
+    EveryStartEventType,
+    CollectFrameCookiesTest,
+    testing::Values(
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::kActualSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedDisplayFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kActualDisplayFrameStartFieldNumber));
+
+// End events have no influence during the collect phase because they don't have
+// a direct connection to a process. They're indirectly connected to a pid via a
+// start event (via a common cookie value).
+TEST_F(CollectFrameCookiesTest, IgnoresFrameEnd) {
+  CollectCookies({CreateFrameEnd(kTimestampA, kPidA)}, &context_);
+
+  ASSERT_TRUE(context_.global_frame_cookies.empty());
+}
+
+class ReduceFrameCookiesTest : public testing::Test,
+                               protected FrameCookieFixture,
+                               public testing::WithParamInterface<int32_t> {
+ protected:
+  void SetUp() {
+    context_.package_uid = kUidA;
+
+    // Time A   +- Time B       +- Time C    +- Time D   +- Time E
+    //          |                            |
+    //          +------------ Pid A ---------+
+    //
+    // The pid will be active from time b to time d. Time A will be used for
+    // "before active". Time C will be used for "while active". Time E will be
+    // used for "after active".
+    CollectEvents(
+        {
+            ProcessThreadTimeline::Event::Open(kTimestampB, kPidA, kPidNone,
+                                               kUidA),
+            ProcessThreadTimeline::Event::Close(kTimestampD, kPidA),
+        },
+        &context_);
+  }
+
+  ReduceFrameCookies reduce_;
+  Context context_;
+};
+
+TEST_P(ReduceFrameCookiesTest, RejectBeforeActive) {
+  auto field_id = GetParam();
+
+  // kTimestampA is before pid starts.
+  auto packet = CreateStartEvent(field_id, kTimestampA, kPidA, kCookieA);
+
+  CollectCookies({packet}, &context_);
+
+  ASSERT_OK(reduce_.Build(&context_));
+  ASSERT_FALSE(context_.package_frame_cookies.count(kCookieA));
+}
+
+TEST_P(ReduceFrameCookiesTest, AcceptDuringActive) {
+  auto field_id = GetParam();
+
+  // kTimestampC is between pid starts and ends.
+  auto packet = CreateStartEvent(field_id, kTimestampC, kPidA, kCookieA);
+
+  CollectCookies({packet}, &context_);
+
+  ASSERT_OK(reduce_.Build(&context_));
+  ASSERT_TRUE(context_.package_frame_cookies.count(kCookieA));
+}
+
+TEST_P(ReduceFrameCookiesTest, RejectAfterActive) {
+  auto field_id = GetParam();
+
+  // kTimestampE is after pid ends.
+  auto packet = CreateStartEvent(field_id, kTimestampE, kPidA, kCookieA);
+
+  CollectCookies({packet}, &context_);
+
+  ASSERT_OK(reduce_.Build(&context_));
+  ASSERT_FALSE(context_.package_frame_cookies.count(kCookieA));
+}
+
+INSTANTIATE_TEST_SUITE_P(
+    EveryStartEventType,
+    ReduceFrameCookiesTest,
+    testing::Values(
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::kActualSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedDisplayFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kActualDisplayFrameStartFieldNumber));
+
+class FilterCookiesFieldsTest : public testing::Test,
+                                protected FrameCookieFixture,
+                                public testing::WithParamInterface<int32_t> {
+ protected:
+  protozero::Field ExtractTimelineEvent(const std::string& packet) const {
+    protozero::ProtoDecoder packet_decoder(packet);
+
+    // There must be one in order for the test to work, so we assume it's there.
+    return packet_decoder.FindField(
+        protos::pbzero::TracePacket::kFrameTimelineEventFieldNumber);
+  }
+
+  FilterFrameEvents filter_;
+  Context context_;
+};
+
+// If the event was within a valid pid's lifespan and was connected to the
+// package, it should be kept.
+TEST_P(FilterCookiesFieldsTest, IncludeIncludedStartCookies) {
+  context_.package_frame_cookies.insert(kCookieA);
+
+  auto field_id = GetParam();
+  auto packet = CreateStartEvent(field_id, kTimestampA, kPidA, kCookieA);
+  auto timeline_field = ExtractTimelineEvent(packet);
+
+  ASSERT_TRUE(filter_.KeepField(context_, timeline_field));
+}
+
+// If the event wasn't within a valid pid's lifespans and/or was connected to a
+// package, it should be removed.
+TEST_P(FilterCookiesFieldsTest, ExcludeMissingStartCookies) {
+  auto field_id = GetParam();
+  auto packet = CreateStartEvent(field_id, kTimestampA, kPidA, kCookieA);
+  auto timeline_field = ExtractTimelineEvent(packet);
+
+  ASSERT_FALSE(filter_.KeepField(context_, timeline_field));
+}
+
+INSTANTIATE_TEST_SUITE_P(
+    EveryStartEventType,
+    FilterCookiesFieldsTest,
+    testing::Values(
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::kActualSurfaceFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kExpectedDisplayFrameStartFieldNumber,
+        protos::pbzero::FrameTimelineEvent::
+            kActualDisplayFrameStartFieldNumber));
+
+TEST_F(FilterCookiesFieldsTest, IncludeIncludedEndCookies) {
+  context_.package_frame_cookies.insert(kCookieA);
+
+  auto packet = CreateFrameEnd(kTimestampA, kCookieA);
+  auto timeline_field = ExtractTimelineEvent(packet);
+
+  ASSERT_TRUE(filter_.KeepField(context_, timeline_field));
+}
+
+TEST_F(FilterCookiesFieldsTest, ExcludeMissingEndCookies) {
+  auto packet = CreateFrameEnd(kTimestampA, kCookieA);
+  auto timeline_field = ExtractTimelineEvent(packet);
+
+  ASSERT_FALSE(filter_.KeepField(context_, timeline_field));
+}
+
+}  // namespace perfetto::trace_redaction
diff --git a/src/trace_redaction/frame_cookie.h b/src/trace_redaction/frame_cookie.h
new file mode 100644
index 0000000..bd96804
--- /dev/null
+++ b/src/trace_redaction/frame_cookie.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#ifndef SRC_TRACE_REDACTION_FRAME_COOKIE_H_
+#define SRC_TRACE_REDACTION_FRAME_COOKIE_H_
+
+#include <cstdint>
+
+struct FrameCookie {
+  // The timestamp from the trace packet.
+  uint64_t ts;
+
+  // The cookie value will be found inside of the start event (there are four
+  // different start types). This is the app's pid (main thread id).
+
+  // ExpectedSurfaceFrameStart: pid = app id
+  // ActualSurfaceFrameStart: pid = app id
+
+  // ExpectedDisplayFrameStart: pid = surface flinger
+  // ActualDisplayFrameStart: pid = surface flinger
+  int32_t pid;
+
+  // The cookie value will be found inside of the start event (there are four
+  // different start types). End events use the cookie to connect to the start
+  // event. Therefore end events don't need a pid.
+  int64_t cookie;
+};
+
+#endif  // SRC_TRACE_REDACTION_FRAME_COOKIE_H_
diff --git a/src/trace_redaction/main.cc b/src/trace_redaction/main.cc
index 656fdef..2e433c0 100644
--- a/src/trace_redaction/main.cc
+++ b/src/trace_redaction/main.cc
@@ -16,6 +16,7 @@
 
 #include "perfetto/base/logging.h"
 #include "perfetto/base/status.h"
+#include "src/trace_redaction/collect_frame_cookies.h"
 #include "src/trace_redaction/collect_timeline_events.h"
 #include "src/trace_redaction/filter_ftrace_using_allowlist.h"
 #include "src/trace_redaction/filter_packet_using_allowlist.h"
@@ -49,15 +50,18 @@
   // Add all collectors.
   redactor.emplace_collect<FindPackageUid>();
   redactor.emplace_collect<CollectTimelineEvents>();
+  redactor.emplace_collect<CollectFrameCookies>();
 
   // Add all builders.
   redactor.emplace_build<PopulateAllowlists>();
   redactor.emplace_build<AllowSuspendResume>();
   redactor.emplace_build<OptimizeTimeline>();
+  redactor.emplace_build<ReduceFrameCookies>();
 
   // Add all transforms.
   auto* scrub_packet = redactor.emplace_transform<ScrubTracePacket>();
   scrub_packet->emplace_back<FilterPacketUsingAllowlist>();
+  scrub_packet->emplace_back<FilterFrameEvents>();
 
   auto* scrub_ftrace_events = redactor.emplace_transform<ScrubFtraceEvents>();
   scrub_ftrace_events->emplace_back<FilterFtraceUsingAllowlist>();
diff --git a/src/trace_redaction/populate_allow_lists.cc b/src/trace_redaction/populate_allow_lists.cc
index 1c42bd1..b2c9431 100644
--- a/src/trace_redaction/populate_allow_lists.cc
+++ b/src/trace_redaction/populate_allow_lists.cc
@@ -26,7 +26,7 @@
 
 base::Status PopulateAllowlists::Build(Context* context) const {
   // These fields are top-level fields that outside the "oneof data" field.
-  std::initializer_list<uint> required_trace_fields = {
+  std::initializer_list<uint32_t> required_trace_fields = {
 
       protos::pbzero::TracePacket::kTimestampFieldNumber,
       protos::pbzero::TracePacket::kTimestampClockIdFieldNumber,
@@ -59,7 +59,7 @@
   //      constraints around keys or values, making fine-grain redaction
   //      difficult. Because this packet's value has no measurable, the safest
   //      option to drop the whole packet.
-  std::initializer_list<uint> trace_packets = {
+  std::initializer_list<uint32_t> trace_packets = {
       protos::pbzero::TracePacket::kProcessTreeFieldNumber,
       protos::pbzero::TracePacket::kProcessStatsFieldNumber,
       protos::pbzero::TracePacket::kClockSnapshotFieldNumber,
@@ -84,7 +84,7 @@
     context->trace_packet_allow_list.insert(item);
   }
 
-  std::initializer_list<uint> ftrace_events = {
+  std::initializer_list<uint32_t> ftrace_events = {
       protos::pbzero::FtraceEvent::kSchedSwitchFieldNumber,
       protos::pbzero::FtraceEvent::kCpuFrequencyFieldNumber,
       protos::pbzero::FtraceEvent::kCpuIdleFieldNumber,
diff --git a/src/trace_redaction/scrub_trace_packet.cc b/src/trace_redaction/scrub_trace_packet.cc
index 77ff55c..fd29885 100644
--- a/src/trace_redaction/scrub_trace_packet.cc
+++ b/src/trace_redaction/scrub_trace_packet.cc
@@ -27,6 +27,10 @@
 
 TracePacketFilter::~TracePacketFilter() = default;
 
+base::Status TracePacketFilter::VerifyContext(const Context&) const {
+  return base::OkStatus();
+}
+
 base::Status ScrubTracePacket::Transform(const Context& context,
                                          std::string* packet) const {
   if (packet == nullptr || packet->empty()) {
diff --git a/src/trace_redaction/scrub_trace_packet.h b/src/trace_redaction/scrub_trace_packet.h
index 331cccf..22e506b 100644
--- a/src/trace_redaction/scrub_trace_packet.h
+++ b/src/trace_redaction/scrub_trace_packet.h
@@ -26,7 +26,7 @@
   virtual ~TracePacketFilter();
 
   // Checks if the context contains all neccessary parameters.
-  virtual base::Status VerifyContext(const Context& context) const = 0;
+  virtual base::Status VerifyContext(const Context& context) const;
 
   // Checks if the field should be pass onto the new packet. Checks are a
   // logical AND, so all filters must return true.
diff --git a/src/trace_redaction/trace_redaction_framework.h b/src/trace_redaction/trace_redaction_framework.h
index f741f9b..cc135a9 100644
--- a/src/trace_redaction/trace_redaction_framework.h
+++ b/src/trace_redaction/trace_redaction_framework.h
@@ -21,9 +21,12 @@
 #include <memory>
 #include <optional>
 #include <string>
+#include <unordered_set>
+#include <vector>
 
 #include "perfetto/base/flat_set.h"
 #include "perfetto/base/status.h"
+#include "src/trace_redaction/frame_cookie.h"
 #include "src/trace_redaction/process_thread_timeline.h"
 
 #include "protos/perfetto/trace/trace_packet.pbzero.h"
@@ -186,6 +189,34 @@
   // After Sort(), Flatten() and Reduce() can be called (optional) to improve
   // the practical look-up times (compared to theoretical look-up times).
   std::unique_ptr<ProcessThreadTimeline> timeline;
+
+  // All frame events:
+  //
+  //  - ActualDisplayFrame
+  //  - ActualSurfaceFrame
+  //  - ExpectedDisplayFrame
+  //  - ExpectedSurfaceFrame
+  //
+  // Connect a time, a pid, and a cookie value. Cookies are unqiue within a
+  // trace, so if a cookie was connected to the target package, it can always be
+  // used.
+  //
+  // End events (i.e. FrameEnd) only have a time and cookie value. The cookie
+  // value connects it to its start time.
+  //
+  // In the collect phase, all start events are collected and converted to a
+  // simpler structure.
+  //
+  // In the build phase, the cookies are filtered to only include the ones that
+  // belong to the target package. This is down in the build phase, and not the
+  // collect phase, because the timeline is needed to determine if the cookie
+  // belongs to the target package.
+  std::vector<FrameCookie> global_frame_cookies;
+
+  // The collect of cookies that belong to the target package. Because cookie
+  // values are unique within the scope of the trace, pid and time are no longer
+  // needed and a set can be used for faster queries.
+  std::unordered_set<int64_t> package_frame_cookies;
 };
 
 // Extracts low-level data from the trace and writes it into the context. The
diff --git a/src/traced/probes/ftrace/event_info.cc b/src/traced/probes/ftrace/event_info.cc
index e11184b..09615fe 100644
--- a/src/traced/probes/ftrace/event_info.cc
+++ b/src/traced/probes/ftrace/event_info.cc
@@ -7597,16 +7597,22 @@
        "panel",
        {
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "type", 1, ProtoSchemaType::kUint32,
+            "pid", 1, ProtoSchemaType::kInt32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "pid", 2, ProtoSchemaType::kInt32,
+            "trace_name", 2, ProtoSchemaType::kString,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "name", 3, ProtoSchemaType::kString,
+            "trace_begin", 3, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "value", 4, ProtoSchemaType::kInt32,
+            "name", 4, ProtoSchemaType::kString,
+            TranslationStrategy::kInvalidTranslationStrategy},
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "type", 5, ProtoSchemaType::kUint32,
+            TranslationStrategy::kInvalidTranslationStrategy},
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "value", 6, ProtoSchemaType::kInt32,
             TranslationStrategy::kInvalidTranslationStrategy},
        },
        kUnsetFtraceId,
@@ -7616,55 +7622,55 @@
        "perf_trace_counters",
        {
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "prev_comm", 1, ProtoSchemaType::kString,
+            "old_pid", 1, ProtoSchemaType::kInt32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "prev_pid", 2, ProtoSchemaType::kInt32,
+            "new_pid", 2, ProtoSchemaType::kInt32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "cyc", 3, ProtoSchemaType::kUint32,
+            "cctr", 3, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "inst", 4, ProtoSchemaType::kUint32,
+            "ctr0", 4, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "stallbm", 5, ProtoSchemaType::kUint32,
+            "ctr1", 5, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "l3dm", 6, ProtoSchemaType::kUint32,
+            "ctr2", 6, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "old_pid", 7, ProtoSchemaType::kInt32,
+            "ctr3", 7, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "new_pid", 8, ProtoSchemaType::kInt32,
+            "lctr0", 8, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "cctr", 9, ProtoSchemaType::kUint32,
+            "lctr1", 9, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr0", 10, ProtoSchemaType::kUint32,
+            "ctr4", 10, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr1", 11, ProtoSchemaType::kUint32,
+            "ctr5", 11, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr2", 12, ProtoSchemaType::kUint32,
+            "prev_comm", 12, ProtoSchemaType::kString,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr3", 13, ProtoSchemaType::kUint32,
+            "prev_pid", 13, ProtoSchemaType::kInt32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "lctr0", 14, ProtoSchemaType::kUint32,
+            "cyc", 14, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "lctr1", 15, ProtoSchemaType::kUint32,
+            "inst", 15, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr4", 16, ProtoSchemaType::kUint32,
+            "stallbm", 16, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
            {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
-            "ctr5", 17, ProtoSchemaType::kUint32,
+            "l3dm", 17, ProtoSchemaType::kUint32,
             TranslationStrategy::kInvalidTranslationStrategy},
        },
        kUnsetFtraceId,
diff --git a/test/cts/heapprofd_test_cts.cc b/test/cts/heapprofd_test_cts.cc
index c4eb97f..99d8c50 100644
--- a/test/cts/heapprofd_test_cts.cc
+++ b/test/cts/heapprofd_test_cts.cc
@@ -88,8 +88,8 @@
     bool multiuser_support = sdk && *sdk >= 34;
     cmd_ = "content read";
     if (multiuser_support) {
-      // This command is available only starting from android U.
-      cmd_ += " --user `cmd user get-main-user`";
+      // This is required only starting from android U.
+      cmd_ += " --user `am get-current-user`";
     }
     cmd_ += std::string(" --uri content://") + app + std::string("/") + path;
     cmd_ += " >" + tempfile_;
diff --git a/test/data/api31_startup_cold.perfetto-trace.sha256 b/test/data/api31_startup_cold.perfetto-trace.sha256
new file mode 100644
index 0000000..98598a7
--- /dev/null
+++ b/test/data/api31_startup_cold.perfetto-trace.sha256
@@ -0,0 +1 @@
+aadf4a141dc0249abd4d7080a7d94bd614949eb0e7398fa6f3c75b503c70dade
\ No newline at end of file
diff --git a/test/data/api31_startup_warm.perfetto-trace.sha256 b/test/data/api31_startup_warm.perfetto-trace.sha256
new file mode 100644
index 0000000..e04f245
--- /dev/null
+++ b/test/data/api31_startup_warm.perfetto-trace.sha256
@@ -0,0 +1 @@
+4655c161656bf0eb66e8bc046ff899813e08bcf73f5e253ca88e8b3be231cb0e
\ No newline at end of file
diff --git a/test/data/api32_startup_warm.perfetto-trace.sha256 b/test/data/api32_startup_warm.perfetto-trace.sha256
deleted file mode 100644
index f83dd34..0000000
--- a/test/data/api32_startup_warm.perfetto-trace.sha256
+++ /dev/null
@@ -1 +0,0 @@
-776122b5660c5d6e738950031fdb4992a64e3224e9e82bbaed474a0a281ed7e3
\ No newline at end of file
diff --git a/test/data/api34_startup_cold.perfetto-trace.sha256 b/test/data/api34_startup_cold.perfetto-trace.sha256
deleted file mode 100644
index 2a7a044..0000000
--- a/test/data/api34_startup_cold.perfetto-trace.sha256
+++ /dev/null
@@ -1 +0,0 @@
-1958521dc5128cd4eadd1df281e19987aded718750e6883f82ffd3b5eb529bd6
\ No newline at end of file
diff --git a/test/data/chrome/scroll_offsets_trace_2.pftrace.sha256 b/test/data/chrome/scroll_offsets_trace_2.pftrace.sha256
new file mode 100644
index 0000000..27d8ace
--- /dev/null
+++ b/test/data/chrome/scroll_offsets_trace_2.pftrace.sha256
@@ -0,0 +1 @@
+2ddd9f78d91d51e39c72c520bb54fdc9dbf1333ae722e87633fc345159296289
\ No newline at end of file
diff --git a/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256 b/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
index 02b1315..4a77c81 100644
--- a/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
+++ b/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
@@ -1 +1 @@
-687a6fc2a478b048bdcbbbfe6231cf3b33463068c8100659a5be0220f41d07fb
\ No newline at end of file
+07bcd60e3622fd39e0270962294696c7280c3cc45997837ae136ea1da0f8d094
\ No newline at end of file
diff --git a/test/data/ui-screenshots/ui-chrome_rendering_desktop_expand_browser_proc.png.sha256 b/test/data/ui-screenshots/ui-chrome_rendering_desktop_expand_browser_proc.png.sha256
index 905ad76..c8cc93d 100644
--- a/test/data/ui-screenshots/ui-chrome_rendering_desktop_expand_browser_proc.png.sha256
+++ b/test/data/ui-screenshots/ui-chrome_rendering_desktop_expand_browser_proc.png.sha256
@@ -1 +1 @@
-c1fa13737c59bf1eeaa997037ca99117625b4d7956496702734317555ff5a2bc
\ No newline at end of file
+193a54d8a03494937a21ecd2210b926a73e43f3d9617d622328e9a45cd32b017
\ No newline at end of file
diff --git a/test/trace_processor/diff_tests/metrics/android/android_boot.out b/test/trace_processor/diff_tests/metrics/android/android_boot.out
index 3bf13cc..50f4757 100644
--- a/test/trace_processor/diff_tests/metrics/android/android_boot.out
+++ b/test/trace_processor/diff_tests/metrics/android/android_boot.out
@@ -1,59 +1,915 @@
 android_boot {
-    system_server_durations {
-        total_dur: 90219646678
-        uninterruptible_sleep_dur: 618417159
-    }
-    systemui_durations {
-        total_dur: 48481027953
-        uninterruptible_sleep_dur: 796263
-    }
-    launcher_durations {
-        total_dur: 23595248987
-        uninterruptible_sleep_dur: 257290255
-    }
-    gms_durations {
-        total_dur: 27804143410
-        uninterruptible_sleep_dur: 101685087
-    }
-    launcher_breakdown {
-        cold_start_dur: 403543498
-    }
-    full_trace_process_start_aggregation {
-        total_start_sum: 10678297679
-        num_of_processes: 29
-        average_start_time: 368217161.3448276
-    }
-    post_boot_process_start_aggregation {
-        total_start_sum: 6112984648
-        num_of_processes: 21
-        average_start_time: 291094507.04761904
-    }
-    full_trace_gc_aggregation {
-        total_gc_count: 4
-        num_of_processes_with_gc: 4
-        num_of_threads_with_gc: 4
-        avg_gc_duration: 260516077.75
-        avg_running_gc_duration: 3902628.5
-        full_gc_count: 4
-        collector_transition_gc_count: 0
-        young_gc_count: 0
-        native_alloc_gc_count: 0
-        explicit_gc_count: 0
-        alloc_gc_count: 0
-        mb_per_ms_of_gc: 0.8829305684617432
-    }
-    post_boot_gc_aggregation {
-        total_gc_count: 4
-        num_of_processes_with_gc: 4
-        num_of_threads_with_gc: 4
-        avg_gc_duration: 260516077.75
-        avg_running_gc_duration: 3902628.5
-        full_gc_count: 4
-        collector_transition_gc_count: 0
-        young_gc_count: 0
-        native_alloc_gc_count: 0
-        explicit_gc_count: 0
-        alloc_gc_count: 0
-        mb_per_ms_of_gc: 0.8829305684617432
-    }
-}
\ No newline at end of file
+system_server_durations {
+total_dur: 90219646678
+uninterruptible_sleep_dur: 618417159
+}
+systemui_durations {
+total_dur: 48481027953
+uninterruptible_sleep_dur: 796263
+}
+launcher_durations {
+total_dur: 23595248987
+uninterruptible_sleep_dur: 257290255
+}
+gms_durations {
+total_dur: 27804143410
+uninterruptible_sleep_dur: 101685087
+}
+launcher_breakdown {
+cold_start_dur: 403543498
+}
+full_trace_process_start_aggregation {
+total_start_sum: 10678297679
+num_of_processes: 29
+average_start_time: 368217161.3448276
+}
+post_boot_process_start_aggregation {
+total_start_sum: 6112984648
+num_of_processes: 21
+average_start_time: 291094507.04761904
+}
+full_trace_gc_aggregation {
+total_gc_count: 4
+num_of_processes_with_gc: 4
+num_of_threads_with_gc: 4
+avg_gc_duration: 260516077.75
+avg_running_gc_duration: 3902628.5
+full_gc_count: 4
+collector_transition_gc_count: 0
+young_gc_count: 0
+native_alloc_gc_count: 0
+explicit_gc_count: 0
+alloc_gc_count: 0
+mb_per_ms_of_gc: 0.8829305684617432
+}
+post_boot_gc_aggregation {
+total_gc_count: 4
+num_of_processes_with_gc: 4
+num_of_threads_with_gc: 4
+avg_gc_duration: 260516077.75
+avg_running_gc_duration: 3902628.5
+full_gc_count: 4
+collector_transition_gc_count: 0
+young_gc_count: 0
+native_alloc_gc_count: 0
+explicit_gc_count: 0
+alloc_gc_count: 0
+mb_per_ms_of_gc: 0.8829305684617432
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 16
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_global {
+dest_bucket: "foreground_app"
+count: 21
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 4
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_global {
+dest_bucket: "native"
+count: 4
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 4
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "/system/bin/apexd"
+dest_bucket: "native"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "<pre-initialized>"
+dest_bucket: "native"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "android.process.acore"
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.amazon.mp3"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.android.keychain"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.android.printspooler"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.android.providers.calendar"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.android.settings"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.apple.android.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.blinkslabs.blinkist.android"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.books"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging"
+dest_bucket: "native"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging:rcs"
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging:rcs"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.nexuslauncher"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wallpaper"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wellbeing"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 5
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wellbeing"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.work.clouddpc"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.youtube.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.calendar"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.carrier"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.cellbroadcastreceiver"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.deskclock"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.dialer"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 4
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.googlequicksearchbox:search"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.keep"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.permissioncontroller"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.providers.media.module"
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.android.youtube"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.ar.core"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.ar.core"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.google.euiccpixel"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.overdrive.mobile.android.libby"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.patreon.android"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "com.spotify.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "org.thoughtcrime.securesms"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_process {
+name: "org.videolan.vlc"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "bindService"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 5
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startReceiver"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 7
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "processBegin"
+dest_bucket: "foreground_app"
+count: 21
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startReceiver"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "unbindService"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "bindService"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+dest_bucket: "native"
+count: 4
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 3
+}
+post_boot_oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "finishReceiver"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "cached_app"
+total_dur: 10419196404
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "foreground_app"
+total_dur: 23641055480
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "native"
+total_dur: 101590616
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "perceptible_app"
+total_dur: 940071238
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "perceptible_low_app"
+total_dur: 199288116
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "persistent_service"
+total_dur: 1546461864
+}
+post_boot_oom_adj_bucket_duration_agg_global {
+bucket: "visible_app"
+total_dur: 2769744731
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/apexd"
+bucket: "native"
+total_dur: 25397654
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "<pre-initialized>"
+bucket: "native"
+total_dur: 50795308
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "android.process.acore"
+bucket: "foreground_app"
+total_dur: 823432282
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.amazon.mp3"
+bucket: "foreground_app"
+total_dur: 1322230378
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.android.keychain"
+bucket: "foreground_app"
+total_dur: 196867340
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.android.printspooler"
+bucket: "foreground_app"
+total_dur: 343904124
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.android.providers.calendar"
+bucket: "foreground_app"
+total_dur: 281386139
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.android.settings"
+bucket: "cached_app"
+total_dur: 967052521
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.apple.android.music"
+bucket: "foreground_app"
+total_dur: 1268519522
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.blinkslabs.blinkist.android"
+bucket: "foreground_app"
+total_dur: 1250421540
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.books"
+bucket: "foreground_app"
+total_dur: 1076963328
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "cached_app"
+total_dur: 1086183503
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "foreground_app"
+total_dur: 402609904
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "perceptible_low_app"
+total_dur: 7658935
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging"
+bucket: "native"
+total_dur: 25397654
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging:rcs"
+bucket: "foreground_app"
+total_dur: 109047811
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging:rcs"
+bucket: "perceptible_app"
+total_dur: 940071238
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.nexuslauncher"
+bucket: "foreground_app"
+total_dur: 1661132477
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wallpaper"
+bucket: "foreground_app"
+total_dur: 177919993
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wellbeing"
+bucket: "cached_app"
+total_dur: 816703328
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wellbeing"
+bucket: "foreground_app"
+total_dur: 884970246
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.work.clouddpc"
+bucket: "cached_app"
+total_dur: 1695452790
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.youtube.music"
+bucket: "foreground_app"
+total_dur: 1558635529
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "cached_app"
+total_dur: 621111806
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "foreground_app"
+total_dur: 303909018
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "perceptible_low_app"
+total_dur: 9431030
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.calendar"
+bucket: "foreground_app"
+total_dur: 1573637523
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.carrier"
+bucket: "cached_app"
+total_dur: 870239329
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.cellbroadcastreceiver"
+bucket: "cached_app"
+total_dur: 870311514
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.deskclock"
+bucket: "foreground_app"
+total_dur: 1674669994
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "cached_app"
+total_dur: 11603068
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "foreground_app"
+total_dur: 115664632
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "visible_app"
+total_dur: 1568444611
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.dialer"
+bucket: "cached_app"
+total_dur: 1701572215
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "cached_app"
+total_dur: 38437012
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "foreground_app"
+total_dur: 1259805736
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "visible_app"
+total_dur: 397030029
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+bucket: "visible_app"
+total_dur: 804270091
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.googlequicksearchbox:search"
+bucket: "foreground_app"
+total_dur: 1467442984
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.keep"
+bucket: "foreground_app"
+total_dur: 576153188
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.permissioncontroller"
+bucket: "cached_app"
+total_dur: 870388947
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.providers.media.module"
+bucket: "persistent_service"
+total_dur: 1546461864
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.youtube"
+bucket: "foreground_app"
+total_dur: 1450400991
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.ar.core"
+bucket: "foreground_app"
+total_dur: 733794515
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.ar.core"
+bucket: "perceptible_low_app"
+total_dur: 182198151
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.google.euiccpixel"
+bucket: "cached_app"
+total_dur: 870140371
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.overdrive.mobile.android.libby"
+bucket: "foreground_app"
+total_dur: 889039012
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.patreon.android"
+bucket: "foreground_app"
+total_dur: 608530141
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "com.spotify.music"
+bucket: "foreground_app"
+total_dur: 566682160
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "org.thoughtcrime.securesms"
+bucket: "foreground_app"
+total_dur: 701758738
+}
+post_boot_oom_adj_bucket_duration_agg_by_process {
+name: "org.videolan.vlc"
+bucket: "foreground_app"
+total_dur: 361526235
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 266887
+max_oom_adj_dur: 7292196
+avg_oom_adj_dur: 6121311.166666667
+oom_adj_event_count: 2
+oom_adj_reason: "activityChange"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 67180
+max_oom_adj_dur: 225871
+avg_oom_adj_dur: 160115.83333333334
+oom_adj_event_count: 5
+oom_adj_reason: "bindService"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 64657
+max_oom_adj_dur: 565674
+avg_oom_adj_dur: 232660.2142857143
+oom_adj_event_count: 11
+oom_adj_reason: "executingService"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 198120
+max_oom_adj_dur: 198120
+avg_oom_adj_dur: 198120.0
+oom_adj_event_count: 1
+oom_adj_reason: "finishReceiver"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 193766
+max_oom_adj_dur: 626302
+avg_oom_adj_dur: 383901.0
+oom_adj_event_count: 4
+oom_adj_reason: "getProvider"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 92366
+max_oom_adj_dur: 1461914
+avg_oom_adj_dur: 257078.14285714287
+oom_adj_event_count: 21
+oom_adj_reason: "processBegin"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 238525
+max_oom_adj_dur: 5160522
+avg_oom_adj_dur: 883870.1111111111
+oom_adj_event_count: 4
+oom_adj_reason: "startReceiver"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 68645
+max_oom_adj_dur: 2294270
+avg_oom_adj_dur: 747080.5
+oom_adj_event_count: 4
+oom_adj_reason: "startService"
+}
+post_boot_oom_adj_duration_agg {
+min_oom_adj_dur: 165242
+max_oom_adj_dur: 380290
+avg_oom_adj_dur: 272766.0
+oom_adj_event_count: 2
+oom_adj_reason: "unbindService"
+}
+}
diff --git a/test/trace_processor/diff_tests/metrics/android/android_oom_adjuster.out b/test/trace_processor/diff_tests/metrics/android/android_oom_adjuster.out
new file mode 100644
index 0000000..e7135d0
--- /dev/null
+++ b/test/trace_processor/diff_tests/metrics/android/android_oom_adjuster.out
@@ -0,0 +1,2745 @@
+android_oom_adjuster {
+oom_adjuster_transition_counts_global {
+dest_bucket: "cached_app"
+count: 7
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 27
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 5
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 3
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "cached_app"
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "previous_app"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "foreground_app"
+count: 27
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 4
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 4
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "logcat"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "native"
+count: 121
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 3
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "persistent_proc"
+count: 17
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "persistent_service"
+count: 2
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "previous_app"
+count: 5
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "service"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "system"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "unknown_native"
+count: 1
+}
+oom_adjuster_transition_counts_global {
+dest_bucket: "visible_app"
+count: 6
+}
+oom_adjuster_transition_counts_global {
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 4
+}
+oom_adjuster_transition_counts_by_process {
+name: ".ShannonImsService"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.android.adbd/bin/adbd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.android.hardware.cas/bin/hw/android.hardware.cas-service.example"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.android.os.statsd/bin/statsd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.google.android.hardware.biometrics.face/bin/hw/android.hardware.biometrics.face-service.22.pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.google.android.widevine/bin/hw/android.hardware.drm-service.widevine"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.google.pixel.camera.hal/bin/hw/android.hardware.camera.provider@2.7-service-google"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.google.pixel.camera.hal/bin/rlsservice"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/apex/com.google.pixel.wifi.ext/bin/hw/vendor.google.wifi_ext-service-vendor"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/apexd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/audioserver"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/cameraserver"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/credstore"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/drmserver"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/gatekeeperd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/gpuservice"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/hw/android.system.suspend-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/incidentd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/init"
+dest_bucket: "native"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/installd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/ip6tables-restore"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/iptables-restore"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/keystore2"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/lmkd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/logd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/mediaserver"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/netd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/prng_seeder"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/servicemanager"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/storaged"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/surfaceflinger"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/tombstoned"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/traced"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/traced_probes"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/ueventd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/update_engine"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/virtual_camera"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/vold"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/bin/wificond"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/system_ext/bin/hw/android.hidl.allocator@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/system_ext/bin/hwservicemanager"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system/vendor/bin/wfc-pkt-router"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system_ext/bin/gs_watchdogd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/system_ext/bin/hw/vendor.google.edgetpu_app_service@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/aocd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/bipchmgr"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/cbd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/chre"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/dmd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.audio.service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.authsecret-service.citadel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.biometrics.fingerprint-service.goodix"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.bluetooth-service.bcmbtlinux"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.boot-service.default-pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.cas@1.2-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.composer.hwc3-service.pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.confirmationui-service.trusty.vendor"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.contexthub-service.generic"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.drm-service.clearkey"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.dumpstate-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.edgetpu.logging@service-edgetpu-logging"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.gatekeeper-service.trusty"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.gnss@2.1-service-brcm"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.graphics.allocator-V2-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.gxp.logging@service-gxp-logging"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.health-service.gs201"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.identity@1.0-service.citadel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.input.processor-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.memtrack-service.pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.neuralnetworks@service-darwinn-aidl"
+dest_bucket: "native"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.nfc-service.st"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.oemlock-service.citadel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.power-service.pixel-libperfmgr"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.power.stats-service.pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-service-gto"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-service-gto-ese2"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-uicc-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.security.keymint-service.citadel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.security.keymint-service.trusty"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.sensors-service.multihal"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.thermal-service.pixel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.usb-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.usb.gadget-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.vibrator-service.cs40l26"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/android.hardware.weaver-service.citadel"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/battery_mitigation"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/citadeld"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/google.hardware.media.c2@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/gpsd"
+dest_bucket: "unknown_native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/lhd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/rild_exynos"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/samsung.hardware.media.c2@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/scd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/vendor.dolby.media.c2@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/vendor.google.audiometricext@1.0-service-vendor"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/vendor.google.google_battery-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/vendor.google.radioext@1.0-service"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/vendor.google.wireless_charger-default"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/hw/wpa_supplicant"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/modem_svc_sit"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/pixelstats-vendor"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/ramdump"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/rfsd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/sced"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/securedpud.slider"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/sscoredump"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/storageproxyd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/trusty_metricsd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/twoshay"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/vcd"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "/vendor/bin/vndservicemanager"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "<pre-initialized>"
+dest_bucket: "native"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "android.process.acore"
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "android.process.acore"
+dest_bucket: "previous_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.amazon.mp3"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.hbmsvmanager"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.keychain"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.networkstack.process"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.nfc"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.phone"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.pixellogger"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.printspooler"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.providers.calendar"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.qns"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.se"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.settings"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.settings"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.android.systemui"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.apple.android.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.blinkslabs.blinkist.android"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.SSRestartDetector"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.books"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.cbrsnetworkmonitor"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.dreamliner"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging:rcs"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging:rcs"
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.messaging:rcs"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.nexuslauncher"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.nexuslauncher"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.scone"
+dest_bucket: "service"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wallpaper"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wellbeing"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wellbeing"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 8
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.wellbeing"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.work.clouddpc"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.work.clouddpc"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.work.clouddpc"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.work.clouddpc"
+src_bucket: "cached_app"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.apps.youtube.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.as.oss"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.bluetooth"
+dest_bucket: "persistent_service"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.calendar"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.carrier"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.carrier"
+dest_bucket: "previous_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.cellbroadcastreceiver"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.cellbroadcastreceiver"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 3
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.connectivitythermalpowermanager"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.deskclock"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.deskclock"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.deskclock"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.deskclock"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.devicelockcontroller"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.dialer"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.dialer"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 7
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.euicc"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.ext.services"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.flipendo"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.flipendo"
+src_bucket: "previous_app"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.flipendo"
+dest_bucket: "previous_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 5
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms.persistent"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.gms.persistent"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.googlequicksearchbox:search"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.grilservice"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.ims"
+dest_bucket: "persistent_service"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.iwlan"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.keep"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.permissioncontroller"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.permissioncontroller"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.pixelsystemservice"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.providers.media.module"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.providers.media.module"
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.repairmode"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.repairmode"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.repairmode"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.android.youtube"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.ar.core"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.ar.core"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.euiccpixel"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.euiccpixel"
+dest_bucket: "previous_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.google.pixel.camera.services"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.overdrive.mobile.android.libby"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.patreon.android"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.samsung.slsi.telephony.oem.oemrilhookservice"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.samsung.slsi.telephony.oemril"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.shannon.imsservice"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.shannon.rcsservice"
+dest_bucket: "persistent_proc"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.shannon.rcsservice:shannonrcsservice"
+dest_bucket: "previous_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "com.spotify.music"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "logcat"
+dest_bucket: "logcat"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "logcat"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "media.extractor"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "media.metrics"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "media.swcodec"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "org.thoughtcrime.securesms"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "org.videolan.vlc"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "perfetto"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "system_server"
+dest_bucket: "system"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "webview_zygote"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_process {
+name: "zygote64"
+dest_bucket: "native"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "cached_app"
+count: 7
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 8
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "bindService"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 8
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startReceiver"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 7
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "uiVisibility"
+src_bucket: "cached_app"
+dest_bucket: "cached_app"
+count: 3
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "uiVisibility"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app"
+count: 5
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "cached_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "previous_app"
+dest_bucket: "cached_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "cached_app"
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "cached_app_lmk_first"
+dest_bucket: "cached_app_lmk_first"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+src_bucket: "previous_app"
+dest_bucket: "cached_app_lmk_first"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "foreground_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "activityChange"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "processBegin"
+dest_bucket: "foreground_app"
+count: 24
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startReceiver"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "cached_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "perceptible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "unbindService"
+src_bucket: "perceptible_low_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "previous_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "bindService"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "getProvider"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "visible_app"
+dest_bucket: "foreground_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "logcat"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "native"
+count: 117
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+dest_bucket: "native"
+count: 4
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_app"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "perceptible_low_app"
+count: 3
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "persistent_proc"
+count: 13
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "processBegin"
+dest_bucket: "persistent_proc"
+count: 4
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "persistent_service"
+count: 2
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "startService"
+src_bucket: "foreground_app"
+dest_bucket: "persistent_service"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "previous_app"
+count: 5
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "service"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "system"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "unknown_native"
+count: 1
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+dest_bucket: "visible_app"
+count: 6
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "executingService"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 3
+}
+oom_adjuster_transition_counts_by_oom_adj_reason {
+name: "finishReceiver"
+src_bucket: "foreground_app"
+dest_bucket: "visible_app"
+count: 1
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "cached_app"
+total_dur: 20351484924
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "cached_app_lmk_first"
+total_dur: 544761924
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "foreground_app"
+total_dur: 33803455234
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "logcat"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "native"
+total_dur: 263503709570
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "perceptible_app"
+total_dur: 940071238
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "perceptible_low_app"
+total_dur: 199288116
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "persistent_proc"
+total_dur: 36752485443
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "persistent_service"
+total_dur: 6049062188
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "previous_app"
+total_dur: 6572285720
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "service"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "system"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "unknown_native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_global {
+bucket: "visible_app"
+total_dur: 12579222928
+}
+oom_adj_bucket_duration_agg_by_process {
+name: ".ShannonImsService"
+bucket: "foreground_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.android.adbd/bin/adbd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.android.hardware.cas/bin/hw/android.hardware.cas-service.example"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.android.os.statsd/bin/statsd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.google.android.hardware.biometrics.face/bin/hw/android.hardware.biometrics.face-service.22.pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.google.android.widevine/bin/hw/android.hardware.drm-service.widevine"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.google.pixel.camera.hal/bin/hw/android.hardware.camera.provider@2.7-service-google"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.google.pixel.camera.hal/bin/rlsservice"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/apex/com.google.pixel.wifi.ext/bin/hw/vendor.google.wifi_ext-service-vendor"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/apexd"
+bucket: "native"
+total_dur: 25397654
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/audioserver"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/cameraserver"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/credstore"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/drmserver"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/gatekeeperd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/gpuservice"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/hw/android.system.suspend-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/incidentd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/init"
+bucket: "native"
+total_dur: 4502600324
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/installd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/ip6tables-restore"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/iptables-restore"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/keystore2"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/lmkd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/logd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/mediaserver"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/netd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/prng_seeder"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/servicemanager"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/storaged"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/surfaceflinger"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/tombstoned"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/traced"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/traced_probes"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/ueventd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/update_engine"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/virtual_camera"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/vold"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/bin/wificond"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/system_ext/bin/hw/android.hidl.allocator@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/system_ext/bin/hwservicemanager"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system/vendor/bin/wfc-pkt-router"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system_ext/bin/gs_watchdogd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/system_ext/bin/hw/vendor.google.edgetpu_app_service@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/aocd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/bipchmgr"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/cbd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/chre"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/dmd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.audio.service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.authsecret-service.citadel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.biometrics.fingerprint-service.goodix"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.bluetooth-service.bcmbtlinux"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.boot-service.default-pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.cas@1.2-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.composer.hwc3-service.pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.confirmationui-service.trusty.vendor"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.contexthub-service.generic"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.drm-service.clearkey"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.dumpstate-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.edgetpu.logging@service-edgetpu-logging"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.gatekeeper-service.trusty"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.gnss@2.1-service-brcm"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.graphics.allocator-V2-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.gxp.logging@service-gxp-logging"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.health-service.gs201"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.identity@1.0-service.citadel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.input.processor-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.memtrack-service.pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.neuralnetworks@service-darwinn-aidl"
+bucket: "native"
+total_dur: 4502600324
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.nfc-service.st"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.oemlock-service.citadel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.power-service.pixel-libperfmgr"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.power.stats-service.pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-service-gto"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-service-gto-ese2"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.secure_element@1.2-uicc-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.security.keymint-service.citadel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.security.keymint-service.trusty"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.sensors-service.multihal"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.thermal-service.pixel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.usb-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.usb.gadget-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.vibrator-service.cs40l26"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/android.hardware.weaver-service.citadel"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/battery_mitigation"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/citadeld"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/google.hardware.media.c2@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/gpsd"
+bucket: "unknown_native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/lhd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/rild_exynos"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/samsung.hardware.media.c2@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/scd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/vendor.dolby.media.c2@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/vendor.google.audiometricext@1.0-service-vendor"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/vendor.google.google_battery-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/vendor.google.radioext@1.0-service"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/vendor.google.wireless_charger-default"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/hw/wpa_supplicant"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/modem_svc_sit"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/pixelstats-vendor"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/ramdump"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/rfsd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/sced"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/securedpud.slider"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/sscoredump"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/storageproxyd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/trusty_metricsd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/twoshay"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/vcd"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "/vendor/bin/vndservicemanager"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "<pre-initialized>"
+bucket: "native"
+total_dur: 50795308
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "android.process.acore"
+bucket: "foreground_app"
+total_dur: 823432282
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "android.process.acore"
+bucket: "previous_app"
+total_dur: 1427867880
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.amazon.mp3"
+bucket: "foreground_app"
+total_dur: 1322230378
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.hbmsvmanager"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.keychain"
+bucket: "foreground_app"
+total_dur: 196867340
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.networkstack.process"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.nfc"
+bucket: "persistent_proc"
+total_dur: 1883581900
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.phone"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.pixellogger"
+bucket: "persistent_proc"
+total_dur: 1852027416
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.printspooler"
+bucket: "foreground_app"
+total_dur: 343904124
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.providers.calendar"
+bucket: "foreground_app"
+total_dur: 281386139
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.qns"
+bucket: "visible_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.se"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.settings"
+bucket: "cached_app"
+total_dur: 967052521
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.settings"
+bucket: "foreground_app"
+total_dur: 1284247641
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.android.systemui"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.apple.android.music"
+bucket: "foreground_app"
+total_dur: 1268519522
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.blinkslabs.blinkist.android"
+bucket: "foreground_app"
+total_dur: 1250421540
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.SSRestartDetector"
+bucket: "persistent_proc"
+total_dur: 1885479849
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.books"
+bucket: "foreground_app"
+total_dur: 1076963328
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.cbrsnetworkmonitor"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "cached_app"
+total_dur: 1086183503
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "foreground_app"
+total_dur: 402609904
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.dreamliner"
+bucket: "perceptible_low_app"
+total_dur: 7658935
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging"
+bucket: "native"
+total_dur: 25397654
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging:rcs"
+bucket: "foreground_app"
+total_dur: 991455486
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.messaging:rcs"
+bucket: "perceptible_app"
+total_dur: 940071238
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.nexuslauncher"
+bucket: "foreground_app"
+total_dur: 1661132477
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.nexuslauncher"
+bucket: "visible_app"
+total_dur: 590167685
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.scone"
+bucket: "service"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wallpaper"
+bucket: "foreground_app"
+total_dur: 177919993
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wellbeing"
+bucket: "cached_app"
+total_dur: 1366329916
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.wellbeing"
+bucket: "foreground_app"
+total_dur: 884970246
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.work.clouddpc"
+bucket: "cached_app"
+total_dur: 2194632641
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.work.clouddpc"
+bucket: "cached_app_lmk_first"
+total_dur: 56667521
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.apps.youtube.music"
+bucket: "foreground_app"
+total_dur: 1558635529
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as"
+bucket: "foreground_app"
+total_dur: 2003700552
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "cached_app"
+total_dur: 621111806
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "foreground_app"
+total_dur: 303909018
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.as.oss"
+bucket: "perceptible_low_app"
+total_dur: 9431030
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.bluetooth"
+bucket: "persistent_service"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.calendar"
+bucket: "foreground_app"
+total_dur: 1573637523
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.carrier"
+bucket: "cached_app"
+total_dur: 870239329
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.carrier"
+bucket: "previous_app"
+total_dur: 1381060833
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.cellbroadcastreceiver"
+bucket: "cached_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.connectivitythermalpowermanager"
+bucket: "persistent_proc"
+total_dur: 1864494172
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.deskclock"
+bucket: "cached_app"
+total_dur: 389354777
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.deskclock"
+bucket: "cached_app_lmk_first"
+total_dur: 187275391
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.deskclock"
+bucket: "foreground_app"
+total_dur: 1674669994
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "cached_app"
+total_dur: 510497641
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "cached_app_lmk_first"
+total_dur: 56693278
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "foreground_app"
+total_dur: 115664632
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.devicelockcontroller"
+bucket: "visible_app"
+total_dur: 1568444611
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.dialer"
+bucket: "cached_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.euicc"
+bucket: "visible_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.ext.services"
+bucket: "visible_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.flipendo"
+bucket: "cached_app"
+total_dur: 2063730581
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.flipendo"
+bucket: "cached_app_lmk_first"
+total_dur: 56672527
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.flipendo"
+bucket: "previous_app"
+total_dur: 130897054
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "cached_app"
+total_dur: 594464397
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "foreground_app"
+total_dur: 1259805736
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms"
+bucket: "visible_app"
+total_dur: 397030029
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms.persistent"
+bucket: "foreground_app"
+total_dur: 2037190298
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.gms.persistent"
+bucket: "visible_app"
+total_dur: 214109864
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+bucket: "foreground_app"
+total_dur: 1185413249
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.googlequicksearchbox:interactor"
+bucket: "visible_app"
+total_dur: 804270091
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.googlequicksearchbox:search"
+bucket: "foreground_app"
+total_dur: 1467442984
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.grilservice"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.ims"
+bucket: "persistent_service"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.iwlan"
+bucket: "visible_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.keep"
+bucket: "foreground_app"
+total_dur: 576153188
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.permissioncontroller"
+bucket: "cached_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.pixelsystemservice"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.providers.media.module"
+bucket: "foreground_app"
+total_dur: 518140177
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.providers.media.module"
+bucket: "persistent_service"
+total_dur: 1546461864
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.repairmode"
+bucket: "cached_app"
+total_dur: 2063846955
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.repairmode"
+bucket: "cached_app_lmk_first"
+total_dur: 187453207
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.android.youtube"
+bucket: "foreground_app"
+total_dur: 1450400991
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.ar.core"
+bucket: "foreground_app"
+total_dur: 733794515
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.ar.core"
+bucket: "perceptible_low_app"
+total_dur: 182198151
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.euiccpixel"
+bucket: "cached_app"
+total_dur: 870140371
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.euiccpixel"
+bucket: "previous_app"
+total_dur: 1381159791
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.google.pixel.camera.services"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.overdrive.mobile.android.libby"
+bucket: "foreground_app"
+total_dur: 889039012
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.patreon.android"
+bucket: "foreground_app"
+total_dur: 608530141
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.samsung.slsi.telephony.oem.oemrilhookservice"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.samsung.slsi.telephony.oemril"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.shannon.imsservice"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.shannon.rcsservice"
+bucket: "persistent_proc"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.shannon.rcsservice:shannonrcsservice"
+bucket: "previous_app"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "com.spotify.music"
+bucket: "foreground_app"
+total_dur: 566682160
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "logcat"
+bucket: "logcat"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "logcat"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "media.extractor"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "media.metrics"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "media.swcodec"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "org.thoughtcrime.securesms"
+bucket: "foreground_app"
+total_dur: 701758738
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "org.videolan.vlc"
+bucket: "foreground_app"
+total_dur: 361526235
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "perfetto"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "system_server"
+bucket: "system"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "webview_zygote"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_bucket_duration_agg_by_process {
+name: "zygote64"
+bucket: "native"
+total_dur: 2251300162
+}
+oom_adj_duration_agg {
+oom_adj_event_count: 0
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 263550
+max_oom_adj_dur: 7292196
+avg_oom_adj_dur: 3888985.6470588236
+oom_adj_event_count: 4
+oom_adj_reason: "activityChange"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 67180
+max_oom_adj_dur: 225871
+avg_oom_adj_dur: 171359.88888888888
+oom_adj_event_count: 6
+oom_adj_reason: "bindService"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 64657
+max_oom_adj_dur: 565674
+avg_oom_adj_dur: 232660.2142857143
+oom_adj_event_count: 11
+oom_adj_reason: "executingService"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 198120
+max_oom_adj_dur: 198120
+avg_oom_adj_dur: 198120.0
+oom_adj_event_count: 1
+oom_adj_reason: "finishReceiver"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 193766
+max_oom_adj_dur: 626302
+avg_oom_adj_dur: 383901.0
+oom_adj_event_count: 4
+oom_adj_reason: "getProvider"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 92366
+max_oom_adj_dur: 1461914
+avg_oom_adj_dur: 330079.5714285714
+oom_adj_event_count: 28
+oom_adj_reason: "processBegin"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 238525
+max_oom_adj_dur: 5160522
+avg_oom_adj_dur: 883870.1111111111
+oom_adj_event_count: 4
+oom_adj_reason: "startReceiver"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 68645
+max_oom_adj_dur: 2294270
+avg_oom_adj_dur: 618880.2
+oom_adj_event_count: 5
+oom_adj_reason: "startService"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 10092
+max_oom_adj_dur: 10092
+avg_oom_adj_dur: 10092.0
+oom_adj_event_count: 1
+oom_adj_reason: "uiVisibility"
+}
+oom_adj_duration_agg {
+min_oom_adj_dur: 165242
+max_oom_adj_dur: 380290
+avg_oom_adj_dur: 272766.0
+oom_adj_event_count: 2
+oom_adj_reason: "unbindService"
+}
+}
diff --git a/test/trace_processor/diff_tests/metrics/android/tests.py b/test/trace_processor/diff_tests/metrics/android/tests.py
index 06cbe59..da5559e 100644
--- a/test/trace_processor/diff_tests/metrics/android/tests.py
+++ b/test/trace_processor/diff_tests/metrics/android/tests.py
@@ -303,3 +303,9 @@
          }
        }
        """))
+  def test_android_oom_adjuster(self):
+    return DiffTestBlueprint(
+      trace=DataPath('android_postboot_unlock.pftrace'),
+      query=Metric("android_oom_adjuster"),
+      out=Path('android_oom_adjuster.out')
+    )
diff --git a/test/trace_processor/diff_tests/parser/android/protolog_packet_loss.textproto b/test/trace_processor/diff_tests/parser/android/protolog_packet_loss.textproto
new file mode 100644
index 0000000..ab6fda5
--- /dev/null
+++ b/test/trace_processor/diff_tests/parser/android/protolog_packet_loss.textproto
@@ -0,0 +1,118 @@
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  sequence_flags: 1
+  previous_packet_dropped: true
+  trusted_pid: 1716
+  first_packet_on_sequence: true
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  interned_data {
+    protolog_string_args {
+      iid: 1
+      str: "MyTestString"
+    }
+  }
+  trusted_pid: 1716
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  interned_data {
+    protolog_string_args {
+      iid: 2
+      str: "MyOtherTestString"
+    }
+  }
+  trusted_pid: 1716
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  sequence_flags: 2
+  trusted_pid: 1716
+  timestamp: 857384130
+  protolog_message {
+    message_id: 6924537961316301726
+    str_param_iids: 1
+    str_param_iids: 1
+  }
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  sequence_flags: 2
+  trusted_pid: 1716
+  timestamp: 857384130
+  protolog_message {
+    message_id: 6924537961316301726
+    str_param_iids: 1
+    str_param_iids: 2
+  }
+  previous_packet_dropped: true
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 3
+  sequence_flags: 2
+  trusted_pid: 1716
+  timestamp: 857384130
+  protolog_message {
+    message_id: 6924537961316301726
+    str_param_iids: 2
+    str_param_iids: 2
+  }
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 4
+  sequence_flags: 1
+  previous_packet_dropped: true
+  trusted_pid: 1716
+  first_packet_on_sequence: true
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 4
+  interned_data {
+    protolog_string_args {
+      iid: 1
+      str: "MyNextTestString"
+    }
+  }
+  trusted_pid: 1716
+}
+packet {
+  trusted_uid: 1000
+  trusted_packet_sequence_id: 4
+  sequence_flags: 2
+  trusted_pid: 1716
+  timestamp: 857384130
+  protolog_message {
+    message_id: 6924537961316301726
+    str_param_iids: 1
+    str_param_iids: 1
+  }
+}
+packet {
+  trusted_uid: 10224
+  trusted_packet_sequence_id: 10
+  previous_packet_dropped: true
+  trusted_pid: 2063
+  first_packet_on_sequence: true
+  protolog_viewer_config {
+    messages {
+      message_id: 6924537961316301726
+      message: "Test message with two strings: %s and %s"
+      level: PROTOLOG_LEVEL_DEBUG
+      group_id: 1
+    }
+    groups {
+      id: 1
+      name: "MY_FIRST_GROUP"
+      tag: "MyFirstGroup"
+    }
+  }
+}
\ No newline at end of file
diff --git a/test/trace_processor/diff_tests/parser/android/tests_protolog.py b/test/trace_processor/diff_tests/parser/android/tests_protolog.py
index 404f34e..358fe51 100644
--- a/test/trace_processor/diff_tests/parser/android/tests_protolog.py
+++ b/test/trace_processor/diff_tests/parser/android/tests_protolog.py
@@ -31,3 +31,13 @@
         1,857384110,"WARN","MySecondGroup","Test message with different int formats: 1776, 0o3360, 0x6f0, 888.000000, 8.880000e+02.","[NULL]"
         2,857384130,"ERROR","MyThirdGroup","Message re-using interned string 'MyOtherTestString' == 'MyOtherTestString', but 'SomeOtherTestString' != 'MyOtherTestString'","[NULL]"
         """))
+
+  def test_handles_packet_loss(self):
+    return DiffTestBlueprint(
+        trace=Path('protolog_packet_loss.textproto'),
+        query="SELECT id, ts, level, tag, message, stacktrace FROM protolog;",
+        out=Csv("""
+        "id","ts","level","tag","message","stacktrace"
+        0,857384130,"DEBUG","MyFirstGroup","Test message with two strings: MyTestString and MyTestString","[NULL]"
+        1,857384130,"DEBUG","MyFirstGroup","Test message with two strings: MyNextTestString and MyNextTestString","[NULL]"
+        """))
diff --git a/test/trace_processor/diff_tests/stdlib/android/frames_tests.py b/test/trace_processor/diff_tests/stdlib/android/frames_tests.py
index eb6e6d0..83297fd 100644
--- a/test/trace_processor/diff_tests/stdlib/android/frames_tests.py
+++ b/test/trace_processor/diff_tests/stdlib/android/frames_tests.py
@@ -30,22 +30,22 @@
         SELECT * FROM android_frames_choreographer_do_frame;
         """,
         out=Csv("""
-        "id","frame_id","ui_thread_utid"
-        2,10,2
-        15,20,2
-        22,30,2
-        35,40,2
-        46,60,2
-        55,90,2
-        63,100,2
-        73,110,2
-        79,120,2
-        87,130,2
-        93,140,2
-        99,145,2
-        102,150,2
-        108,160,2
-        140,1000,2
+        "id","frame_id","ui_thread_utid","upid"
+        2,10,2,2
+        15,20,2,2
+        22,30,2,2
+        35,40,2,2
+        46,60,2,2
+        55,90,2,2
+        63,100,2,2
+        73,110,2,2
+        79,120,2,2
+        87,130,2,2
+        93,140,2,2
+        99,145,2,2
+        102,150,2,2
+        108,160,2,2
+        140,1000,2,2
         """))
 
   def test_android_frames_draw_frame(self):
@@ -57,24 +57,24 @@
         SELECT * FROM android_frames_draw_frame;
         """,
         out=Csv("""
-        "id","frame_id","render_thread_utid"
-        8,10,4
-        16,20,4
-        23,30,4
-        41,40,4
-        50,60,4
-        57,90,4
-        60,90,4
-        66,100,4
-        69,100,4
-        74,110,4
-        80,120,4
-        89,130,4
-        95,140,4
-        100,145,4
-        105,150,4
-        109,160,4
-        146,1000,4
+        "id","frame_id","render_thread_utid","upid"
+        8,10,4,2
+        16,20,4,2
+        23,30,4,2
+        41,40,4,2
+        50,60,4,2
+        57,90,4,2
+        60,90,4,2
+        66,100,4,2
+        69,100,4,2
+        74,110,4,2
+        80,120,4,2
+        89,130,4,2
+        95,140,4,2
+        100,145,4,2
+        105,150,4,2
+        109,160,4,2
+        146,1000,4,2
         """))
 
   def test_android_frames(self):
diff --git a/test/trace_processor/diff_tests/stdlib/android/startups_tests.py b/test/trace_processor/diff_tests/stdlib/android/startups_tests.py
index 14d002a..197ac2a 100644
--- a/test/trace_processor/diff_tests/stdlib/android/startups_tests.py
+++ b/test/trace_processor/diff_tests/stdlib/android/startups_tests.py
@@ -35,26 +35,26 @@
 
   def test_warm_startups(self):
     return DiffTestBlueprint(
-        trace=DataPath('api32_startup_warm.perfetto-trace'),
+        trace=DataPath('api31_startup_warm.perfetto-trace'),
         query="""
         INCLUDE PERFETTO MODULE android.startup.startups;
         SELECT * FROM android_startups;
         """,
         out=Csv("""
         "startup_id","ts","ts_end","dur","package","startup_type"
-        28,157479786566030,157479943081777,156515747,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
+        1,186982050780778,186982115528805,64748027,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
         """))
 
   def test_cold_startups(self):
     return DiffTestBlueprint(
-        trace=DataPath('api34_startup_cold.perfetto-trace'),
+        trace=DataPath('api31_startup_cold.perfetto-trace'),
         query="""
         INCLUDE PERFETTO MODULE android.startup.startups;
         SELECT * FROM android_startups;
         """,
         out=Csv("""
         "startup_id","ts","ts_end","dur","package","startup_type"
-        61,17806781251694,17806891032171,109780477,"com.android.systemui.people","warm"
+        1,186974938196632,186975083989042,145792410,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
         """))
 
   def test_hot_startups_maxsdk28(self):
@@ -66,8 +66,8 @@
         """,
         out=Csv("""
         "startup_id","ts","ts_end","dur","package","startup_type"
-        1,779860286416,779893485322,33198906,"com.google.android.googlequicksearchbox","[NULL]"
-        2,780778904571,780813944498,35039927,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
+        1,779860286416,779893485322,33198906,"com.google.android.googlequicksearchbox","hot"
+        2,780778904571,780813944498,35039927,"androidx.benchmark.integration.macrobenchmark.target","hot"
         """))
 
   def test_warm_startups_maxsdk28(self):
@@ -79,7 +79,7 @@
         """,
         out=Csv("""
         "startup_id","ts","ts_end","dur","package","startup_type"
-        1,799979565075,800014194731,34629656,"com.google.android.googlequicksearchbox","[NULL]"
+        1,799979565075,800014194731,34629656,"com.google.android.googlequicksearchbox","hot"
         2,800868511677,800981929562,113417885,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
         """))
 
@@ -94,3 +94,77 @@
         "startup_id","ts","ts_end","dur","package","startup_type"
         1,791231114368,791501060868,269946500,"androidx.benchmark.integration.macrobenchmark.target","[NULL]"
         """))
+
+  def test_android_startup_time_to_display_hot_maxsdk28(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api24_startup_hot.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,33198906,"[NULL]",1,"[NULL]",355
+        2,35039927,537343160,4,5,383
+        """))
+
+  def test_android_startup_time_to_display_warm_maxsdk28(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api24_startup_warm.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,34629656,"[NULL]",1,"[NULL]",355
+        2,108563770,581026583,4,5,388
+        """))
+
+  def test_android_startup_time_to_display_cold_maxsdk28(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api24_startup_cold.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,264869885,715406822,65,66,396
+        """))
+
+  def test_android_startup_time_to_display_hot(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api31_startup_hot.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,40534066,542222554,5872867,5872953,184
+        """))
+
+  def test_android_startup_time_to_display_warm(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api31_startup_warm.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,62373965,555968701,5873800,5873889,185
+        """))
+
+  def test_android_startup_time_to_display_cold(self):
+    return DiffTestBlueprint(
+        trace=DataPath('api31_startup_cold.perfetto-trace'),
+        query="""
+        INCLUDE PERFETTO MODULE android.startup.time_to_display;
+        SELECT * FROM android_startup_time_to_display;
+        """,
+        out=Csv("""
+        "startup_id","time_to_inital_display","time_to_full_display","ttid_frame_id","ttfd_frame_id","upid"
+        1,143980066,620815843,5873276,5873353,229
+        """))
diff --git a/test/trace_processor/diff_tests/stdlib/chrome/tests_scroll_jank.py b/test/trace_processor/diff_tests/stdlib/chrome/tests_scroll_jank.py
index 3f9e4b8..bdde242 100755
--- a/test/trace_processor/diff_tests/stdlib/chrome/tests_scroll_jank.py
+++ b/test/trace_processor/diff_tests/stdlib/chrome/tests_scroll_jank.py
@@ -83,7 +83,7 @@
 
   def test_chrome_scroll_input_offsets(self):
     return DiffTestBlueprint(
-        trace=DataPath('scroll_offsets.pftrace'),
+        trace=DataPath('scroll_offsets_trace_2.pftrace'),
         query="""
         INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_offsets;
 
@@ -91,18 +91,19 @@
           scroll_update_id,
           ts,
           delta_y,
-          offset_y
+          relative_offset_y
         FROM chrome_scroll_input_offsets
+        WHERE scroll_update_id IS NOT NULL
         ORDER by ts
         LIMIT 5;
         """,
         out=Csv("""
-        "scroll_update_id","ts","delta_y","offset_y"
-        1983,4687296612739,-36.999939,-36.999939
-        1983,4687307175845,-39.000092,-76.000031
-        1987,4687313206739,-35.999969,-112.000000
-        1987,4687323152462,-35.000000,-147.000000
-        1991,4687329240739,-28.999969,-175.999969
+        "scroll_update_id","ts","delta_y","relative_offset_y"
+        130,1349914859791,-6.932281,-308.342704
+        132,1349923327791,-32.999954,-341.342659
+        134,1349931893791,-39.999954,-381.342613
+        140,1349956886791,-51.000046,-432.342659
+        147,1349982489791,-89.808540,-522.151199
         """))
 
   def test_chrome_janky_event_latencies_v3(self):
@@ -192,7 +193,7 @@
         """))
   def test_chrome_presented_scroll_offsets(self):
     return DiffTestBlueprint(
-        trace=DataPath('scroll_offsets.pftrace'),
+        trace=DataPath('scroll_offsets_trace_2.pftrace'),
         query="""
         INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_offsets;
 
@@ -200,18 +201,19 @@
           scroll_update_id,
           ts,
           delta_y,
-          offset_y
+          relative_offset_y
         FROM chrome_presented_scroll_offsets
+        WHERE scroll_update_id IS NOT NULL
         ORDER by ts
         LIMIT 5;
         """,
         out=Csv("""
-        "scroll_update_id","ts","delta_y","offset_y"
-        1983,4687341817739,"[NULL]",0
-        1987,4687352950739,-50,-50
-        1991,4687364083739,-50,-100
-        1993,4687375224739,-81,-181
-        1996,4687386343739,-66,-247
+        "scroll_update_id","ts","delta_y","relative_offset_y"
+        130,1349963342791,-6.932281,-6.932281
+        132,1349985554791,-16.573090,-23.505371
+        134,1349996680791,-107.517273,-131.022644
+        140,1350007850791,-158.728424,-289.751068
+        147,1350018935791,-89.808540,-379.559608
         """))
 
   def test_scroll_jank_cause_map(self):
diff --git a/test/trace_processor/diff_tests/stdlib/memory/heap_graph_dominator_tree_tests.py b/test/trace_processor/diff_tests/stdlib/memory/heap_graph_dominator_tree_tests.py
index 52bb465..0aa0f64 100644
--- a/test/trace_processor/diff_tests/stdlib/memory/heap_graph_dominator_tree_tests.py
+++ b/test/trace_processor/diff_tests/stdlib/memory/heap_graph_dominator_tree_tests.py
@@ -65,7 +65,7 @@
           19,14,1,128,4,"U"
           20,14,1,256,4,"V"
           21,14,1,512,4,"W"
-          23,25,1,1024,1,"java.lang.ref.FinalizerReference"
+          23,25,1,1024,1,"sun.misc.Cleaner"
         """))
 
   def test_heap_graph_super_root_fn(self):
diff --git a/test/trace_processor/diff_tests/stdlib/memory/heap_graph_for_dominator_tree.textproto b/test/trace_processor/diff_tests/stdlib/memory/heap_graph_for_dominator_tree.textproto
index b0de072..940b38f 100644
--- a/test/trace_processor/diff_tests/stdlib/memory/heap_graph_for_dominator_tree.textproto
+++ b/test/trace_processor/diff_tests/stdlib/memory/heap_graph_for_dominator_tree.textproto
@@ -26,7 +26,7 @@
   # 2. a synthetic tree whose dominator tree is itself. It's drawn below with
   #    each object represented by it's class name. Number in the bracket is the
   #    size of each node in bytes.
-  #                 S[1]     java.lang.ref.FinalizerReference[1024]
+  #                 S[1]     sun.misc.Cleaner[1024]
   #                /    \    /
   #            M[2]      N[4]
   #           /   \      /   \
@@ -191,7 +191,7 @@
     }
     objects {
       id: 0x18
-      type_id: 24 # "java.lang.ref.FinalizerReference"
+      type_id: 24 # "sun.misc.Cleaner"
       self_size: 1024
       reference_object_id: 0x0e
     }
@@ -335,9 +335,15 @@
     }
     types {
       id: 24
-      class_name: "java.lang.ref.FinalizerReference"
+      class_name: "sun.misc.Cleaner"
+      kind: KIND_PHANTOM_REFERENCE
+      reference_field_id: 123
       location_id: 1
     }
+    field_names {
+      iid: 123
+      str: "java.lang.ref.Reference.referent"
+    }
     continued: false
     index: 1
   }
diff --git a/tools/cpu_profile b/tools/cpu_profile
index 17f0996..ece5095 100755
--- a/tools/cpu_profile
+++ b/tools/cpu_profile
@@ -219,6 +219,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -235,28 +238,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index d71b0dc..c8a2b1a 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -768,7 +768,6 @@
   # The .proto filegroup will be added to `tool_files` of rdeps so that the
   # genrules can be sandboxed.
 
-  tool_files = set()
   for proto_dep in target.proto_deps().union(target.transitive_proto_deps()):
     tool_files.add(":" + label_to_module_name(proto_dep.name))
 
diff --git a/tools/gn_utils.py b/tools/gn_utils.py
index d0417d7..904760e 100644
--- a/tools/gn_utils.py
+++ b/tools/gn_utils.py
@@ -529,9 +529,8 @@
     return metadata.get('exports', [])
 
   def get_proto_paths(self, proto_desc):
-    # import_dirs in metadata will be available for source_set targets.
     metadata = proto_desc.get('metadata', {})
-    return metadata.get('import_dirs', [])
+    return metadata.get('proto_import_dirs', [])
 
   def get_proto_target_type(self, target: Target
                            ) -> Tuple[Optional[str], Optional[Dict]]:
diff --git a/tools/heap_profile b/tools/heap_profile
index 700cfeb..eec9508 100755
--- a/tools/heap_profile
+++ b/tools/heap_profile
@@ -216,6 +216,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -232,28 +235,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/tools/record_android_trace b/tools/record_android_trace
index ceb0808..f2a48c9 100755
--- a/tools/record_android_trace
+++ b/tools/record_android_trace
@@ -201,6 +201,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -217,28 +220,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/tools/trace_processor b/tools/trace_processor
index 0917f54..972c9af 100755
--- a/tools/trace_processor
+++ b/tools/trace_processor
@@ -212,6 +212,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -228,28 +231,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/tools/tracebox b/tools/tracebox
index a9a89e6..144df3a 100755
--- a/tools/tracebox
+++ b/tools/tracebox
@@ -198,6 +198,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -214,28 +217,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/tools/traceconv b/tools/traceconv
index 8ba7114..817022c 100755
--- a/tools/traceconv
+++ b/tools/traceconv
@@ -212,6 +212,9 @@
 import platform
 import subprocess
 import sys
+import threading
+
+DOWNLOAD_LOCK = threading.Lock()
 
 
 def download_or_get_cached(file_name, url, sha256):
@@ -228,28 +231,36 @@
   sha256_path = os.path.join(dir, file_name + '.sha256')
   needs_download = True
 
-  # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
-  # download is cached into file_name.sha256, just check if that matches.
-  if os.path.exists(bin_path) and os.path.exists(sha256_path):
-    with open(sha256_path, 'rb') as f:
-      digest = f.read().decode()
-      if digest == sha256:
-        needs_download = False
+  try:
+    # In BatchTraceProcessor, many threads can be trying to execute the below
+    # code in parallel. For this reason, protect the whole operation with a
+    # lock.
+    DOWNLOAD_LOCK.acquire()
 
-  if needs_download:
-    # Either the filed doesn't exist or the SHA256 doesn't match.
-    tmp_path = bin_path + '.tmp'
-    print('Downloading ' + url)
-    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
-    with open(tmp_path, 'rb') as fd:
-      actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
-    if actual_sha256 != sha256:
-      raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
-                      (url, actual_sha256, sha256))
-    os.chmod(tmp_path, 0o755)
-    os.replace(tmp_path, bin_path)
-    with open(sha256_path, 'w') as f:
-      f.write(sha256)
+    # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
+    # download is cached into file_name.sha256, just check if that matches.
+    if os.path.exists(bin_path) and os.path.exists(sha256_path):
+      with open(sha256_path, 'rb') as f:
+        digest = f.read().decode()
+        if digest == sha256:
+          needs_download = False
+
+    if needs_download:
+      # Either the filed doesn't exist or the SHA256 doesn't match.
+      tmp_path = bin_path + '.tmp'
+      print('Downloading ' + url)
+      subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
+      with open(tmp_path, 'rb') as fd:
+        actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
+      if actual_sha256 != sha256:
+        raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
+                        (url, actual_sha256, sha256))
+      os.chmod(tmp_path, 0o755)
+      os.replace(tmp_path, bin_path)
+      with open(sha256_path, 'w') as f:
+        f.write(sha256)
+  finally:
+    DOWNLOAD_LOCK.release()
   return bin_path
 
 
diff --git a/ui/src/assets/details.scss b/ui/src/assets/details.scss
index d09690a..ff66708 100644
--- a/ui/src/assets/details.scss
+++ b/ui/src/assets/details.scss
@@ -446,112 +446,46 @@
   header.stale {
     color: grey;
   }
+}
 
-  .rows {
-    position: relative;
-    direction: ltr;
-    width: 100%;
+.pf-ftrace-explorer {
+  height: 100%;
+  font-size: 11px;
+  font-family: var(--monospace-font);
 
-    .row {
-      @include transition();
-      position: absolute;
-      width: 100%;
-      height: 20px;
-      line-height: 20px;
-      background-color: hsl(214, 22%, 100%);
+  .colour {
+    display: inline-block;
+    height: 10px;
+    width: 10px;
+    margin-right: 4px;
+  }
+}
 
-      &.D {
-        color: hsl(122, 20%, 40%);
-      }
-      &.V {
-        color: hsl(122, 20%, 30%);
-      }
-      &.I {
-        color: hsl(0, 0%, 20%);
-      }
-      &.W {
-        color: hsl(45, 60%, 45%);
-      }
-      &.E {
-        color: hsl(4, 90%, 58%);
-      }
-      &.F {
-        color: hsl(291, 64%, 42%);
-      }
-      &.stale {
-        color: #aaa;
-      }
-      &:nth-child(even) {
-        background-color: hsl(214, 22%, 95%);
-      }
-      &:hover {
-        background-color: $table-hover-color;
-      }
-      .cell {
-        font-size: 11px;
-        font-family: var(--monospace-font);
-        white-space: nowrap;
-        overflow: scroll;
-        padding-left: 10px;
-        padding-right: 10px;
-        display: inline-block;
-        &:first-child {
-          padding-left: 5px;
-        }
-        &:last-child {
-          padding-right: 5px;
-        }
-        &:only-child {
-          width: 100%;
-        }
+.pf-android-logs-table {
+  height: 100%;
+  font-size: 11px;
+  font-family: var(--monospace-font);
 
-        // The following children will be used as columns in the table showing
-        // Android logs.
-
-        // 1.Timestamp
-        &:nth-child(1) {
-          width: 7rem;
-          text-overflow: clip;
-          text-align: right;
-        }
-        // 2.Level
-        &:nth-child(2) {
-          width: 4rem;
-        }
-        // 3.Tag
-        &:nth-child(3) {
-          width: 13rem;
-        }
-
-        &.with-process {
-          // 4.Process name
-          &:nth-child(4) {
-            width: 18rem;
-          }
-          // 5.Message - a long string, will take most of the display space.
-          &:nth-child(5) {
-            width: calc(100% - 42rem);
-          }
-        }
-
-        &.no-process {
-          // 4.Message - a long string, will take most of the display space.
-          &:nth-child(4) {
-            width: calc(100% - 24rem);
-          }
-        }
-
-        &.row-header {
-          text-align: left;
-          font-weight: bold;
-          font-size: 13px;
-        }
-
-        &.row-header:first-child {
-          padding-left: 15px;
-        }
-      }
-    }
+  .D {
+    color: hsl(122, 20%, 40%);
+  }
+  .V {
+    color: hsl(122, 20%, 30%);
+  }
+  .I {
+    color: hsl(0, 0%, 20%);
+  }
+  .W {
+    color: hsl(45, 60%, 45%);
+  }
+  .E {
+    color: hsl(4, 90%, 58%);
+  }
+  .F {
+    color: hsl(291, 64%, 42%);
+  }
+  .pf-highlighted {
+    background: #d2efe0;
   }
 }
 
@@ -559,109 +493,6 @@
   margin: 10px;
 }
 
-.ftrace-panel {
-  display: contents;
-
-  .sticky {
-    position: sticky;
-    top: 0;
-    left: 0;
-    z-index: 1;
-    background-color: white;
-    color: #3c4b5d;
-    padding: 5px 10px;
-    display: grid;
-    grid-template-columns: auto auto;
-    justify-content: space-between;
-  }
-
-  .ftrace-rows-label {
-    display: flex;
-    align-items: center;
-  }
-
-  header.stale {
-    color: grey;
-  }
-
-  .rows {
-    position: relative;
-    direction: ltr;
-    min-width: 100%;
-    font-size: 12px;
-
-    .row {
-      @include transition();
-      position: absolute;
-      min-width: 100%;
-      line-height: 20px;
-      background-color: hsl(214, 22%, 100%);
-      white-space: nowrap;
-
-      &:nth-child(even) {
-        background-color: hsl(214, 22%, 95%);
-      }
-
-      &:hover {
-        background-color: $table-hover-color;
-      }
-
-      .cell {
-        font-family: var(--monospace-font);
-        white-space: nowrap;
-        overflow: hidden;
-        text-overflow: ellipsis;
-        margin-right: 8px;
-        display: inline-block;
-
-        .colour {
-          display: inline-block;
-          height: 10px;
-          width: 10px;
-          margin-right: 4px;
-        }
-
-        &:first-child {
-          margin-left: 8px;
-        }
-
-        &:last-child {
-          margin-right: 8px;
-        }
-
-        &:only-child {
-          width: 100%;
-        }
-
-        // Timestamp
-        &:nth-child(1) {
-          width: 13em;
-          // text-align: right;
-        }
-
-        // Name
-        &:nth-child(2) {
-          width: 24em;
-        }
-
-        // CPU
-        &:nth-child(3) {
-          width: 3em;
-        }
-
-        // Process
-        &:nth-child(4) {
-          width: 24em;
-        }
-
-        &.row-header {
-          font-weight: bold;
-        }
-      }
-    }
-  }
-}
-
 .screenshot-panel {
   height: 100%;
   img {
diff --git a/ui/src/assets/perfetto.scss b/ui/src/assets/perfetto.scss
index 8bb1cdc..567deae 100644
--- a/ui/src/assets/perfetto.scss
+++ b/ui/src/assets/perfetto.scss
@@ -56,3 +56,4 @@
 @import "widgets/hotkey";
 @import "widgets/text_paragraph";
 @import "widgets/treetable";
+@import "widgets/virtual_table";
diff --git a/ui/src/assets/widgets/details_shell.scss b/ui/src/assets/widgets/details_shell.scss
index a71f237..4888f6b 100644
--- a/ui/src/assets/widgets/details_shell.scss
+++ b/ui/src/assets/widgets/details_shell.scss
@@ -63,6 +63,8 @@
 
   &.pf-fill-parent {
     height: 100%;
+    overflow-y: hidden;
+
     .pf-content {
       overflow-y: auto;
     }
diff --git a/ui/src/assets/widgets/virtual_table.scss b/ui/src/assets/widgets/virtual_table.scss
new file mode 100644
index 0000000..acd22d5
--- /dev/null
+++ b/ui/src/assets/widgets/virtual_table.scss
@@ -0,0 +1,89 @@
+// 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.
+
+@use "sass:math";
+@import "theme";
+
+// Adding these to a new layer makes other rules take precedence
+@layer widgets {
+  .pf-vtable {
+    overflow: auto;
+    font-family: $pf-font;
+    position: relative;
+    background: white; // Performance tweak - see b/335451611
+
+    .pf-vtable-content {
+      display: inline-flex;
+      flex-direction: column;
+      min-width: 100%;
+
+      .pf-vtable-header {
+        font-weight: bold;
+        position: sticky;
+        top: 0;
+        z-index: 1;
+        background: white;
+        white-space: nowrap;
+        padding-inline: 4px;
+
+        // A shadow improves distinction between header and content
+        box-shadow: #0001 0px 0px 8px;
+      }
+
+      .pf-vtable-data {
+        white-space: nowrap;
+        overflow: hidden;
+        text-overflow: ellipsis;
+        margin-right: 8px;
+        display: inline-block;
+      }
+
+      .pf-vtable-slider {
+        overflow: hidden;
+
+        // Necessary trig because we have a 45deg stripes
+        $pattern-density: 1px * math.sqrt(2);
+        $pattern-col: #ddd;
+        overflow: hidden;
+
+        background: repeating-linear-gradient(
+          -45deg,
+          $pattern-col,
+          $pattern-col $pattern-density,
+          white $pattern-density,
+          white $pattern-density * 2
+        );
+
+        .pf-vtable-puck {
+          .pf-vtable-row {
+            white-space: nowrap;
+            padding-inline: 4px;
+
+            &:nth-child(odd) {
+              background-color: hsl(214, 22%, 95%);
+            }
+
+            &:nth-child(even) {
+              background-color: white;
+            }
+
+            &:hover {
+              background-color: $table-hover-color;
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/ui/src/base/geom.ts b/ui/src/base/geom.ts
index f569400..5a20023 100644
--- a/ui/src/base/geom.ts
+++ b/ui/src/base/geom.ts
@@ -24,6 +24,11 @@
   readonly height: number;
 }
 
+export interface Vector {
+  readonly x: number;
+  readonly y: number;
+}
+
 export function intersectRects(a: Rect, b: Rect): Rect {
   return {
     top: Math.max(a.top, b.top),
@@ -57,3 +62,28 @@
     height: r.bottom - r.top,
   };
 }
+
+/**
+ * Return true if rect a contains rect b.
+ *
+ * @param a A rect.
+ * @param b Another rect.
+ * @returns True if rect a contains rect b, false otherwise.
+ */
+export function containsRect(a: Rect, b: Rect): boolean {
+  return !(
+    b.top < a.top ||
+    b.bottom > a.bottom ||
+    b.left < a.left ||
+    b.right > a.right
+  );
+}
+
+export function translateRect(a: Rect, b: Vector): Rect {
+  return {
+    top: a.top + b.y,
+    left: a.left + b.x,
+    bottom: a.bottom + b.y,
+    right: a.right + b.x,
+  };
+}
diff --git a/ui/src/common/flamegraph_util.ts b/ui/src/common/flamegraph_util.ts
index 0817ebf..acf2ee8 100644
--- a/ui/src/common/flamegraph_util.ts
+++ b/ui/src/common/flamegraph_util.ts
@@ -24,7 +24,7 @@
   id: 'showHeapGraphDominatorTree',
   name: 'Show heap graph dominator tree',
   description: 'Show dominated size and objects tabs in Java heap graph view.',
-  defaultValue: false,
+  defaultValue: true,
 });
 
 export function viewingOptions(profileType: ProfileType): Array<ViewingOption> {
diff --git a/ui/src/common/search_data.ts b/ui/src/common/search_data.ts
index b81dfb2..7209c04 100644
--- a/ui/src/common/search_data.ts
+++ b/ui/src/common/search_data.ts
@@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+export type SearchSource = 'cpu' | 'log' | 'slice' | 'track';
+
 export interface SearchSummary {
   tsStarts: BigInt64Array;
   tsEnds: BigInt64Array;
@@ -19,10 +21,10 @@
 }
 
 export interface CurrentSearchResults {
-  sliceIds: Float64Array;
-  tsStarts: BigInt64Array;
+  eventIds: Float64Array;
+  tses: BigInt64Array;
   utids: Float64Array;
   trackKeys: string[];
-  sources: string[];
+  sources: SearchSource[];
   totalResults: number;
 }
diff --git a/ui/src/controller/aggregation/counter_aggregation_controller.ts b/ui/src/controller/aggregation/counter_aggregation_controller.ts
index 704add7..20afd9e 100644
--- a/ui/src/controller/aggregation/counter_aggregation_controller.ts
+++ b/ui/src/controller/aggregation/counter_aggregation_controller.ts
@@ -39,33 +39,72 @@
     const duration = area.end - area.start;
     const durationSec = Duration.toSeconds(duration);
 
-    const query = `create view ${this.kind} as select
-    name,
-    count(1) as count,
-    round(sum(weighted_value)/${duration}, 2) as avg_value,
-    last as last_value,
-    first as first_value,
-    max(last) - min(first) as delta_value,
-    round((max(last) - min(first))/${durationSec}, 2) as rate,
-    min(value) as min_value,
-    max(value) as max_value
-    from
-        (select *,
-        (min(ts + dur, ${area.end}) - max(ts,${area.start}))
-        * value as weighted_value,
-        first_value(value) over
-        (partition by track_id order by ts) as first,
-        last_value(value) over
-        (partition by track_id order by ts
-            range between unbounded preceding and unbounded following) as last
-        from experimental_counter_dur
-        where track_id in (${trackIds})
-        and ts + dur >= ${area.start} and
-        ts <= ${area.end})
-    join counter_track
-    on track_id = counter_track.id
-    group by track_id`;
-
+    // TODO(lalitm): Rewrite this query in a way that is both simpler and faster
+    let query;
+    if (trackIds.length === 1) {
+      // Optimized query for the special case where there is only 1 track id.
+      query = `CREATE VIEW ${this.kind} AS
+      WITH aggregated AS (
+        SELECT
+          COUNT(1) AS count,
+          ROUND(SUM(
+            (MIN(ts + dur, ${area.end}) - MAX(ts,${area.start}))*value)/${duration},
+            2
+          ) AS avg_value,
+          (SELECT value FROM experimental_counter_dur WHERE track_id = ${trackIds[0]}
+            AND ts + dur >= ${area.start}
+            AND ts <= ${area.end} ORDER BY ts DESC LIMIT 1)
+            AS last_value,
+          (SELECT value FROM experimental_counter_dur WHERE track_id = ${trackIds[0]}
+            AND ts + dur >= ${area.start}
+            AND ts <= ${area.end} ORDER BY ts ASC LIMIT 1)
+            AS first_value,
+          MIN(value) AS min_value,
+          MAX(value) AS max_value
+        FROM experimental_counter_dur
+          WHERE track_id = ${trackIds[0]}
+          AND ts + dur >= ${area.start}
+          AND ts <= ${area.end})
+      SELECT
+        (SELECT name FROM counter_track WHERE id = ${trackIds[0]}) AS name,
+        *,
+        MAX(last_value) - MIN(first_value) AS delta_value,
+        ROUND((MAX(last_value) - MIN(first_value))/${durationSec}, 2) AS rate
+      FROM aggregated`;
+    } else {
+      // Slower, but general purspose query that can aggregate multiple tracks
+      query = `CREATE VIEW ${this.kind} AS
+      WITH aggregated AS (
+        SELECT track_id,
+          COUNT(1) AS count,
+          ROUND(SUM(
+            (MIN(ts + dur, ${area.end}) - MAX(ts,${area.start}))*value)/${duration},
+            2
+          ) AS avg_value,
+          value_at_max_ts(-ts, value) AS first,
+          value_at_max_ts(ts, value) AS last,
+          MIN(value) AS min_value,
+          MAX(value) AS max_value
+        FROM experimental_counter_dur
+          WHERE track_id IN (${trackIds})
+          AND ts + dur >= ${area.start} AND
+          ts <= ${area.end}
+        GROUP BY track_id
+      )
+      SELECT
+        name,
+        count,
+        avg_value,
+        last AS last_value,
+        first AS first_value,
+        last - first AS delta_value,
+        ROUND((last - first)/${durationSec}, 2) AS rate,
+        min_value,
+        max_value
+      FROM aggregated JOIN counter_track ON
+        track_id = counter_track.id
+      GROUP BY track_id`;
+    }
     await engine.query(query);
     return true;
   }
diff --git a/ui/src/controller/flamegraph_controller.ts b/ui/src/controller/flamegraph_controller.ts
index b1c00a4..22160d6 100644
--- a/ui/src/controller/flamegraph_controller.ts
+++ b/ui/src/controller/flamegraph_controller.ts
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import {Duration, Time, time} from '../base/time';
+import {Duration, time} from '../base/time';
 import {exists} from '../base/utils';
 import {Actions} from '../common/actions';
 import {
@@ -25,8 +25,8 @@
   CallsiteInfo,
   FlamegraphState,
   FlamegraphStateViewingOption,
-  ProfileType,
   isHeapGraphDominatorTreeViewingOption,
+  ProfileType,
 } from '../common/state';
 import {FlamegraphDetails, globals} from '../frontend/globals';
 import {publishFlamegraphDetails} from '../frontend/publish';
@@ -106,6 +106,10 @@
     }
     return tableName;
   }
+
+  hasQuery(query: string): boolean {
+    return this.cache.get(query) !== undefined;
+  }
 }
 
 export class FlamegraphController extends Controller<'main'> {
@@ -116,10 +120,6 @@
   private flamegraphDetails: FlamegraphDetails = {};
   private areaSelectionHandler: AreaSelectionHandler;
   private cache: TablesCache;
-  private heapGraphSelected: {upid: number; timestamp: time} = {
-    upid: -1,
-    timestamp: Time.INVALID,
-  };
 
   constructor(private args: FlamegraphControllerArgs) {
     super('main');
@@ -215,9 +215,8 @@
       const flamegraphData = await this.getFlamegraphData(
         key,
         /* eslint-disable @typescript-eslint/strict-boolean-expressions */
-        selectedFlamegraphState.viewingOption
-          ? /* eslint-enable */
-            selectedFlamegraphState.viewingOption
+        selectedFlamegraphState.viewingOption /* eslint-enable */
+          ? selectedFlamegraphState.viewingOption
           : defaultViewingOption(selectedFlamegraphState.type),
         selection.start,
         selection.end,
@@ -540,22 +539,18 @@
   }
 
   private async loadHeapGraphDominatorTreeQuery(upid: number, timestamp: time) {
-    const selectTreeQuery = `
-    -- cache invalidate: upid ${upid}, ts ${timestamp}
-    SELECT * FROM heap_graph_type_dominated`;
-    if (
-      this.heapGraphSelected.upid === upid &&
-      this.heapGraphSelected.timestamp === timestamp
-    ) {
-      return selectTreeQuery;
+    const outputTableName = `heap_graph_type_dominated_${upid}_${timestamp}`;
+    const outputQuery = `SELECT * FROM ${outputTableName}`;
+    if (this.cache.hasQuery(outputQuery)) {
+      return outputQuery;
     }
-    this.heapGraphSelected = {upid, timestamp};
+
     this.args.engine.query(`
     INCLUDE PERFETTO MODULE memory.heap_graph_dominator_tree;
 
     -- heap graph dominator tree with objects as nodes and all relavant
     -- object self stats and dominated stats
-    CREATE PERFETTO TABLE heap_graph_object_dominated AS
+    CREATE PERFETTO TABLE _heap_graph_object_dominated AS
     SELECT
      node.id,
      node.idom_id,
@@ -574,21 +569,19 @@
     -- calculate for each object node in the dominator tree the
     -- HASH(path of type_id's from the super root to the object)
     CREATE PERFETTO TABLE _dominator_tree_path_hash AS
-    WITH RECURSIVE _tree_visitor(id, path, path_hash) AS (
+    WITH RECURSIVE _tree_visitor(id, path_hash) AS (
       SELECT
         id,
-        CAST(type_id AS text) || '-' || IFNULL(root_type, '') AS path,
         HASH(
-          CAST(type_id AS text) || '-' || IFNULL(root_type, '')
+          CAST(type_id AS TEXT) || '-' || IFNULL(root_type, '')
         ) AS path_hash
-      FROM heap_graph_object_dominated
+      FROM _heap_graph_object_dominated
       WHERE depth = 1
       UNION ALL
       SELECT
         child.id,
-        parent.path || '/' || CAST(type_id AS text) AS path,
-        HASH(parent.path || '/' || CAST(type_id AS text)) AS path_hash
-      FROM heap_graph_object_dominated child
+        HASH(CAST(parent.path_hash AS TEXT) || '/' || CAST(type_id AS TEXT)) AS path_hash
+      FROM _heap_graph_object_dominated child
       JOIN _tree_visitor parent ON child.idom_id = parent.id
     )
     SELECT * from _tree_visitor
@@ -597,7 +590,7 @@
     -- merge object nodes with the same path into one "class type node", so the
     -- end result is a tree where nodes are identified by their types and the
     -- dominator relationships are preserved.
-    CREATE PERFETTO TABLE heap_graph_type_dominated AS
+    CREATE PERFETTO TABLE ${outputTableName} AS
     SELECT
       map.path_hash as id,
       COALESCE(cls.deobfuscated_name, cls.name, '[NULL]') || IIF(
@@ -615,13 +608,18 @@
       -1 as line_number,
       sum(self_size) AS size,
       count(*) AS count
-    FROM heap_graph_object_dominated node
+    FROM _heap_graph_object_dominated node
     JOIN _dominator_tree_path_hash map USING(id)
     LEFT JOIN _dominator_tree_path_hash parent_map ON node.idom_id = parent_map.id
     JOIN heap_graph_class cls ON node.type_id = cls.id
-    GROUP BY map.path_hash, name, parent_id, depth, map_name, source_file, line_number;`);
+    GROUP BY map.path_hash, name, parent_id, depth, map_name, source_file, line_number;
 
-    return selectTreeQuery;
+    -- These are intermediates and not needed
+    DROP TABLE _heap_graph_object_dominated;
+    DROP TABLE _dominator_tree_path_hash;
+    `);
+
+    return outputQuery;
   }
 
   getMinSizeDisplayed(
diff --git a/ui/src/controller/search_controller.ts b/ui/src/controller/search_controller.ts
index 5caff6e..61ada93 100644
--- a/ui/src/controller/search_controller.ts
+++ b/ui/src/controller/search_controller.ts
@@ -15,7 +15,11 @@
 import {sqliteString} from '../base/string_utils';
 import {Duration, duration, Span, time, Time, TimeSpan} from '../base/time';
 import {exists} from '../base/utils';
-import {CurrentSearchResults, SearchSummary} from '../common/search_data';
+import {
+  CurrentSearchResults,
+  SearchSource,
+  SearchSummary,
+} from '../common/search_data';
 import {OmniboxState} from '../common/state';
 import {globals} from '../frontend/globals';
 import {publishSearch, publishSearchResult} from '../frontend/publish';
@@ -100,8 +104,8 @@
         count: new Uint8Array(0),
       });
       publishSearchResult({
-        sliceIds: new Float64Array(0),
-        tsStarts: new BigInt64Array(0),
+        eventIds: new Float64Array(0),
+        tses: new BigInt64Array(0),
         utids: new Float64Array(0),
         sources: [],
         trackKeys: [],
@@ -203,11 +207,9 @@
     // easier once the track table has entries for all the tracks.
     const cpuToTrackId = new Map();
     for (const track of Object.values(globals.state.tracks)) {
-      if (exists(track?.uri)) {
-        const trackInfo = globals.trackManager.resolveTrackInfo(track.uri);
-        if (trackInfo?.kind === CPU_SLICE_TRACK_KIND) {
-          exists(trackInfo.cpu) && cpuToTrackId.set(trackInfo.cpu, track.key);
-        }
+      const trackInfo = globals.trackManager.resolveTrackInfo(track.uri);
+      if (trackInfo?.kind === CPU_SLICE_TRACK_KIND) {
+        exists(trackInfo.cpu) && cpuToTrackId.set(trackInfo.cpu, track.key);
       }
     }
 
@@ -220,60 +222,83 @@
       utids.push(it.utid);
     }
 
-    const queryRes = await this.query(`
-    select
-      id as sliceId,
-      ts,
-      'cpu' as source,
-      cpu as sourceId,
-      utid
-    from sched where utid in (${utids.join(',')})
-    union
-    select
-      slice_id as sliceId,
-      ts,
-      'track' as source,
-      track_id as sourceId,
-      0 as utid
-      from slice
-      where slice.name glob ${searchLiteral}
-        or (
-          0 != CAST(${sqliteString(search)} AS INT) and
-          sliceId = CAST(${sqliteString(search)} AS INT)
-        )
-    union
-    select
-      slice_id as sliceId,
-      ts,
-      'track' as source,
-      track_id as sourceId,
-      0 as utid
-      from slice
-      join args using(arg_set_id)
-      where string_value glob ${searchLiteral} or key glob ${searchLiteral}
-    union
-    select
-      id as sliceId,
-      ts,
-      'log' as source,
-      0 as sourceId,
-      utid
-    from android_logs where msg glob ${searchLiteral}
-    order by ts
-
+    const res = await this.query(`
+      select
+        id as sliceId,
+        ts,
+        'cpu' as source,
+        cpu as sourceId,
+        utid
+      from sched where utid in (${utids.join(',')})
+      union all
+      select *
+      from (
+        select
+          slice_id as sliceId,
+          ts,
+          'slice' as source,
+          track_id as sourceId,
+          0 as utid
+          from slice
+          where slice.name glob ${searchLiteral}
+            or (
+              0 != CAST(${sqliteString(search)} AS INT) and
+              sliceId = CAST(${sqliteString(search)} AS INT)
+            )
+        union
+        select
+          slice_id as sliceId,
+          ts,
+          'slice' as source,
+          track_id as sourceId,
+          0 as utid
+        from slice
+        join args using(arg_set_id)
+        where string_value glob ${searchLiteral} or key glob ${searchLiteral}
+      )
+      union all
+      select
+        id as sliceId,
+        ts,
+        'log' as source,
+        0 as sourceId,
+        utid
+      from android_logs where msg glob ${searchLiteral}
+      order by ts
     `);
 
-    const rows = queryRes.numRows();
     const searchResults: CurrentSearchResults = {
-      sliceIds: new Float64Array(rows),
-      tsStarts: new BigInt64Array(rows),
-      utids: new Float64Array(rows),
-      trackKeys: [],
+      eventIds: new Float64Array(0),
+      tses: new BigInt64Array(0),
+      utids: new Float64Array(0),
       sources: [],
+      trackKeys: [],
       totalResults: 0,
     };
 
-    const it = queryRes.iter({
+    const lowerSearch = search.toLowerCase();
+    for (const track of Object.values(globals.state.tracks)) {
+      if (track.name.toLowerCase().indexOf(lowerSearch) === -1) {
+        continue;
+      }
+      searchResults.totalResults++;
+      searchResults.sources.push('track');
+      searchResults.trackKeys.push(track.key);
+    }
+
+    const rows = res.numRows();
+    searchResults.eventIds = new Float64Array(
+      searchResults.totalResults + rows,
+    );
+    searchResults.tses = new BigInt64Array(searchResults.totalResults + rows);
+    searchResults.utids = new Float64Array(searchResults.totalResults + rows);
+    for (let i = 0; i < searchResults.totalResults; ++i) {
+      searchResults.eventIds[i] = -1;
+      searchResults.tses[i] = -1n;
+      searchResults.utids[i] = -1;
+    }
+
+    const it = res.iter({
       sliceId: NUM,
       ts: LONG,
       source: STR,
@@ -284,7 +309,7 @@
       let trackId = undefined;
       if (it.source === 'cpu') {
         trackId = cpuToTrackId.get(it.sourceId);
-      } else if (it.source === 'track') {
+      } else if (it.source === 'slice') {
         trackId = globals.trackManager.trackKeyByTrackId.get(it.sourceId);
       } else if (it.source === 'log') {
         const logTracks = Object.values(globals.state.tracks).filter(
@@ -305,9 +330,9 @@
 
       const i = searchResults.totalResults++;
       searchResults.trackKeys.push(trackId);
-      searchResults.sources.push(it.source);
-      searchResults.sliceIds[i] = it.sliceId;
-      searchResults.tsStarts[i] = it.ts;
+      searchResults.sources.push(it.source as SearchSource);
+      searchResults.eventIds[i] = it.sliceId;
+      searchResults.tses[i] = it.ts;
       searchResults.utids[i] = it.utid;
     }
     return searchResults;
diff --git a/ui/src/controller/trace_controller.ts b/ui/src/controller/trace_controller.ts
index 5194215..c1f0d6e 100644
--- a/ui/src/controller/trace_controller.ts
+++ b/ui/src/controller/trace_controller.ts
@@ -201,20 +201,14 @@
 // ensure it's only run once.
 async function defineMaxLayoutDepthSqlFunction(engine: Engine): Promise<void> {
   await engine.query(`
-    create or replace perfetto table __max_layout_depth_state as
-    select track_id, max(depth) as max_depth
-    from slice
-    group by track_id
-    order by track_id;
-
     create perfetto function __max_layout_depth(track_count INT, track_ids STRING)
     returns INT AS
     select iif(
       $track_count = 1,
       (
         select max_depth
-        from __max_layout_depth_state
-        where track_id = cast($track_ids AS int)
+        from _slice_track_summary
+        where id = cast($track_ids AS int)
       ),
       (
         select max(layout_depth)
@@ -517,6 +511,7 @@
 
     // Make sure the helper views are available before we start adding tracks.
     await this.initialiseHelperViews();
+    await this.includeSummaryTables();
 
     await defineMaxLayoutDepthSqlFunction(engine);
 
@@ -1097,6 +1092,22 @@
     }
   }
 
+  async includeSummaryTables() {
+    const engine = assertExists<Engine>(this.engine);
+
+    this.updateStatus('Creating slice summaries');
+    await engine.query(`include perfetto module viz.summary.slices;`);
+
+    this.updateStatus('Creating thread summaries');
+    await engine.query(`include perfetto module viz.summary.threads;`);
+
+    this.updateStatus('Creating processes summaries');
+    await engine.query(`include perfetto module viz.summary.processes;`);
+
+    this.updateStatus('Creating track summaries');
+    await engine.query(`include perfetto module viz.summary.tracks;`);
+  }
+
   private updateStatus(msg: string): void {
     globals.dispatch(
       Actions.updateStatus({
diff --git a/ui/src/controller/track_decider.ts b/ui/src/controller/track_decider.ts
index d8f42fb..b6dd388 100644
--- a/ui/src/controller/track_decider.ts
+++ b/ui/src/controller/track_decider.ts
@@ -167,64 +167,35 @@
 
   async addGlobalAsyncTracks(engine: EngineProxy): Promise<void> {
     const rawGlobalAsyncTracks = await engine.query(`
-      with tracks_with_slices as materialized (
-        select distinct track_id
-        from slice
-      ),
-      global_tracks as (
-        select
-          track.parent_id as parent_id,
-          track.id as track_id,
-          track.name as name
-        from track
-        join tracks_with_slices on tracks_with_slices.track_id = track.id
-        where
-          track.type = "track"
-          or track.type = "gpu_track"
-          or track.type = "cpu_track"
-      ),
-      global_tracks_grouped as (
-        select
-          parent_id,
-          name,
-          group_concat(track_id) as trackIds,
-          count(track_id) as trackCount
-        from global_tracks track
-        group by parent_id, name
+      with global_tracks_grouped as (
+        select distinct t.parent_id, t.name
+        from track t
+        join _slice_track_summary using (id)
+        where t.type in ('track', 'gpu_track', 'cpu_track')
       )
       select
-        t.parent_id as parentId,
-        p.name as parentName,
         t.name as name,
-        t.trackIds as trackIds,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
+        t.parent_id as parentId,
+        p.name as parentName
       from global_tracks_grouped AS t
       left join track p on (t.parent_id = p.id)
-      order by p.name, t.name;
+      order by p.name, t.name
     `);
     const it = rawGlobalAsyncTracks.iter({
       name: STR_NULL,
-      parentName: STR_NULL,
       parentId: NUM_NULL,
-      maxDepth: NUM_NULL,
+      parentName: STR_NULL,
     });
 
     const parentIdToGroupId = new Map<number, string>();
-
     for (; it.valid(); it.next()) {
       const kind = ASYNC_SLICE_TRACK_KIND;
       const rawName = it.name === null ? undefined : it.name;
       const rawParentName = it.parentName === null ? undefined : it.parentName;
       const name = getTrackName({name: rawName, kind});
       const parentTrackId = it.parentId;
-      const maxDepth = it.maxDepth;
       let trackGroup = SCROLLING_TRACK_GROUP;
 
-      // If there are no slices in this track, skip it.
-      if (maxDepth === null) {
-        continue;
-      }
-
       if (parentTrackId !== null) {
         const groupId = parentIdToGroupId.get(parentTrackId);
         if (groupId === undefined) {
@@ -261,11 +232,11 @@
       // Only add a gpu freq track if we have
       // gpu freq data.
       const freqExistsResult = await engine.query(`
-      select *
-      from gpu_counter_track
-      where name = 'gpufreq' and gpu_id = ${gpu}
-      limit 1;
-    `);
+        select *
+        from gpu_counter_track
+        where name = 'gpufreq' and gpu_id = ${gpu}
+        limit 1;
+      `);
       if (freqExistsResult.numRows() > 0) {
         this.tracksToAdd.push({
           uri: `perfetto.Counter#gpu_freq${gpu}`,
@@ -638,14 +609,14 @@
 
   async addThreadStateTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with ts_distinct as materialized (select distinct utid from thread_state)
       select
         utid,
         upid,
         tid,
         thread.name as threadName
       from thread
-      where utid != 0 and utid in ts_distinct`);
+      join _sched_summary using (utid)
+    `);
 
     const it = result.iter({
       utid: NUM,
@@ -726,16 +697,16 @@
 
   async addThreadCounterTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-    select
-      thread_counter_track.name as trackName,
-      utid,
-      upid,
-      tid,
-      thread.name as threadName,
-      thread_counter_track.id as trackId
-    from thread_counter_track
-    join thread using(utid)
-    where thread_counter_track.name != 'thread_time'
+      select
+        thread_counter_track.name as trackName,
+        utid,
+        upid,
+        tid,
+        thread.name as threadName,
+        thread_counter_track.id as trackId
+      from thread_counter_track
+      join thread using(utid)
+      where thread_counter_track.name != 'thread_time'
   `);
 
     const it = result.iter({
@@ -776,27 +747,15 @@
 
   async addProcessAsyncSliceTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where
-            process_track.name is null or
-            process_track.name not like "% Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
+        upid,
+        t.name as trackName,
+        t.track_ids as trackIds,
+        process.name as processName,
+        process.pid as pid
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name is null or t.name not glob "* Timeline"
     `);
 
     const it = result.iter({
@@ -805,7 +764,6 @@
       trackIds: STR,
       processName: STR_NULL,
       pid: NUM_NULL,
-      maxDepth: NUM_NULL,
     });
     for (; it.valid(); it.next()) {
       const upid = it.upid;
@@ -813,14 +771,8 @@
       const rawTrackIds = it.trackIds;
       const processName = it.processName;
       const pid = it.pid;
-      const maxDepth = it.maxDepth;
 
-      if (maxDepth === null) {
-        // If there are no slices in this track, skip it.
-        continue;
-      }
-
-      const uuid = this.getUuid(0, upid);
+      const uuid = this.getUuid(null, upid);
       const name = getTrackName({
         name: trackName,
         upid,
@@ -840,37 +792,18 @@
 
   async addUserAsyncSliceTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with tracks_with_slices as materialized (
-        select distinct track_id
-        from slice
-      ),
-      global_tracks as (
-        select
-          uid_track.name,
-          uid_track.uid,
-          group_concat(uid_track.id) as trackIds,
-          count(uid_track.id) as trackCount
-        from uid_track
-        join tracks_with_slices
-        where tracks_with_slices.track_id == uid_track.id
-        group by uid_track.uid
-      )
       select
         t.name as name,
         t.uid as uid,
-        package_list.package_name as package_name,
-        t.trackIds as trackIds,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from global_tracks t
-      join package_list
-      where t.uid = package_list.uid
-      group by t.uid
-      `);
+        package_list.package_name as packageName
+      from _uid_track_track_summary_by_uid_and_name t
+      join package_list using (uid)
+    `);
 
     const it = result.iter({
       name: STR_NULL,
       uid: NUM_NULL,
-      package_name: STR_NULL,
+      packageName: STR_NULL,
     });
 
     // Map From [name] -> [uuid, key]
@@ -882,8 +815,7 @@
       }
       const rawName = it.name;
       const uid = it.uid === null ? undefined : it.uid;
-      const userName =
-        it.package_name === null ? `UID: ${uid}` : it.package_name;
+      const userName = it.packageName === null ? `UID: ${uid}` : it.packageName;
 
       const groupUuid = `uid-track-group${rawName}`;
       if (groupMap.get(rawName) === undefined) {
@@ -910,48 +842,29 @@
 
   async addActualFramesTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where process_track.name = "Actual Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
-  `);
+        upid,
+        t.name as trackName,
+        process.name as processName,
+        process.pid as pid
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name = "Actual Timeline"
+    `);
 
     const it = result.iter({
       upid: NUM,
       trackName: STR_NULL,
       processName: STR_NULL,
       pid: NUM_NULL,
-      maxDepth: NUM_NULL,
     });
     for (; it.valid(); it.next()) {
       const upid = it.upid;
       const trackName = it.trackName;
       const processName = it.processName;
       const pid = it.pid;
-      const maxDepth = it.maxDepth;
 
-      if (maxDepth === null) {
-        // If there are no slices in this track, skip it.
-        continue;
-      }
-
-      const uuid = this.getUuid(0, upid);
-
+      const uuid = this.getUuid(null, upid);
       const kind = ACTUAL_FRAMES_SLICE_TRACK_KIND;
       const name = getTrackName({
         name: trackName,
@@ -972,33 +885,21 @@
 
   async addExpectedFramesTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where process_track.name = "Expected Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
-  `);
+        upid,
+        t.name as trackName,
+        process.name as processName,
+        process.pid as pid
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name = "Expected Timeline"
+    `);
 
     const it = result.iter({
       upid: NUM,
       trackName: STR_NULL,
       processName: STR_NULL,
       pid: NUM_NULL,
-      maxDepth: NUM_NULL,
     });
 
     for (; it.valid(); it.next()) {
@@ -1006,15 +907,8 @@
       const trackName = it.trackName;
       const processName = it.processName;
       const pid = it.pid;
-      const maxDepth = it.maxDepth;
 
-      if (maxDepth === null) {
-        // If there are no slices in this track, skip it.
-        continue;
-      }
-
-      const uuid = this.getUuid(0, upid);
-
+      const uuid = this.getUuid(null, upid);
       const kind = EXPECTED_FRAMES_SLICE_TRACK_KIND;
       const name = getTrackName({
         name: trackName,
@@ -1035,7 +929,6 @@
 
   async addThreadSliceTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      with slice_track as materialized (select distinct track_id from slice)
       select
         thread_track.utid as utid,
         thread_track.id as trackId,
@@ -1046,8 +939,8 @@
         thread.name as threadName,
         thread.upid as upid
       from thread_track
+      join _slice_track_summary using (id)
       join thread using(utid)
-      join slice_track on thread_track.id = slice_track.track_id
   `);
 
     const it = result.iter({
@@ -1091,14 +984,14 @@
 
   async addProcessCounterTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-    select
-      process_counter_track.id as trackId,
-      process_counter_track.name as trackName,
-      upid,
-      process.pid,
-      process.name as processName
-    from process_counter_track
-    join process using(upid);
+      select
+        process_counter_track.id as trackId,
+        process_counter_track.name as trackName,
+        upid,
+        process.pid,
+        process.name as processName
+      from process_counter_track
+      join process using(upid);
   `);
     const it = result.iter({
       trackId: NUM,
@@ -1113,7 +1006,7 @@
       const trackId = it.trackId;
       const trackName = it.trackName;
       const processName = it.processName;
-      const uuid = this.getUuid(0, upid);
+      const uuid = this.getUuid(null, upid);
       const name = getTrackName({
         name: trackName,
         upid,
@@ -1135,13 +1028,13 @@
 
   async addProcessHeapProfileTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-    select distinct(upid) from heap_profile_allocation
-    union
-    select distinct(upid) from heap_graph_object
+      select upid
+      from _process_available_info_summary
+      where allocation_count > 0 or graph_object_count > 0
   `);
     for (const it = result.iter({upid: NUM}); it.valid(); it.next()) {
       const upid = it.upid;
-      const uuid = this.getUuid(0, upid);
+      const uuid = this.getUuid(null, upid);
       this.tracksToAdd.push({
         uri: `perfetto.HeapProfile#${upid}`,
         trackSortKey: PrimaryTrackSortKey.HEAP_PROFILE_TRACK,
@@ -1153,14 +1046,15 @@
 
   async addProcessPerfSamplesTracks(engine: EngineProxy): Promise<void> {
     const result = await engine.query(`
-      select distinct upid, pid
-      from perf_sample join thread using (utid) join process using (upid)
-      where callsite_id is not null
+      select upid, pid
+      from _process_available_info_summary
+      join process using (upid)
+      where perf_sample_count > 0
   `);
     for (const it = result.iter({upid: NUM, pid: NUM}); it.valid(); it.next()) {
       const upid = it.upid;
       const pid = it.pid;
-      const uuid = this.getUuid(0, upid);
+      const uuid = this.getUuid(null, upid);
       this.tracksToAdd.push({
         uri: `perfetto.PerfSamplesProfile#${upid}`,
         trackSortKey: PrimaryTrackSortKey.PERF_SAMPLES_PROFILE_TRACK,
@@ -1170,22 +1064,22 @@
     }
   }
 
-  getUuidUnchecked(utid: number, upid: number | null) {
+  getUuidUnchecked(utid: number | null, upid: number | null) {
     return upid === null
-      ? this.utidToUuid.get(utid)
+      ? this.utidToUuid.get(utid!)
       : this.upidToUuid.get(upid);
   }
 
-  getUuid(utid: number, upid: number | null) {
+  getUuid(utid: number | null, upid: number | null) {
     return assertExists(this.getUuidUnchecked(utid, upid));
   }
 
-  getOrCreateUuid(utid: number, upid: number | null) {
+  getOrCreateUuid(utid: number | null, upid: number | null) {
     let uuid = this.getUuidUnchecked(utid, upid);
     if (uuid === undefined) {
       uuid = uuidv4();
       if (upid === null) {
-        this.utidToUuid.set(utid, uuid);
+        this.utidToUuid.set(utid!, uuid);
       } else {
         this.upidToUuid.set(upid, uuid);
       }
@@ -1274,181 +1168,155 @@
     //  thread name
     //  utid
     const result = await engine.query(`
-    with candidateThreadsAndProcesses as materialized (
-      select upid, 0 as utid from process_track
-      union
-      select upid, 0 as utid from process_counter_track
-      union
-      select upid, utid from thread_counter_track join thread using(utid)
-      union
-      select upid, utid from thread_track join thread using(utid)
-      union
-      select upid, utid from (
-        select distinct utid from sched
-      ) join thread using(utid) group by utid
-      union
-      select upid, 0 as utid from (
-        select distinct utid from perf_sample where callsite_id is not null
-      ) join thread using (utid)
-      union
-      select upid, utid from (
-        select distinct utid from cpu_profile_stack_sample
-      ) join thread using(utid)
-      union
-      select upid as upid, 0 as utid from heap_profile_allocation
-      union
-      select upid as upid, 0 as utid from heap_graph_object
-    ),
-    schedSum as materialized (
-      select upid, sum(thread_total_dur) as total_dur
-      from (
-        select utid, sum(dur) as thread_total_dur
-        from sched where dur != -1 and utid != 0
-        group by utid
+      with processGroups as (
+        select
+          upid,
+          process.pid as pid,
+          process.name as processName,
+          sum_running_dur as sumRunningDur,
+          thread_slice_count + process_slice_count as sliceCount,
+          perf_sample_count as perfSampleCount,
+          allocation_count as heapProfileAllocationCount,
+          graph_object_count as heapGraphObjectCount,
+          (
+            select group_concat(string_value)
+            from args
+            where
+              process.arg_set_id is not null and
+              arg_set_id = process.arg_set_id and
+              flat_key = 'chrome.process_label'
+          ) chromeProcessLabels,
+          case process.name
+            when 'Browser' then 3
+            when 'Gpu' then 2
+            when 'Renderer' then 1
+            else 0
+          end as chromeProcessRank
+        from _process_available_info_summary
+        join process using(upid)
+      ),
+      threadGroups as (
+        select
+          utid,
+          tid,
+          thread.name as threadName,
+          sum_running_dur as sumRunningDur,
+          slice_count as sliceCount,
+          perf_sample_count as perfSampleCount
+        from _thread_available_info_summary
+        join thread using (utid)
+        where upid is null
       )
-      join thread using (utid)
-      group by upid
-    ),
-    sliceSum as materialized (
-      select
-        process.upid as upid,
-        sum(cnt) as sliceCount
-      from (select track_id, count(*) as cnt from slice group by track_id)
-        left join thread_track on track_id = thread_track.id
-        left join thread on thread_track.utid = thread.utid
-        left join process_track on track_id = process_track.id
-        join process on process.upid = thread.upid
-          or process_track.upid = process.upid
-      where process.upid is not null
-      group by process.upid
-    )
-    select
-      the_tracks.upid,
-      the_tracks.utid,
-      total_dur as hasSched,
-      hasHeapProfiles,
-      process.pid as pid,
-      thread.tid as tid,
-      process.name as processName,
-      thread.name as threadName,
-      package_list.debuggable as isDebuggable,
-      ifnull((
-        select group_concat(string_value)
-        from args
-        where
-          process.arg_set_id is not null and
-          arg_set_id = process.arg_set_id and
-          flat_key = 'chrome.process_label'
-      ), '') AS chromeProcessLabels,
-      (case process.name
-         when 'Browser' then 3
-         when 'Gpu' then 2
-         when 'Renderer' then 1
-         else 0
-      end) as chromeProcessRank
-    from candidateThreadsAndProcesses the_tracks
-    left join schedSum using(upid)
-    left join (
-      select
-        distinct(upid) as upid,
-        true as hasHeapProfiles
-      from heap_profile_allocation
-      union
-      select
-        distinct(upid) as upid,
-        true as hasHeapProfiles
-      from heap_graph_object
-    ) using (upid)
-    left join (
-      select
-        thread.upid as upid,
-        sum(cnt) as perfSampleCount
+      select *
       from (
-          select utid, count(*) as cnt
-          from perf_sample where callsite_id is not null
-          group by utid
-      ) join thread using (utid)
-      group by thread.upid
-    ) using (upid)
-    left join sliceSum using (upid)
-    left join thread using(utid)
-    left join process using(upid)
-    left join package_list using(uid)
-    order by
-      chromeProcessRank desc,
-      hasHeapProfiles desc,
-      perfSampleCount desc,
-      total_dur desc,
-      sliceCount desc,
-      processName asc nulls last,
-      the_tracks.upid asc nulls last,
-      threadName asc nulls last,
-      the_tracks.utid asc nulls last;
+        select
+          upid,
+          null as utid,
+          pid,
+          null as tid,
+          processName,
+          null as threadName,
+          sumRunningDur > 0 as hasSched,
+          heapProfileAllocationCount > 0
+            or heapGraphObjectCount > 0 as hasHeapInfo,
+          ifnull(chromeProcessLabels, '') as chromeProcessLabels
+        from processGroups
+        order by
+          chromeProcessRank desc,
+          heapProfileAllocationCount desc,
+          heapGraphObjectCount desc,
+          perfSampleCount desc,
+          sumRunningDur desc,
+          sliceCount desc,
+          processName asc,
+          upid asc
+      )
+      union all
+      select *
+      from (
+        select
+          null,
+          utid,
+          null as pid,
+          tid,
+          null as processName,
+          threadName,
+          sumRunningDur > 0 as hasSched,
+          0 as hasHeapInfo,
+          '' as chromeProcessLabels
+        from threadGroups
+        order by
+          perfSampleCount desc,
+          sumRunningDur desc,
+          sliceCount desc,
+          threadName asc,
+          utid asc
+      )
   `);
 
     const it = result.iter({
-      utid: NUM,
       upid: NUM_NULL,
-      tid: NUM_NULL,
+      utid: NUM_NULL,
       pid: NUM_NULL,
-      threadName: STR_NULL,
+      tid: NUM_NULL,
       processName: STR_NULL,
+      threadName: STR_NULL,
       hasSched: NUM_NULL,
-      hasHeapProfiles: NUM_NULL,
+      hasHeapInfo: NUM_NULL,
       chromeProcessLabels: STR,
     });
     for (; it.valid(); it.next()) {
       const utid = it.utid;
-      const tid = it.tid;
       const upid = it.upid;
       const pid = it.pid;
+      const tid = it.tid;
       const threadName = it.threadName;
       const processName = it.processName;
       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
       const hasSched = !!it.hasSched;
       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
-      const hasHeapProfiles = !!it.hasHeapProfiles;
+      const hasHeapInfo = !!it.hasHeapInfo;
 
-      // Group by upid if present else by utid.
-      let pUuid =
-        upid === null ? this.utidToUuid.get(utid) : this.upidToUuid.get(upid);
-      // These should only happen once for each track group.
-      if (pUuid === undefined) {
-        pUuid = this.getOrCreateUuid(utid, upid);
-        const summaryTrackKey = uuidv4();
-        const type = hasSched ? 'schedule' : 'summary';
-        const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
+      const summaryTrackKey = uuidv4();
+      const type = hasSched ? 'schedule' : 'summary';
+      const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
 
-        this.tracksToAdd.push({
-          uri,
-          key: summaryTrackKey,
-          trackSortKey: hasSched
-            ? PrimaryTrackSortKey.PROCESS_SCHEDULING_TRACK
-            : PrimaryTrackSortKey.PROCESS_SUMMARY_TRACK,
-          name: `${upid === null ? tid : pid} summary`,
-          labels: it.chromeProcessLabels.split(','),
-        });
-
-        const name = getTrackName({
-          utid,
-          processName,
-          pid,
-          threadName,
-          tid,
-          upid,
-        });
-        const addTrackGroup = Actions.addTrackGroup({
-          summaryTrackKey,
-          name,
-          id: pUuid,
-          // Perf profiling tracks remain collapsed, otherwise we would have too
-          // many expanded process tracks for some perf traces, leading to
-          // jankyness.
-          collapsed: !hasHeapProfiles,
-        });
-
-        this.addTrackGroupActions.push(addTrackGroup);
+      // If previous groupings (e.g. kernel threads) picked up there tracks,
+      // don't try to regroup them.
+      const pUuid =
+        upid === null ? this.utidToUuid.get(utid!) : this.upidToUuid.get(upid);
+      if (pUuid !== undefined) {
+        continue;
       }
+
+      this.tracksToAdd.push({
+        uri,
+        key: summaryTrackKey,
+        trackSortKey: hasSched
+          ? PrimaryTrackSortKey.PROCESS_SCHEDULING_TRACK
+          : PrimaryTrackSortKey.PROCESS_SUMMARY_TRACK,
+        name: `${upid === null ? tid : pid} summary`,
+        labels: it.chromeProcessLabels.split(','),
+      });
+
+      const name = getTrackName({
+        utid,
+        processName,
+        pid,
+        threadName,
+        tid,
+        upid,
+      });
+      const addTrackGroup = Actions.addTrackGroup({
+        summaryTrackKey,
+        name,
+        id: this.getOrCreateUuid(utid, upid),
+        // Perf profiling tracks remain collapsed, otherwise we would have too
+        // many expanded process tracks for some perf traces, leading to
+        // jankyness.
+        collapsed: !hasHeapInfo,
+      });
+      this.addTrackGroupActions.push(addTrackGroup);
     }
   }
 
diff --git a/ui/src/core/timeline_cache.ts b/ui/src/core/timeline_cache.ts
index 30d1cd3..fe84876 100644
--- a/ui/src/core/timeline_cache.ts
+++ b/ui/src/core/timeline_cache.ts
@@ -13,7 +13,6 @@
 // limitations under the License.
 
 import {BigintMath} from '../base/bigint_math';
-import {assertTrue} from '../base/logging';
 import {duration, time, Time} from '../base/time';
 
 export const BUCKETS_PER_PIXEL = 2;
@@ -123,63 +122,3 @@
     return `CacheKey<${start}, ${end}, ${bucket}, ${size}>`;
   }
 }
-
-interface CacheItem<T> {
-  t: T;
-  lastAccessId: number;
-}
-
-// LRU cache for the timeline.
-// T is all the data needed for a displaying the track in a given
-// CacheKey area - generally an array of slices.
-export class TimelineCache<T> {
-  private cacheSize: number;
-  private cache: Map<string, CacheItem<T>>;
-  private lastAccessId: number;
-
-  constructor(cacheSize: number) {
-    assertTrue(cacheSize >= 2);
-    this.cacheSize = cacheSize;
-    this.cache = new Map();
-    this.lastAccessId = 0;
-  }
-
-  invalidate() {
-    this.cache.clear();
-  }
-
-  insert(cacheKey: CacheKey, t: T): void {
-    assertTrue(cacheKey.isNormalized());
-    const key = cacheKey.toString();
-    this.cache.set(key, {
-      t,
-      lastAccessId: this.lastAccessId++,
-    });
-    this.updateLru();
-  }
-
-  lookup(cacheKey: CacheKey): undefined | T {
-    assertTrue(cacheKey.isNormalized());
-    const key = cacheKey.toString();
-    const item = this.cache.get(key);
-    if (item) {
-      item.lastAccessId = this.lastAccessId++;
-      this.updateLru();
-    }
-    return item === undefined ? undefined : item.t;
-  }
-
-  private updateLru(): void {
-    while (this.cache.size > this.cacheSize) {
-      let oldestKey = '';
-      let oldestAccessId = Number.MAX_SAFE_INTEGER;
-      for (const [k, v] of this.cache.entries()) {
-        if (v.lastAccessId < oldestAccessId) {
-          oldestAccessId = v.lastAccessId;
-          oldestKey = k;
-        }
-      }
-      this.cache.delete(oldestKey);
-    }
-  }
-}
diff --git a/ui/src/core/timeline_cache_unittest.ts b/ui/src/core/timeline_cache_unittest.ts
index 227c19d..c41fb64 100644
--- a/ui/src/core/timeline_cache_unittest.ts
+++ b/ui/src/core/timeline_cache_unittest.ts
@@ -14,7 +14,7 @@
 
 import {Time} from '../base/time';
 
-import {CacheKey, TimelineCache} from './timeline_cache';
+import {CacheKey} from './timeline_cache';
 
 test('cacheKeys', () => {
   const k = CacheKey.create(Time.fromRaw(201n), Time.fromRaw(302n), 123);
@@ -29,62 +29,3 @@
   expect(n.bucketSize).toBeGreaterThanOrEqual(k.bucketSize);
   expect(Math.abs(n.windowSizePx - k.windowSizePx)).toBeLessThanOrEqual(200);
 });
-
-test('cache', () => {
-  const key1 = CacheKey.create(
-    Time.fromRaw(1000n),
-    Time.fromRaw(1100n),
-    100,
-  ).normalize();
-  const key2 = CacheKey.create(
-    Time.fromRaw(2000n),
-    Time.fromRaw(2100n),
-    100,
-  ).normalize();
-  const key3 = CacheKey.create(
-    Time.fromRaw(3000n),
-    Time.fromRaw(3100n),
-    100,
-  ).normalize();
-  const key4 = CacheKey.create(
-    Time.fromRaw(4000n),
-    Time.fromRaw(4100n),
-    100,
-  ).normalize();
-  const key5 = CacheKey.create(
-    Time.fromRaw(5000n),
-    Time.fromRaw(5100n),
-    100,
-  ).normalize();
-  const key6 = CacheKey.create(
-    Time.fromRaw(6000n),
-    Time.fromRaw(6100n),
-    100,
-  ).normalize();
-  const key7 = CacheKey.create(
-    Time.fromRaw(7000n),
-    Time.fromRaw(7100n),
-    100,
-  ).normalize();
-  const cache = new TimelineCache<string>(5);
-
-  cache.insert(key1, 'v1');
-  expect(cache.lookup(key1)).toEqual('v1');
-
-  cache.insert(key2, 'v2');
-  cache.insert(key3, 'v3');
-  cache.insert(key4, 'v4');
-  cache.insert(key5, 'v5');
-
-  // Should push key1/v1 out of the cache:
-  cache.insert(key6, 'v6');
-  expect(cache.lookup(key1)).toEqual(undefined);
-
-  // Access key2 then add one more entry:
-  expect(cache.lookup(key2)).toEqual('v2');
-  cache.insert(key7, 'v7');
-
-  // key2/v2 should still be present but key3/v3 should be discarded:
-  expect(cache.lookup(key2)).toEqual('v2');
-  expect(cache.lookup(key3)).toEqual(undefined);
-});
diff --git a/ui/src/frontend/app.ts b/ui/src/frontend/app.ts
index 0f11c59..dc65d19 100644
--- a/ui/src/frontend/app.ts
+++ b/ui/src/frontend/app.ts
@@ -414,7 +414,7 @@
     },
     {
       id: 'perfetto.ShowSliceTable',
-      name: 'Show slice table',
+      name: 'Open new slice table tab',
       callback: () => {
         addSqlTableTab({
           table: SqlTables.slice,
@@ -452,13 +452,13 @@
     },
     {
       id: 'perfetto.OpenCommandPalette',
-      name: 'Open Command Palette',
+      name: 'Open command palette',
       callback: () => this.enterCommandMode(),
       defaultHotkey: '!Mod+Shift+P',
     },
     {
       id: 'perfetto.RunQuery',
-      name: 'Run Query',
+      name: 'Run query',
       callback: () => this.enterQueryMode(),
       defaultHotkey: '!Mod+O',
     },
@@ -545,7 +545,7 @@
     },
     {
       id: 'perfetto.FocusSelection',
-      name: 'Focus selection',
+      name: 'Focus current selection',
       callback: () => findCurrentSelection(),
       defaultHotkey: 'F',
     },
diff --git a/ui/src/frontend/base_counter_track.ts b/ui/src/frontend/base_counter_track.ts
index 9996782..91b0939 100644
--- a/ui/src/frontend/base_counter_track.ts
+++ b/ui/src/frontend/base_counter_track.ts
@@ -17,7 +17,7 @@
 import {searchSegment} from '../base/binary_search';
 import {Disposable, NullDisposable} from '../base/disposable';
 import {assertTrue, assertUnreachable} from '../base/logging';
-import {duration, Time, time} from '../base/time';
+import {Time, time} from '../base/time';
 import {drawTrackHoverTooltip} from '../common/canvas_utils';
 import {raf} from '../core/raf_scheduler';
 import {EngineProxy, LONG, NUM, Track} from '../public';
@@ -27,10 +27,10 @@
 import {checkerboardExcept} from './checkerboard';
 import {globals} from './globals';
 import {PanelSize} from './panel';
-import {constraintsToQuerySuffix} from './sql_utils';
 import {NewTrackArgs} from './track';
-import {CacheKey, TimelineCache} from '../core/timeline_cache';
+import {CacheKey} from '../core/timeline_cache';
 import {featureFlags} from '../core/feature_flags';
+import {uuidv4Sql} from '../base/uuid';
 
 export const COUNTER_DEBUG_MENU_ITEMS = featureFlags.register({
   id: 'counterDebugMenuItems',
@@ -128,8 +128,6 @@
 
 interface CounterData {
   timestamps: BigInt64Array;
-  counts: Uint32Array;
-  avgValues: Float64Array;
   minDisplayValues: Float64Array;
   maxDisplayValues: Float64Array;
   lastDisplayValues: Float64Array;
@@ -142,13 +140,10 @@
 interface CounterLimits {
   maxDisplayValue: number;
   minDisplayValue: number;
-  maxDurNs: duration;
 }
 
 interface CounterTooltipState {
   lastDisplayValue: number;
-  avgValue: number;
-  count: number;
   ts: time;
   tsEnd?: time;
 }
@@ -201,22 +196,19 @@
 export abstract class BaseCounterTrack implements Track {
   protected engine: EngineProxy;
   protected trackKey: string;
+  protected trackUuid = uuidv4Sql();
 
   // This is the over-skirted cached bounds:
   private countersKey: CacheKey = CacheKey.zero();
 
   private counters: CounterData = {
     timestamps: new BigInt64Array(0),
-    counts: new Uint32Array(0),
-    avgValues: new Float64Array(0),
     minDisplayValues: new Float64Array(0),
     maxDisplayValues: new Float64Array(0),
     lastDisplayValues: new Float64Array(0),
     displayValueRange: [0, 0],
   };
 
-  private cache: TimelineCache<CounterData> = new TimelineCache(5);
-
   // Cleanup hook for onInit.
   private initState?: Disposable;
 
@@ -427,12 +419,9 @@
 
   protected invalidate() {
     this.limits = undefined;
-    this.cache.invalidate();
     this.countersKey = CacheKey.zero();
     this.counters = {
       timestamps: new BigInt64Array(0),
-      counts: new Uint32Array(0),
-      avgValues: new Float64Array(0),
       minDisplayValues: new Float64Array(0),
       maxDisplayValues: new Float64Array(0),
       lastDisplayValues: new Float64Array(0),
@@ -462,6 +451,33 @@
 
   async onCreate(): Promise<void> {
     this.initState = await this.onInit();
+
+    const displayValueQuery = await this.engine.query(`
+        create virtual table ${this.getTableName()}
+        using __intrinsic_counter_mipmap((
+          SELECT
+            ts,
+            ${this.getValueExpression()} as value
+          FROM (${this.getSqlSource()})
+        ));
+
+        select
+          min_value as minDisplayValue,
+          max_value as maxDisplayValue
+        from ${this.getTableName()}(
+          trace_start(), trace_end(), trace_dur()
+        );
+      `);
+
+    const {minDisplayValue, maxDisplayValue} = displayValueQuery.firstRow({
+      minDisplayValue: NUM,
+      maxDisplayValue: NUM,
+    });
+
+    this.limits = {
+      minDisplayValue,
+      maxDisplayValue,
+    };
   }
 
   async onUpdate(): Promise<void> {
@@ -479,10 +495,7 @@
   }
 
   render(ctx: CanvasRenderingContext2D, size: PanelSize) {
-    const {
-      visibleTimeScale: timeScale,
-      // visibleWindowTime: vizTime,
-    } = globals.timeline;
+    const {visibleTimeScale: timeScale} = globals.timeline;
 
     // In any case, draw whatever we have (which might be stale/incomplete).
 
@@ -490,11 +503,17 @@
     const data = this.counters;
 
     if (data.timestamps.length === 0 || limits === undefined) {
+      checkerboardExcept(
+        ctx,
+        this.getHeight(),
+        0,
+        size.width,
+        timeScale.timeToPx(this.countersKey.start),
+        timeScale.timeToPx(this.countersKey.end),
+      );
       return;
     }
 
-    assertTrue(data.timestamps.length === data.counts.length);
-    assertTrue(data.timestamps.length === data.avgValues.length);
     assertTrue(data.timestamps.length === data.minDisplayValues.length);
     assertTrue(data.timestamps.length === data.maxDisplayValues.length);
     assertTrue(data.timestamps.length === data.lastDisplayValues.length);
@@ -520,6 +539,7 @@
       zeroY = effectiveHeight * (yMax / (yMax - yMin)) + MARGIN_TOP;
     }
 
+    // Use hue to differentiate the scale of the counter value
     const exp = Math.ceil(Math.log10(Math.max(yMax, 1)));
     const expCapped = Math.min(exp - 3, 9);
     const hue = (180 - Math.floor(expCapped * (180 / 6)) + 360) % 360;
@@ -540,11 +560,11 @@
 
     ctx.beginPath();
     const timestamp = Time.fromRaw(timestamps[0]);
-    ctx.moveTo(calculateX(timestamp), zeroY);
+    ctx.moveTo(Math.max(0, calculateX(timestamp)), zeroY);
     let lastDrawnY = zeroY;
     for (let i = 0; i < timestamps.length; i++) {
       const timestamp = Time.fromRaw(timestamps[i]);
-      const x = calculateX(timestamp);
+      const x = Math.max(0, calculateX(timestamp));
       const minY = calculateY(minValues[i]);
       const maxY = calculateY(maxValues[i]);
       const lastY = calculateY(lastValues[i]);
@@ -581,7 +601,7 @@
 
     const hover = this.hover;
     if (hover !== undefined) {
-      let text = `${hover.avgValue.toLocaleString()}`;
+      let text = `${hover.lastDisplayValue.toLocaleString()}`;
 
       const unit = this.unit;
       switch (options.yMode) {
@@ -599,14 +619,11 @@
           break;
       }
 
-      if (hover.count > 1) {
-        text += ` (avg of ${hover.count})`;
-      }
-
       ctx.fillStyle = `hsl(${hue}, 45%, 75%)`;
       ctx.strokeStyle = `hsl(${hue}, 45%, 45%)`;
 
-      const xStart = Math.floor(timeScale.timeToPx(hover.ts));
+      const rawXStart = calculateX(hover.ts);
+      const xStart = Math.max(0, rawXStart);
       const xEnd =
         hover.tsEnd === undefined
           ? endPx
@@ -626,17 +643,19 @@
       ctx.stroke();
       ctx.lineWidth = 1;
 
-      // Draw change marker.
-      ctx.beginPath();
-      ctx.arc(
-        xStart,
-        y,
-        3 /* r*/,
-        0 /* start angle*/,
-        2 * Math.PI /* end angle*/,
-      );
-      ctx.fill();
-      ctx.stroke();
+      // Draw change marker if it would be visible.
+      if (rawXStart >= -6) {
+        ctx.beginPath();
+        ctx.arc(
+          xStart,
+          y,
+          3 /* r*/,
+          0 /* start angle*/,
+          2 * Math.PI /* end angle*/,
+        );
+        ctx.fill();
+        ctx.stroke();
+      }
 
       // Draw the tooltip.
       drawTrackHoverTooltip(ctx, this.mousePos, this.getHeight(), text);
@@ -644,11 +663,11 @@
 
     // Write the Y scale on the top left corner.
     ctx.fillStyle = 'rgba(255, 255, 255, 0.6)';
-    ctx.fillRect(0, 0, 42, 16);
+    ctx.fillRect(0, 0, 42, 13);
     ctx.fillStyle = '#666';
     ctx.textAlign = 'left';
     ctx.textBaseline = 'alphabetic';
-    ctx.fillText(`${yLabel}`, 5, 14);
+    ctx.fillText(`${yLabel}`, 5, 11);
 
     // TODO(hjd): Refactor this into checkerboardExcept
     {
@@ -690,14 +709,10 @@
     const tsEnd =
       right === -1 ? undefined : Time.fromRaw(data.timestamps[right]);
     const lastDisplayValue = data.lastDisplayValues[left];
-    const count = data.counts[left];
-    const avgValue = data.avgValues[left];
     this.hover = {
       ts,
       tsEnd,
       lastDisplayValue,
-      count,
-      avgValue,
     };
   }
 
@@ -705,11 +720,14 @@
     this.hover = undefined;
   }
 
-  onDestroy(): void {
+  async onDestroy(): Promise<void> {
     if (this.initState) {
       this.initState.dispose();
       this.initState = undefined;
     }
+    if (this.engine.isAlive) {
+      await this.engine.query(`drop table if exists ${this.getTableName()}`);
+    }
   }
 
   // Compute the range of values to display and range label.
@@ -784,7 +802,6 @@
         break;
       default:
         assertUnreachable(options.yMode);
-        break;
     }
 
     if (options.yDisplay === 'log') {
@@ -800,11 +817,10 @@
   }
 
   // The underlying table has `ts` and `value` columns.
-  private getSqlPreamble(): string {
+  private getValueExpression(): string {
     const options = this.getCounterOptions();
 
     let valueExpr;
-
     switch (options.yMode) {
       case 'value':
         valueExpr = 'value';
@@ -818,64 +834,20 @@
         break;
       default:
         assertUnreachable(options.yMode);
-        break;
     }
 
-    let displayValueExpr = valueExpr;
     if (options.yDisplay === 'log') {
-      displayValueExpr = `ifnull(ln(${displayValueExpr}), 0)`;
+      return `ifnull(ln(${valueExpr}), 0)`;
+    } else {
+      return valueExpr;
     }
+  }
 
-    return `
-      WITH data AS (
-        SELECT
-          ts,
-          ${valueExpr} as value,
-          ${displayValueExpr} as displayValue
-        FROM (${this.getSqlSource()})
-      )
-    `;
+  private getTableName(): string {
+    return `counter_${this.trackUuid}`;
   }
 
   private async maybeRequestData(rawCountersKey: CacheKey) {
-    let limits = this.limits;
-    if (limits === undefined) {
-      const maxDurQuery = await this.engine.query(`
-        ${this.getSqlPreamble()}
-        SELECT
-          max(dur) as maxDur
-        FROM (
-          SELECT
-            lead(ts, 1, ts) over (order by ts) - ts as dur
-          FROM data
-        )
-      `);
-      const maxDurRow = maxDurQuery.firstRow({
-        maxDur: LONG,
-      });
-      const maxDurNs = maxDurRow.maxDur;
-
-      const displayValueQuery = await this.engine.query(`
-        ${this.getSqlPreamble()}
-        SELECT
-          max(displayValue) as maxDisplayValue,
-          min(displayValue) as minDisplayValue
-        FROM data
-      `);
-      const displayValueRow = displayValueQuery.firstRow({
-        minDisplayValue: NUM,
-        maxDisplayValue: NUM,
-      });
-
-      const minDisplayValue = displayValueRow.minDisplayValue;
-      const maxDisplayValue = displayValueRow.maxDisplayValue;
-      limits = this.limits = {
-        minDisplayValue,
-        maxDisplayValue,
-        maxDurNs,
-      };
-    }
-
     if (rawCountersKey.isCoveredBy(this.countersKey)) {
       return; // We have the data already, no need to re-query.
     }
@@ -887,42 +859,21 @@
       );
     }
 
-    const maybeCachedCounters = this.cache.lookup(countersKey);
-    if (maybeCachedCounters) {
-      this.countersKey = countersKey;
-      this.counters = maybeCachedCounters;
-      return;
-    }
-
-    const bucketNs = countersKey.bucketSize;
-
-    const constraint = constraintsToQuerySuffix({
-      filters: [
-        `ts >= ${countersKey.start} - ${limits.maxDurNs}`,
-        `ts <= ${countersKey.end}`,
-        `value is not null`,
-      ],
-      groupBy: ['tsq'],
-      orderBy: ['tsq'],
-    });
-
     const queryRes = await this.engine.query(`
-      ${this.getSqlPreamble()}
       SELECT
-        (ts + ${bucketNs / 2n}) / ${bucketNs} * ${bucketNs} as tsq,
-        count(value) as count,
-        avg(value) as avgValue,
-        min(displayValue) as minDisplayValue,
-        max(displayValue) as maxDisplayValue,
-        value_at_max_ts(ts, displayValue) as lastDisplayValue
-      FROM data
-      ${constraint}
+        min_value as minDisplayValue,
+        max_value as maxDisplayValue,
+        last_ts as ts,
+        last_value as lastDisplayValue
+      FROM ${this.getTableName()}(
+        ${countersKey.start},
+        ${countersKey.end},
+        ${countersKey.bucketSize}
+      );
     `);
 
     const it = queryRes.iter({
-      tsq: LONG,
-      count: NUM,
-      avgValue: NUM,
+      ts: LONG,
       minDisplayValue: NUM,
       maxDisplayValue: NUM,
       lastDisplayValue: NUM,
@@ -931,8 +882,6 @@
     const numRows = queryRes.numRows();
     const data: CounterData = {
       timestamps: new BigInt64Array(numRows),
-      counts: new Uint32Array(numRows),
-      avgValues: new Float64Array(numRows),
       minDisplayValues: new Float64Array(numRows),
       maxDisplayValues: new Float64Array(numRows),
       lastDisplayValues: new Float64Array(numRows),
@@ -942,10 +891,7 @@
     let min = 0;
     let max = 0;
     for (let row = 0; it.valid(); it.next(), row++) {
-      const ts = Time.fromRaw(it.tsq);
-      data.timestamps[row] = ts;
-      data.counts[row] = it.count;
-      data.avgValues[row] = it.avgValue;
+      data.timestamps[row] = Time.fromRaw(it.ts);
       data.minDisplayValues[row] = it.minDisplayValue;
       data.maxDisplayValues[row] = it.maxDisplayValue;
       data.lastDisplayValues[row] = it.lastDisplayValue;
@@ -955,7 +901,6 @@
 
     data.displayValueRange = [min, max];
 
-    this.cache.insert(countersKey, data);
     this.countersKey = countersKey;
     this.counters = data;
 
diff --git a/ui/src/frontend/base_slice_track.ts b/ui/src/frontend/base_slice_track.ts
index ef3b60b..e4b03a2 100644
--- a/ui/src/frontend/base_slice_track.ts
+++ b/ui/src/frontend/base_slice_track.ts
@@ -39,13 +39,9 @@
 import {globals} from './globals';
 import {PanelSize} from './panel';
 import {DEFAULT_SLICE_LAYOUT, SliceLayout} from './slice_layout';
-import {constraintsToQuerySuffix} from './sql_utils';
 import {NewTrackArgs} from './track';
-import {
-  BUCKETS_PER_PIXEL,
-  CacheKey,
-  TimelineCache,
-} from '../core/timeline_cache';
+import {BUCKETS_PER_PIXEL, CacheKey} from '../core/timeline_cache';
+import {uuidv4Sql} from '../base/uuid';
 
 // The common class that underpins all tracks drawing slices.
 
@@ -125,13 +121,11 @@
   // to the right).
   // Since the slices are sorted by startS we can check this easily:
   const maybeFirstSlice: S | undefined = slices[0];
-  if (exists(maybeFirstSlice) && maybeFirstSlice.startNsQ > end) {
+  if (exists(maybeFirstSlice) && maybeFirstSlice.startNs > end) {
     return [];
   }
 
-  return slices.filter(
-    (slice) => slice.startNsQ <= end && slice.endNsQ >= start,
-  );
+  return slices.filter((slice) => slice.startNs <= end && slice.endNs >= start);
 }
 
 export const filterVisibleSlicesForTesting = filterVisibleSlices;
@@ -148,10 +142,6 @@
   ts: LONG, // Start time in nanoseconds.
   dur: LONG, // Duration in nanoseconds. -1 = incomplete, 0 = instant.
   depth: NUM, // Vertical depth.
-
-  // These are computed by the base class:
-  tsq: LONG, // Quantized |ts|. This class owns the quantization logic.
-  tsqEnd: LONG, // Quantized |ts+dur|. The end bucket.
 };
 
 export type BaseRow = typeof BASE_ROW;
@@ -185,6 +175,7 @@
   protected sliceLayout: SliceLayout = {...DEFAULT_SLICE_LAYOUT};
   protected engine: EngineProxy;
   protected trackKey: string;
+  protected trackUuid = uuidv4Sql();
 
   // This is the over-skirted cached bounds:
   private slicesKey: CacheKey = CacheKey.zero();
@@ -192,17 +183,11 @@
   // This is the currently 'cached' slices:
   private slices = new Array<CastInternal<T['slice']>>();
 
-  // This is the slices cache:
-  private cache: TimelineCache<Array<CastInternal<T['slice']>>> =
-    new TimelineCache(5);
-
-  private hasOneOffData: boolean = false;
   // Incomplete slices (dur = -1). Rather than adding a lot of logic to
   // the SQL queries to handle this case we materialise them one off
   // then unconditionally render them. This should be efficient since
   // there are at most |depth| slices.
   private incomplete = new Array<CastInternal<T['slice']>>();
-  private maxDurNs: duration = 0n;
 
   // The currently selected slice.
   // TODO(hjd): We should fetch this from the underlying data rather
@@ -324,8 +309,67 @@
     return `${size}px Roboto Condensed`;
   }
 
+  private getTableName(): string {
+    return `slice_${this.trackUuid}`;
+  }
+
   async onCreate(): Promise<void> {
     this.initState = await this.onInit();
+
+    // TODO(hjd): Consider case below:
+    // raw:
+    // 0123456789
+    //   [A     did not end)
+    //     [B ]
+    //
+    //
+    // quantised:
+    // 0123456789
+    //   [A     did not end)
+    // [     B  ]
+    // Does it lead to odd results?
+    const extraCols = this.extraSqlColumns.join(',');
+    let queryRes;
+    if (CROP_INCOMPLETE_SLICE_FLAG.get()) {
+      queryRes = await this.engine.query(`
+          select
+            ${this.depthColumn()},
+            ts,
+            -1 as dur,
+            id
+            ${extraCols ? ',' + extraCols : ''}
+          from (${this.getSqlSource()})
+          where dur = -1;
+        `);
+    } else {
+      queryRes = await this.engine.query(`
+        select
+          ${this.depthColumn()},
+          max(ts) as ts,
+          -1 as dur,
+          id
+          ${extraCols ? ',' + extraCols : ''}
+        from (${this.getSqlSource()})
+        where dur = -1
+        group by 1
+      `);
+    }
+    const incomplete = new Array<CastInternal<T['slice']>>(queryRes.numRows());
+    const it = queryRes.iter(this.getRowSpec());
+    for (let i = 0; it.valid(); it.next(), ++i) {
+      incomplete[i] = this.rowToSliceInternal(it);
+    }
+    this.onUpdatedSlices(incomplete);
+    this.incomplete = incomplete;
+
+    await this.engine.query(`
+      create virtual table ${this.getTableName()}
+      using __intrinsic_slice_mipmap((
+        select id, ts, dur, ${this.depthColumn()}
+        from (${this.getSqlSource()})
+        where dur != -1
+      ));
+    `);
   }
 
   async onUpdate(): Promise<void> {
@@ -394,8 +438,8 @@
       // partially visible. This might end up with a negative x if the
       // slice starts before the visible time or with a width that overflows
       // pxEnd.
-      slice.x = timeScale.timeToPx(slice.startNsQ);
-      slice.w = timeScale.durationToPx(slice.durNsQ);
+      slice.x = timeScale.timeToPx(slice.startNs);
+      slice.w = timeScale.durationToPx(slice.durNs);
 
       if (slice.flags & SLICE_FLAGS_INSTANT) {
         // In the case of an instant slice, set the slice geometry on the
@@ -611,82 +655,20 @@
     } // if (hoveredSlice)
   }
 
-  onDestroy() {
+  async onDestroy(): Promise<void> {
     if (this.initState) {
       this.initState.dispose();
       this.initState = undefined;
     }
+    if (this.engine.isAlive) {
+      await this.engine.execute(`drop table ${this.getTableName()}`);
+    }
   }
 
   // This method figures out if the visible window is outside the bounds of
   // the cached data and if so issues new queries (i.e. sorta subsumes the
   // onBoundsChange).
   private async maybeRequestData(rawSlicesKey: CacheKey) {
-    if (!this.hasOneOffData) {
-      // TODO(hjd): This could be done in onInit maybe?
-      const queryRes = await this.engine.query(`select
-          ifnull(max(dur), 0) as maxDur, count(1) as rowCount
-          from (${this.getSqlSource()})`);
-      const row = queryRes.firstRow({maxDur: LONG, rowCount: NUM});
-      this.maxDurNs = row.maxDur;
-
-      {
-        // TODO(hjd): Consider case below:
-        // raw:
-        // 0123456789
-        //   [A     did not end)
-        //     [B ]
-        //
-        //
-        // quantised:
-        // 0123456789
-        //   [A     did not end)
-        // [     B  ]
-        // Does it lead to odd results?
-        const extraCols = this.extraSqlColumns.join(',');
-        let queryRes;
-        if (CROP_INCOMPLETE_SLICE_FLAG.get()) {
-          queryRes = await this.engine.query(`
-            select
-              ${this.depthColumn()},
-              ts as tsq,
-              ts as tsqEnd,
-              ts,
-              -1 as dur,
-              id
-              ${extraCols ? ',' + extraCols : ''}
-            from (${this.getSqlSource()})
-            where dur = -1;
-          `);
-        } else {
-          queryRes = await this.engine.query(`
-            select
-              ${this.depthColumn()},
-              max(ts) as tsq,
-              max(ts) as tsqEnd,
-              max(ts) as ts,
-              -1 as dur,
-              id
-              ${extraCols ? ',' + extraCols : ''}
-            from (${this.getSqlSource()})
-            group by 1
-            having dur = -1;
-          `);
-        }
-        const incomplete = new Array<CastInternal<T['slice']>>(
-          queryRes.numRows(),
-        );
-        const it = queryRes.iter(this.getRowSpec());
-        for (let i = 0; it.valid(); it.next(), ++i) {
-          incomplete[i] = this.rowToSliceInternal(it);
-        }
-        this.onUpdatedSlices(incomplete);
-        this.incomplete = incomplete;
-      }
-
-      this.hasOneOffData = true;
-    }
-
     if (rawSlicesKey.isCoveredBy(this.slicesKey)) {
       return; // We have the data already, no need to re-query
     }
@@ -699,52 +681,20 @@
       );
     }
 
-    const maybeCachedSlices = this.cache.lookup(slicesKey);
-    if (maybeCachedSlices) {
-      this.slicesKey = slicesKey;
-      this.onUpdatedSlices(maybeCachedSlices);
-      this.slices = maybeCachedSlices;
-      return;
-    }
-
-    const bucketNs = slicesKey.bucketSize;
-    let queryTsq;
-    let queryTsqEnd;
-    // When we're zoomed into the level of single ns there is no point
-    // doing quantization (indeed it causes bad artifacts) so instead
-    // we use ts / ts+dur directly.
-    if (bucketNs === 1n) {
-      queryTsq = 'ts';
-      queryTsqEnd = 'ts + dur';
-    } else {
-      queryTsq = `(ts + ${bucketNs / 2n}) / ${bucketNs} * ${bucketNs}`;
-      queryTsqEnd = `(ts + dur + ${bucketNs / 2n}) / ${bucketNs} * ${bucketNs}`;
-    }
-
     const extraCols = this.extraSqlColumns.join(',');
-    const maybeDepth = this.isFlat() ? undefined : 'depth';
-
-    const constraint = constraintsToQuerySuffix({
-      filters: [
-        `ts >= ${slicesKey.start - this.maxDurNs}`,
-        `ts <= ${slicesKey.end}`,
-      ],
-      groupBy: [maybeDepth, 'tsq'],
-      orderBy: [maybeDepth, 'tsq'],
-    });
-
-    // TODO(hjd): Count and expose the number of slices summarized in
-    // each bucket?
     const queryRes = await this.engine.query(`
       SELECT
-        ${queryTsq} AS tsq,
-        ${queryTsqEnd} AS tsqEnd,
-        ts,
-        MAX(dur) AS dur,
-        id,
-        ${this.depthColumn()}
+        (z.ts / ${rawSlicesKey.bucketSize}) * ${rawSlicesKey.bucketSize} as ts,
+        iif(s.dur = -1, s.dur, max(z.dur, ${rawSlicesKey.bucketSize})) as dur,
+        s.id,
+        z.depth
         ${extraCols ? ',' + extraCols : ''}
-      FROM (${this.getSqlSource()}) ${constraint}
+      FROM ${this.getTableName()}(
+        ${slicesKey.start},
+        ${slicesKey.end},
+        ${slicesKey.bucketSize}
+      ) z
+      CROSS JOIN (${this.getSqlSource()}) s using (id)
     `);
 
     // Here convert each row to a Slice. We do what we can do
@@ -768,7 +718,6 @@
     }
     this.maxDataDepth = maxDataDepth;
     this.onUpdatedSlices(slices);
-    this.cache.insert(slicesKey, slices);
     this.slices = slices;
 
     raf.scheduleRedraw();
@@ -789,8 +738,8 @@
   }
 
   rowToSlice(row: T['row']): T['slice'] {
-    const startNsQ = Time.fromRaw(row.tsq);
-    const endNsQ = Time.fromRaw(row.tsqEnd);
+    const startNs = Time.fromRaw(row.ts);
+    const endNs = Time.fromRaw(row.ts + row.dur);
     const ts = Time.fromRaw(row.ts);
     const dur: duration = row.dur;
 
@@ -803,9 +752,9 @@
 
     return {
       id: row.id,
-      startNsQ,
-      endNsQ,
-      durNsQ: endNsQ - startNsQ,
+      startNs,
+      endNs,
+      durNs: row.dur,
       ts,
       dur,
       flags,
@@ -846,7 +795,7 @@
     for (const slice of this.incomplete) {
       const visibleTimeScale = globals.timeline.visibleTimeScale;
       const startPx = CROP_INCOMPLETE_SLICE_FLAG.get()
-        ? visibleTimeScale.timeToPx(slice.startNsQ)
+        ? visibleTimeScale.timeToPx(slice.startNs)
         : slice.x;
       const cropUnfinishedSlicesCondition = CROP_INCOMPLETE_SLICE_FLAG.get()
         ? startPx + INCOMPLETE_SLICE_WIDTH_PX >= x
diff --git a/ui/src/frontend/base_slice_track_unittest.ts b/ui/src/frontend/base_slice_track_unittest.ts
index 196cc2e..4e8fd51 100644
--- a/ui/src/frontend/base_slice_track_unittest.ts
+++ b/ui/src/frontend/base_slice_track_unittest.ts
@@ -19,16 +19,16 @@
 import {filterVisibleSlicesForTesting as filterVisibleSlices} from './base_slice_track';
 
 function slice(start: number, duration: number, depth: number = 0): Slice {
-  const startNsQ = Time.fromRaw(BigInt(start));
-  const durNsQ = Time.fromRaw(BigInt(duration));
-  const endNsQ = Time.fromRaw(startNsQ + durNsQ);
+  const startNs = Time.fromRaw(BigInt(start));
+  const durNs = Time.fromRaw(BigInt(duration));
+  const endNs = Time.fromRaw(startNs + durNs);
   return {
     id: 42,
-    startNsQ,
-    endNsQ,
-    durNsQ,
-    ts: startNsQ,
-    dur: durNsQ,
+    startNs,
+    endNs,
+    durNs,
+    ts: startNs,
+    dur: durNs,
     depth,
     flags: 0,
     title: '',
diff --git a/ui/src/frontend/css_constants.ts b/ui/src/frontend/css_constants.ts
index 1a37c1e..f756136 100644
--- a/ui/src/frontend/css_constants.ts
+++ b/ui/src/frontend/css_constants.ts
@@ -23,7 +23,6 @@
 export let SELECTION_FILL_COLOR = '#8398e64d';
 export let OVERVIEW_TIMELINE_NON_VISIBLE_COLOR = '#c8c8c8cc';
 export let DEFAULT_DETAILS_CONTENT_HEIGHT = 280;
-export const SELECTED_LOG_ROWS_COLOR = '#D2EFE0';
 export let BACKGROUND_COLOR = '#ffffff';
 export let FOREGROUND_COLOR = '#222';
 export let COLLAPSED_BACKGROUND = '#ffffff';
diff --git a/ui/src/frontend/globals.ts b/ui/src/frontend/globals.ts
index 8fc392d..68e16a5 100644
--- a/ui/src/frontend/globals.ts
+++ b/ui/src/frontend/globals.ts
@@ -276,8 +276,8 @@
   private _publishRedraw?: () => void = undefined;
 
   private _currentSearchResults: CurrentSearchResults = {
-    sliceIds: new Float64Array(0),
-    tsStarts: new BigInt64Array(0),
+    eventIds: new Float64Array(0),
+    tses: new BigInt64Array(0),
     utids: new Float64Array(0),
     trackKeys: [],
     sources: [],
@@ -648,8 +648,8 @@
     this._numQueriesQueued = 0;
     this._metricResult = undefined;
     this._currentSearchResults = {
-      sliceIds: new Float64Array(0),
-      tsStarts: new BigInt64Array(0),
+      eventIds: new Float64Array(0),
+      tses: new BigInt64Array(0),
       utids: new Float64Array(0),
       trackKeys: [],
       sources: [],
diff --git a/ui/src/frontend/search_handler.ts b/ui/src/frontend/search_handler.ts
index d9e3f0d..3fcc178 100644
--- a/ui/src/frontend/search_handler.ts
+++ b/ui/src/frontend/search_handler.ts
@@ -13,8 +13,10 @@
 // limitations under the License.
 
 import {searchSegment} from '../base/binary_search';
+import {assertUnreachable} from '../base/logging';
 import {Actions} from '../common/actions';
 import {globals} from './globals';
+import {verticalScrollToTrack} from './scroll_helper';
 
 function setToPrevious(current: number) {
   let index = current - 1;
@@ -34,7 +36,7 @@
   const vizWindow = globals.stateVisibleTime();
   const startNs = vizWindow.start;
   const endNs = vizWindow.end;
-  const currentTs = globals.currentSearchResults.tsStarts[index];
+  const currentTs = globals.currentSearchResults.tses[index];
 
   // If the value of |globals.currentSearchResults.totalResults| is 0,
   // it means that the query is in progress or no results are found.
@@ -44,12 +46,12 @@
 
   // If this is a new search or the currentTs is not in the viewport,
   // select the first/last item in the viewport.
-  if (index === -1 || currentTs < startNs || currentTs > endNs) {
+  if (
+    index === -1 ||
+    (currentTs !== -1n && (currentTs < startNs || currentTs > endNs))
+  ) {
     if (reverse) {
-      const [smaller] = searchSegment(
-        globals.currentSearchResults.tsStarts,
-        endNs,
-      );
+      const [smaller] = searchSegment(globals.currentSearchResults.tses, endNs);
       // If there is no item in the viewport just go to the previous.
       if (smaller === -1) {
         setToPrevious(index);
@@ -58,7 +60,7 @@
       }
     } else {
       const [, larger] = searchSegment(
-        globals.currentSearchResults.tsStarts,
+        globals.currentSearchResults.tses,
         startNs,
       );
       // If there is no item in the viewport just go to the next.
@@ -82,52 +84,61 @@
 function selectCurrentSearchResult() {
   const searchIndex = globals.state.searchIndex;
   const source = globals.currentSearchResults.sources[searchIndex];
-  const currentId = globals.currentSearchResults.sliceIds[searchIndex];
+  const currentId = globals.currentSearchResults.eventIds[searchIndex];
   const trackKey = globals.currentSearchResults.trackKeys[searchIndex];
 
   if (currentId === undefined) return;
 
-  if (source === 'cpu') {
-    globals.setLegacySelection(
-      {
-        kind: 'SLICE',
-        id: currentId,
-        trackKey,
-      },
-      {
-        clearSearch: false,
-        pendingScrollId: currentId,
-        switchToCurrentSelectionTab: true,
-      },
-    );
-  } else if (source === 'log') {
-    globals.setLegacySelection(
-      {
-        kind: 'LOG',
-        id: currentId,
-        trackKey,
-      },
-      {
-        clearSearch: false,
-        pendingScrollId: currentId,
-        switchToCurrentSelectionTab: true,
-      },
-    );
-  } else {
-    // Search results only include slices from the slice table for now.
-    // When we include annotations we need to pass the correct table.
-    globals.setLegacySelection(
-      {
-        kind: 'CHROME_SLICE',
-        id: currentId,
-        trackKey,
-        table: 'slice',
-      },
-      {
-        clearSearch: false,
-        pendingScrollId: currentId,
-        switchToCurrentSelectionTab: true,
-      },
-    );
+  switch (source) {
+    case 'track':
+      verticalScrollToTrack(trackKey, true);
+      break;
+    case 'cpu':
+      globals.setLegacySelection(
+        {
+          kind: 'SLICE',
+          id: currentId,
+          trackKey,
+        },
+        {
+          clearSearch: false,
+          pendingScrollId: currentId,
+          switchToCurrentSelectionTab: true,
+        },
+      );
+      break;
+    case 'log':
+      globals.setLegacySelection(
+        {
+          kind: 'LOG',
+          id: currentId,
+          trackKey,
+        },
+        {
+          clearSearch: false,
+          pendingScrollId: currentId,
+          switchToCurrentSelectionTab: true,
+        },
+      );
+      break;
+    case 'slice':
+      // Search results only include slices from the slice table for now.
+      // When we include annotations we need to pass the correct table.
+      globals.setLegacySelection(
+        {
+          kind: 'CHROME_SLICE',
+          id: currentId,
+          trackKey,
+          table: 'slice',
+        },
+        {
+          clearSearch: false,
+          pendingScrollId: currentId,
+          switchToCurrentSelectionTab: true,
+        },
+      );
+      break;
+    default:
+      assertUnreachable(source);
   }
 }
diff --git a/ui/src/frontend/simple_counter_track.ts b/ui/src/frontend/simple_counter_track.ts
index 084c14f..361480b 100644
--- a/ui/src/frontend/simple_counter_track.ts
+++ b/ui/src/frontend/simple_counter_track.ts
@@ -17,6 +17,7 @@
 import {BaseCounterTrack, CounterOptions} from './base_counter_track';
 import {CounterColumns, SqlDataSource} from './debug_tracks';
 import {Disposable, DisposableCallback} from '../base/disposable';
+import {uuidv4Sql} from '../base/uuid';
 
 export type SimpleCounterTrackConfig = {
   data: SqlDataSource;
@@ -39,7 +40,7 @@
       options: config.options,
     });
     this.config = config;
-    this.sqlTableName = `__simple_counter_${this.trackKey}`;
+    this.sqlTableName = `__simple_counter_${uuidv4Sql()}`;
   }
 
   async onInit(): Promise<Disposable> {
@@ -74,7 +75,7 @@
 
   private async dropTrackTable(): Promise<void> {
     if (this.engine.isAlive) {
-      this.engine.query(`drop table if exists ${this.sqlTableName}`);
+      await this.engine.query(`drop table if exists ${this.sqlTableName}`);
     }
   }
 }
diff --git a/ui/src/frontend/simple_slice_track.ts b/ui/src/frontend/simple_slice_track.ts
index baa907d..6d287b3 100644
--- a/ui/src/frontend/simple_slice_track.ts
+++ b/ui/src/frontend/simple_slice_track.ts
@@ -87,13 +87,12 @@
     // TODO(altimin): Support removing this table when the track is closed.
     const dur = sliceColumns.dur === '0' ? 0 : sliceColumns.dur;
     await this.engine.query(`
-      create table ${this.sqlTableName} as
+      create perfetto table ${this.sqlTableName} as
       with data${dataColumns} as (
         ${data.sqlSource}
       ),
       prepared_data as (
         select
-          row_number() over () as id,
           ${sliceColumns.ts} as ts,
           ifnull(cast(${dur} as int), -1) as dur,
           printf('%s', ${sliceColumns.name}) as name
@@ -102,6 +101,7 @@
         from data
       )
       select
+        row_number() over (order by ts) as id,
         *
       from prepared_data
       order by ts;`);
diff --git a/ui/src/frontend/tickmark_panel.ts b/ui/src/frontend/tickmark_panel.ts
index 2703720..90f3e4c 100644
--- a/ui/src/frontend/tickmark_panel.ts
+++ b/ui/src/frontend/tickmark_panel.ts
@@ -84,19 +84,21 @@
       );
     }
     const index = globals.state.searchIndex;
-    if (index !== -1 && index < globals.currentSearchResults.tsStarts.length) {
-      const start = globals.currentSearchResults.tsStarts[index];
-      const triangleStart =
-        Math.max(visibleTimeScale.timeToPx(Time.fromRaw(start)), 0) +
-        TRACK_SHELL_WIDTH;
-      ctx.fillStyle = '#000';
-      ctx.beginPath();
-      ctx.moveTo(triangleStart, size.height);
-      ctx.lineTo(triangleStart - 3, 0);
-      ctx.lineTo(triangleStart + 3, 0);
-      ctx.lineTo(triangleStart, size.height);
-      ctx.fill();
-      ctx.closePath();
+    if (index !== -1 && index < globals.currentSearchResults.tses.length) {
+      const start = globals.currentSearchResults.tses[index];
+      if (start !== -1n) {
+        const triangleStart =
+          Math.max(visibleTimeScale.timeToPx(Time.fromRaw(start)), 0) +
+          TRACK_SHELL_WIDTH;
+        ctx.fillStyle = '#000';
+        ctx.beginPath();
+        ctx.moveTo(triangleStart, size.height);
+        ctx.lineTo(triangleStart - 3, 0);
+        ctx.lineTo(triangleStart + 3, 0);
+        ctx.lineTo(triangleStart, size.height);
+        ctx.fill();
+        ctx.closePath();
+      }
     }
 
     ctx.restore();
diff --git a/ui/src/frontend/track_panel.ts b/ui/src/frontend/track_panel.ts
index d2cc66b..806b49c 100644
--- a/ui/src/frontend/track_panel.ts
+++ b/ui/src/frontend/track_panel.ts
@@ -100,6 +100,7 @@
       {
         trigger: m(Button, {
           icon: Icons.Crashed,
+          compact: true,
         }),
       },
       this.renderErrorMessage(attrs.error),
diff --git a/ui/src/frontend/widgets_page.ts b/ui/src/frontend/widgets_page.ts
index ea80972..65fb04e 100644
--- a/ui/src/frontend/widgets_page.ts
+++ b/ui/src/frontend/widgets_page.ts
@@ -50,6 +50,11 @@
 import {TableShowcase} from './tables/table_showcase';
 import {TreeTable, TreeTableAttrs} from './widgets/treetable';
 import {Intent} from '../widgets/common';
+import {
+  VirtualTable,
+  VirtualTableAttrs,
+  VirtualTableRow,
+} from '../widgets/virtual_table';
 
 const DATA_ENGLISH_LETTER_FREQUENCY = {
   table: [
@@ -569,6 +574,11 @@
   },
 ];
 
+let virtualTableData: {offset: number; rows: VirtualTableRow[]} = {
+  offset: 0,
+  rows: [],
+};
+
 export const WidgetsPage = createPage({
   view() {
     return m(
@@ -1154,10 +1164,38 @@
           return m(TreeTable<File>, attrs);
         },
       }),
+      m(WidgetShowcase, {
+        label: 'VirtualTable',
+        description: `Virtualized table for efficient rendering of large datasets`,
+        renderWidget: () => {
+          const attrs: VirtualTableAttrs = {
+            columns: [
+              {header: 'x', width: '4em'},
+              {header: 'x^2', width: '8em'},
+            ],
+            rows: virtualTableData.rows,
+            firstRowOffset: virtualTableData.offset,
+            rowHeight: 20,
+            numRows: 500_000,
+            style: {height: '200px'},
+            onReload: (rowOffset, rowCount) => {
+              const rows = [];
+              for (let i = rowOffset; i < rowOffset + rowCount; i++) {
+                rows.push({id: i, cells: [i, i ** 2]});
+              }
+              virtualTableData = {
+                offset: rowOffset,
+                rows,
+              };
+              raf.scheduleFullRedraw();
+            },
+          };
+          return m(VirtualTable, attrs);
+        },
+      }),
     );
   },
 });
-
 class ModalShowcase implements m.ClassComponent {
   private static counter = 0;
 
diff --git a/ui/src/plugins/dev.perfetto.AndroidCujs/index.ts b/ui/src/plugins/dev.perfetto.AndroidCujs/index.ts
index 5fb1a1a..2c13c76 100644
--- a/ui/src/plugins/dev.perfetto.AndroidCujs/index.ts
+++ b/ui/src/plugins/dev.perfetto.AndroidCujs/index.ts
@@ -129,7 +129,7 @@
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     ctx.registerCommand({
       id: 'dev.perfetto.AndroidCujs#PinJankCUJs',
-      name: 'Pin: Android Jank CUJs',
+      name: 'Add track: Android jank CUJs',
       callback: () => {
         runQuery(JANK_CUJ_QUERY_PRECONDITIONS, ctx.engine).then(() => {
           addDebugSliceTrack(
@@ -148,7 +148,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.AndroidCujs#ListJankCUJs',
-      name: 'Run query: Android Jank CUJs',
+      name: 'Run query: Android jank CUJs',
       callback: () => {
         runQuery(JANK_CUJ_QUERY_PRECONDITIONS, ctx.engine).then(() =>
           ctx.tabs.openQuery(JANK_CUJ_QUERY, 'Android Jank CUJs'),
@@ -158,7 +158,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.AndroidCujs#PinLatencyCUJs',
-      name: 'Pin: Android Latency CUJs',
+      name: 'Add track: Android latency CUJs',
       callback: () => {
         addDebugSliceTrack(
           ctx.engine,
diff --git a/ui/src/plugins/dev.perfetto.AndroidNetwork/index.ts b/ui/src/plugins/dev.perfetto.AndroidNetwork/index.ts
index 0eb7e0f..9cb8405 100644
--- a/ui/src/plugins/dev.perfetto.AndroidNetwork/index.ts
+++ b/ui/src/plugins/dev.perfetto.AndroidNetwork/index.ts
@@ -41,7 +41,7 @@
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     ctx.registerCommand({
       id: 'dev.perfetto.AndroidNetwork#batteryEvents',
-      name: 'Run query: Pin battery events',
+      name: 'Add track: battery events',
       callback: async (track) => {
         if (track === undefined) {
           track = prompt('Battery Track', '');
@@ -62,7 +62,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.AndroidNetwork#activityTrack',
-      name: 'Run query: Visualize Network Activity',
+      name: 'Add track: network activity',
       callback: async (groupby, filter, trackName) => {
         if (groupby === undefined) {
           groupby = prompt('Group by', 'package_name');
diff --git a/ui/src/plugins/dev.perfetto.CoreCommands/index.ts b/ui/src/plugins/dev.perfetto.CoreCommands/index.ts
index 8dc6a6f..54cd458 100644
--- a/ui/src/plugins/dev.perfetto.CoreCommands/index.ts
+++ b/ui/src/plugins/dev.perfetto.CoreCommands/index.ts
@@ -19,7 +19,6 @@
   PluginContext,
   PluginContextTrace,
   PluginDescriptor,
-  addDebugSliceTrack,
 } from '../../public';
 
 const SQL_STATS = `
@@ -107,7 +106,7 @@
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#RunQueryAllProcesses',
-      name: 'Run query: all processes',
+      name: 'Run query: All processes',
       callback: () => {
         ctx.tabs.openQuery(ALL_PROCESSES_QUERY, 'All Processes');
       },
@@ -138,7 +137,7 @@
       callback: () => {
         ctx.tabs.openQuery(
           CPU_TIME_BY_CPU_BY_PROCESS,
-          'CPU Time by CPU by process',
+          'CPU time by CPU by process',
         );
       },
     });
@@ -163,18 +162,8 @@
     });
 
     ctx.registerCommand({
-      id: 'dev.perfetto.CoreCommands#PinFtraceTracks',
-      name: 'Pin ftrace tracks',
-      callback: () => {
-        ctx.timeline.pinTracksByPredicate((tags) => {
-          return !!tags.name?.startsWith('Ftrace Events Cpu ');
-        });
-      },
-    });
-
-    ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#UnpinAllTracks',
-      name: 'Unpin all tracks',
+      name: 'Unpin all pinned tracks',
       callback: () => {
         ctx.timeline.unpinTracksByPredicate((_) => {
           return true;
@@ -184,7 +173,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#ExpandAllGroups',
-      name: 'Expand all groups',
+      name: 'Expand all track groups',
       callback: () => {
         ctx.timeline.expandGroupsByPredicate((_) => {
           return true;
@@ -194,7 +183,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#CollapseAllGroups',
-      name: 'Collapse all groups',
+      name: 'Collapse all track groups',
       callback: () => {
         ctx.timeline.collapseGroupsByPredicate((_) => {
           return true;
@@ -204,7 +193,7 @@
 
     ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#PanToTimestamp',
-      name: 'Pan To Timestamp',
+      name: 'Pan to timestamp',
       callback: (tsRaw: unknown) => {
         if (exists(tsRaw)) {
           if (typeof tsRaw !== 'bigint') {
@@ -222,29 +211,8 @@
     });
 
     ctx.registerCommand({
-      id: 'test',
-      name: 'Make Test Debug Track',
-      callback: () => {
-        addDebugSliceTrack(
-          ctx.engine,
-          {
-            sqlSource: `
-              SELECT *
-              FROM slice
-              WHERE name like 'a%'
-              LIMIT 10000
-            `,
-          },
-          'Track Name',
-          {ts: 'ts', dur: 'dur', name: 'name'},
-          [],
-        );
-      },
-    });
-
-    ctx.registerCommand({
       id: 'dev.perfetto.CoreCommands#ShowCurrentSelectionTab',
-      name: 'Show Current Selection Tab',
+      name: 'Show current selection tab',
       callback: () => {
         ctx.tabs.showTab('current_selection');
       },
diff --git a/ui/src/plugins/org.kernel.LinuxKernelDevices/index.ts b/ui/src/plugins/org.kernel.LinuxKernelDevices/index.ts
index d7a37d8..b9127f0 100644
--- a/ui/src/plugins/org.kernel.LinuxKernelDevices/index.ts
+++ b/ui/src/plugins/org.kernel.LinuxKernelDevices/index.ts
@@ -27,23 +27,11 @@
 class LinuxKernelDevices implements Plugin {
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     const result = await ctx.engine.query(`
-      with
-        slices_tracks as materialized (
-          select distinct track_id
-          from slice
-        ),
-        tracks as (
-          select
-            linux_device_track.id as track_id,
-            linux_device_track.name
-          from linux_device_track
-          join slices_tracks on
-          slices_tracks.track_id = linux_device_track.id
-        )
       select
-        t.name,
-        t.track_id as trackId
-      from tracks as t
+        t.id as trackId,
+        t.name
+      from linux_device_track t
+      join _slice_track_summary using (id)
       order by t.name;
     `);
 
diff --git a/ui/src/public/index.ts b/ui/src/public/index.ts
index a8d2949..ece6ea0 100644
--- a/ui/src/public/index.ts
+++ b/ui/src/public/index.ts
@@ -45,9 +45,9 @@
   // These properties are updated only once per query result when the Slice
   // object is created and don't change afterwards.
   readonly id: number;
-  readonly startNsQ: time;
-  readonly endNsQ: time;
-  readonly durNsQ: duration;
+  readonly startNs: time;
+  readonly endNs: time;
+  readonly durNs: duration;
   readonly ts: time;
   readonly dur: duration;
   readonly depth: number;
diff --git a/ui/src/public/utils.ts b/ui/src/public/utils.ts
index 60c4487..f5d3d7a 100644
--- a/ui/src/public/utils.ts
+++ b/ui/src/public/utils.ts
@@ -22,7 +22,7 @@
 export function getTrackName(
   args: Partial<{
     name: string | null;
-    utid: number;
+    utid: number | null;
     processName: string | null;
     pid: number | null;
     threadName: string | null;
diff --git a/ui/src/tracks/android_log/index.ts b/ui/src/tracks/android_log/index.ts
index 7247376..53e6f69 100644
--- a/ui/src/tracks/android_log/index.ts
+++ b/ui/src/tracks/android_log/index.ts
@@ -84,7 +84,7 @@
 
     ctx.registerCommand({
       id: 'perfetto.AndroidLog#ShowLogsTab',
-      name: 'Show Android Logs Tab',
+      name: 'Show android logs tab',
       callback: () => {
         ctx.tabs.showTab(androidLogsTabUri);
       },
diff --git a/ui/src/tracks/android_log/logs_panel.ts b/ui/src/tracks/android_log/logs_panel.ts
index 51e0889..3970190 100644
--- a/ui/src/tracks/android_log/logs_panel.ts
+++ b/ui/src/tracks/android_log/logs_panel.ts
@@ -18,12 +18,10 @@
 import {Actions} from '../../common/actions';
 import {raf} from '../../core/raf_scheduler';
 import {DetailsShell} from '../../widgets/details_shell';
-import {VirtualScrollContainer} from '../../widgets/virtual_scroll_container';
 
-import {SELECTED_LOG_ROWS_COLOR} from '../../frontend/css_constants';
 import {globals} from '../../frontend/globals';
 import {Timestamp} from '../../frontend/widgets/timestamp';
-import {createStore, EngineProxy, LONG, NUM, Store, STR} from '../../public';
+import {EngineProxy, LONG, NUM, NUM_NULL, Store, STR} from '../../public';
 import {Monitor} from '../../base/monitor';
 import {AsyncLimiter} from '../../base/async_limiter';
 import {escapeGlob, escapeQuery} from '../../trace_processor/query_utils';
@@ -31,6 +29,8 @@
 import {Button} from '../../widgets/button';
 import {TextInput} from '../../widgets/text_input';
 import {Intent} from '../../widgets/common';
+import {VirtualTable, VirtualTableRow} from '../../widgets/virtual_table';
+import {classNames} from '../../base/classnames';
 
 const ROW_H = 20;
 
@@ -63,15 +63,12 @@
 }
 
 export class LogPanel implements m.ClassComponent<LogPanelAttrs> {
-  private readonly SKIRT_SIZE = 50;
   private entries?: LogEntries;
-  private isStale = true;
-  private viewportBounds = {top: 0, bottom: 0};
 
-  private readonly paginationStore = createStore<Pagination>({
+  private pagination: Pagination = {
     offset: 0,
     count: 0,
-  });
+  };
   private readonly rowsMonitor: Monitor;
   private readonly filterMonitor: Monitor;
   private readonly queryLimiter = new AsyncLimiter();
@@ -81,7 +78,6 @@
       () => attrs.filterStore.state,
       () => globals.state.frontendLocalState.visibleState.start,
       () => globals.state.frontendLocalState.visibleState.end,
-      () => this.paginationStore.state,
     ]);
 
     this.filterMonitor = new Monitor([() => attrs.filterStore.state]);
@@ -89,148 +85,104 @@
 
   view({attrs}: m.CVnode<LogPanelAttrs>) {
     if (this.rowsMonitor.ifStateChanged()) {
-      this.queryLimiter.schedule(async () => {
-        this.isStale = true;
-        raf.scheduleFullRedraw();
-
-        const visibleState = globals.state.frontendLocalState.visibleState;
-        const visibleSpan = new TimeSpan(visibleState.start, visibleState.end);
-
-        if (this.filterMonitor.ifStateChanged()) {
-          await updateLogView(attrs.engine, attrs.filterStore.state);
-        }
-
-        this.entries = await updateLogEntries(
-          attrs.engine,
-          visibleSpan,
-          this.paginationStore.state,
-        );
-
-        raf.scheduleFullRedraw();
-        this.isStale = false;
-      });
+      this.reloadData(attrs);
     }
 
     const hasProcessNames =
       this.entries &&
       this.entries.processName.filter((name) => name).length > 0;
+    const totalEvents = this.entries?.totalEvents ?? 0;
 
-    const rows: m.Children = [];
-    rows.push(
-      m(
-        `.row`,
-        m('.cell.row-header', 'Timestamp'),
-        m('.cell.row-header', 'Level'),
-        m('.cell.row-header', 'Tag'),
-        hasProcessNames
-          ? m('.cell.with-process.row-header', 'Process name')
-          : undefined,
-        hasProcessNames
-          ? m('.cell.with-process.row-header', 'Message')
-          : m('.cell.no-process.row-header', 'Message'),
-        m('br'),
-      ),
-    );
-    if (this.entries) {
-      const offset = this.entries.offset;
-      const timestamps = this.entries.timestamps;
-      const priorities = this.entries.priorities;
-      const tags = this.entries.tags;
-      const messages = this.entries.messages;
-      const processNames = this.entries.processName;
-      const totalEvents = this.entries.totalEvents;
-
-      for (let i = 0; i < this.entries.timestamps.length; i++) {
-        const priorityLetter = LOG_PRIORITIES[priorities[i]][0];
-        const ts = timestamps[i];
-        const prioClass = priorityLetter || '';
-        const style: {top: string; backgroundColor?: string} = {
-          // 1.5 is for the width of the header
-          top: `${(offset + i + 1.5) * ROW_H}px`,
-        };
-        if (this.entries.isHighlighted[i]) {
-          style.backgroundColor = SELECTED_LOG_ROWS_COLOR;
-        }
-
-        rows.push(
-          m(
-            `.row.${prioClass}`,
-            {
-              class: this.isStale ? 'stale' : '',
-              style,
-              onmouseover: () => {
-                globals.dispatch(Actions.setHoverCursorTimestamp({ts}));
-              },
-              onmouseout: () => {
-                globals.dispatch(
-                  Actions.setHoverCursorTimestamp({ts: Time.INVALID}),
-                );
-              },
-            },
-            m('.cell', m(Timestamp, {ts})),
-            m('.cell', priorityLetter || '?'),
-            m('.cell', tags[i]),
-            hasProcessNames
-              ? m('.cell.with-process', processNames[i])
-              : undefined,
-            hasProcessNames
-              ? m('.cell.with-process', messages[i])
-              : m('.cell.no-process', messages[i]),
-            m('br'),
-          ),
-        );
-      }
-
-      return m(
-        DetailsShell,
-        {
-          title: 'Android Logs',
-          description: `[${this.viewportBounds.top}, ${this.viewportBounds.bottom}] / ${totalEvents}`,
-          buttons: m(LogsFilters, {store: attrs.filterStore}),
+    return m(
+      DetailsShell,
+      {
+        title: 'Android Logs',
+        description: `Total messages: ${totalEvents}`,
+        buttons: m(LogsFilters, {store: attrs.filterStore}),
+      },
+      m(VirtualTable, {
+        className: 'pf-android-logs-table',
+        columns: [
+          {header: 'Timestamp', width: '7rem'},
+          {header: 'Level', width: '4rem'},
+          {header: 'Tag', width: '13rem'},
+          ...(hasProcessNames ? [{header: 'Process', width: '18rem'}] : []),
+          {header: 'Message', width: '42rem'},
+        ],
+        rows: this.renderRows(hasProcessNames),
+        firstRowOffset: this.entries?.offset ?? 0,
+        numRows: this.entries?.totalEvents ?? 0,
+        rowHeight: ROW_H,
+        onReload: (offset, count) => {
+          this.pagination = {offset, count};
+          this.reloadData(attrs);
         },
-        m(
-          VirtualScrollContainer,
-          {
-            onScroll: (scrollContainer: HTMLElement) => {
-              this.recomputeVisibleRowsAndUpdate(scrollContainer);
-              raf.scheduleFullRedraw();
-            },
-          },
-          m(
-            '.log-panel',
-            m('.rows', {style: {height: `${totalEvents * ROW_H}px`}}, rows),
-          ),
-        ),
-      );
-    }
-
-    return null;
+        onRowHover: (id) => {
+          const timestamp = this.entries?.timestamps[id];
+          if (timestamp !== undefined) {
+            globals.dispatch(Actions.setHoverCursorTimestamp({ts: timestamp}));
+          }
+        },
+        onRowOut: () => {
+          globals.dispatch(Actions.setHoverCursorTimestamp({ts: Time.INVALID}));
+        },
+      }),
+    );
   }
 
-  recomputeVisibleRowsAndUpdate(scrollContainer: HTMLElement) {
-    const viewportTop = Math.floor(scrollContainer.scrollTop / ROW_H);
-    const viewportHeight = Math.ceil(scrollContainer.clientHeight / ROW_H);
-    const viewportBottom = viewportTop + viewportHeight;
+  private reloadData(attrs: LogPanelAttrs) {
+    this.queryLimiter.schedule(async () => {
+      const visibleState = globals.state.frontendLocalState.visibleState;
+      const visibleSpan = new TimeSpan(visibleState.start, visibleState.end);
 
-    this.viewportBounds = {
-      top: viewportTop,
-      bottom: viewportBottom,
-    };
+      if (this.filterMonitor.ifStateChanged()) {
+        await updateLogView(attrs.engine, attrs.filterStore.state);
+      }
 
-    const curPage = this.paginationStore.state;
+      this.entries = await updateLogEntries(
+        attrs.engine,
+        visibleSpan,
+        this.pagination,
+      );
 
-    if (
-      viewportTop < curPage.offset ||
-      viewportBottom >= curPage.offset + curPage.count
-    ) {
-      this.paginationStore.edit((draft) => {
-        const offset = Math.max(0, viewportTop - this.SKIRT_SIZE);
-        // Make it even so alternating coloured rows line up
-        const offsetEven = Math.floor(offset / 2) * 2;
-        draft.offset = offsetEven;
-        draft.count = viewportHeight + this.SKIRT_SIZE * 2;
+      raf.scheduleFullRedraw();
+    });
+  }
+
+  private renderRows(hasProcessNames: boolean | undefined): VirtualTableRow[] {
+    if (!this.entries) {
+      return [];
+    }
+
+    const timestamps = this.entries.timestamps;
+    const priorities = this.entries.priorities;
+    const tags = this.entries.tags;
+    const messages = this.entries.messages;
+    const processNames = this.entries.processName;
+
+    const rows: VirtualTableRow[] = [];
+    for (let i = 0; i < this.entries.timestamps.length; i++) {
+      const priorityLetter = LOG_PRIORITIES[priorities[i]][0];
+      const ts = timestamps[i];
+      const prioClass = priorityLetter || '';
+
+      rows.push({
+        id: i,
+        className: classNames(
+          prioClass,
+          this.entries.isHighlighted[i] && 'pf-highlighted',
+        ),
+        cells: [
+          m(Timestamp, {ts}),
+          priorityLetter || '?',
+          tags[i],
+          ...(hasProcessNames ? [processNames[i]] : []),
+          messages[i],
+        ],
       });
     }
+
+    return rows;
   }
 }
 
@@ -460,7 +412,7 @@
     prio: NUM,
     tag: STR,
     msg: STR,
-    isMsgHighlighted: NUM,
+    isMsgHighlighted: NUM_NULL,
     isProcessHighlighted: NUM,
     processName: STR,
   });
diff --git a/ui/src/tracks/async_slices/index.ts b/ui/src/tracks/async_slices/index.ts
index 2e8b3d5..18883d9 100644
--- a/ui/src/tracks/async_slices/index.ts
+++ b/ui/src/tracks/async_slices/index.ts
@@ -30,77 +30,41 @@
   async addGlobalAsyncTracks(ctx: PluginContextTrace): Promise<void> {
     const {engine} = ctx;
     const rawGlobalAsyncTracks = await engine.query(`
-      with tracks_with_slices as materialized (
-        select distinct track_id
-        from slice
-      ),
-      global_tracks as (
-        select
-          track.parent_id as parent_id,
-          track.id as track_id,
-          track.name as name
-        from track
-        join tracks_with_slices on tracks_with_slices.track_id = track.id
-        where
-          track.type = "track"
-          or track.type = "gpu_track"
-          or track.type = "cpu_track"
-      ),
-      global_tracks_grouped as (
+      with global_tracks_grouped as (
         select
           parent_id,
           name,
-          group_concat(track_id) as trackIds,
-          count(track_id) as trackCount
-        from global_tracks track
+          group_concat(id) as trackIds,
+          count() as trackCount
+        from track t
+        join _slice_track_summary using (id)
+        where t.type in ('track', 'gpu_track', 'cpu_track')
         group by parent_id, name
       )
       select
-        t.parent_id as parentId,
-        p.name as parentName,
         t.name as name,
+        t.parent_id as parentId,
         t.trackIds as trackIds,
         __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from global_tracks_grouped AS t
-      left join track p on (t.parent_id = p.id)
-      order by p.name, t.name;
+      from global_tracks_grouped t
     `);
     const it = rawGlobalAsyncTracks.iter({
       name: STR_NULL,
-      parentName: STR_NULL,
       parentId: NUM_NULL,
       trackIds: STR,
-      maxDepth: NUM_NULL,
+      maxDepth: NUM,
     });
 
-    // let scrollJankRendered = false;
-
     for (; it.valid(); it.next()) {
       const rawName = it.name === null ? undefined : it.name;
-      // const rawParentName = it.parentName === null ? undefined :
-      // it.parentName;
       const displayName = getTrackName({
         name: rawName,
         kind: ASYNC_SLICE_TRACK_KIND,
       });
       const rawTrackIds = it.trackIds;
       const trackIds = rawTrackIds.split(',').map((v) => Number(v));
-      // const parentTrackId = it.parentId;
       const maxDepth = it.maxDepth;
 
-      // If there are no slices in this track, skip it.
-      if (maxDepth === null) {
-        continue;
-      }
-
-      // if (ENABLE_SCROLL_JANK_PLUGIN_V2.get() && !scrollJankRendered &&
-      //     name.includes(INPUT_LATENCY_TRACK)) {
-      //   // This ensures that the scroll jank tracks render above the tracks
-      //   // for GestureScrollUpdate.
-      //   await this.addScrollJankTracks(this.engine);
-      //   scrollJankRendered = true;
-      // }
-
       ctx.registerTrack({
         uri: `perfetto.AsyncSlices#${rawName}.${it.parentId}`,
         displayName,
@@ -115,27 +79,16 @@
 
   async addProcessAsyncSliceTracks(ctx: PluginContextTrace): Promise<void> {
     const result = await ctx.engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where
-            process_track.name is null or
-            process_track.name not like "% Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
+        upid,
+        t.name as trackName,
+        t.track_ids as trackIds,
+        process.name as processName,
+        process.pid as pid,
+        __max_layout_depth(t.track_count, t.track_ids) as maxDepth
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name is null or t.name not glob "* Timeline"
     `);
 
     const it = result.iter({
@@ -144,7 +97,7 @@
       trackIds: STR,
       processName: STR_NULL,
       pid: NUM_NULL,
-      maxDepth: NUM_NULL,
+      maxDepth: NUM,
     });
     for (; it.valid(); it.next()) {
       const upid = it.upid;
@@ -155,11 +108,6 @@
       const pid = it.pid;
       const maxDepth = it.maxDepth;
 
-      if (maxDepth === null) {
-        // If there are no slices in this track, skip it.
-        continue;
-      }
-
       const kind = ASYNC_SLICE_TRACK_KIND;
       const displayName = getTrackName({
         name: trackName,
@@ -188,37 +136,20 @@
   async addUserAsyncSliceTracks(ctx: PluginContextTrace): Promise<void> {
     const {engine} = ctx;
     const result = await engine.query(`
-      with tracks_with_slices as materialized (
-        select distinct track_id
-        from slice
-      ),
-      global_tracks as (
-        select
-          uid_track.name,
-          uid_track.uid,
-          group_concat(uid_track.id) as trackIds,
-          count(uid_track.id) as trackCount
-        from uid_track
-        join tracks_with_slices
-        where tracks_with_slices.track_id == uid_track.id
-        group by uid_track.uid
-      )
       select
         t.name as name,
         t.uid as uid,
-        package_list.package_name as package_name,
-        t.trackIds as trackIds,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from global_tracks t
-      join package_list
-      where t.uid = package_list.uid
-      group by t.uid
-      `);
+        package_list.package_name as packageName,
+        t.track_ids as trackIds,
+        __max_layout_depth(t.track_count, t.track_ids) as maxDepth
+      from _uid_track_track_summary_by_uid_and_name t
+      join package_list using (uid)
+    `);
 
     const it = result.iter({
       name: STR_NULL,
       uid: NUM_NULL,
-      package_name: STR_NULL,
+      packageName: STR_NULL,
       trackIds: STR,
       maxDepth: NUM_NULL,
     });
@@ -226,7 +157,7 @@
     for (; it.valid(); it.next()) {
       const kind = ASYNC_SLICE_TRACK_KIND;
       const rawName = it.name === null ? undefined : it.name;
-      const userName = it.package_name === null ? undefined : it.package_name;
+      const userName = it.packageName === null ? undefined : it.packageName;
       const uid = it.uid === null ? undefined : it.uid;
       const rawTrackIds = it.trackIds;
       const trackIds = rawTrackIds.split(',').map((v) => Number(v));
diff --git a/ui/src/tracks/chrome_critical_user_interactions/index.ts b/ui/src/tracks/chrome_critical_user_interactions/index.ts
index 427acc7..faa863b 100644
--- a/ui/src/tracks/chrome_critical_user_interactions/index.ts
+++ b/ui/src/tracks/chrome_critical_user_interactions/index.ts
@@ -284,7 +284,7 @@
   onActivate(ctx: PluginContext): void {
     ctx.registerCommand({
       id: 'perfetto.CriticalUserInteraction.AddInteractionTrack',
-      name: 'Add Chrome Interactions track',
+      name: 'Add track: Chrome interactions',
       callback: () => addCriticalUserInteractionTrack(),
     });
   }
diff --git a/ui/src/tracks/chrome_scroll_jank/event_latency_track.ts b/ui/src/tracks/chrome_scroll_jank/event_latency_track.ts
index 85a2a70..11cc6d1 100644
--- a/ui/src/tracks/chrome_scroll_jank/event_latency_track.ts
+++ b/ui/src/tracks/chrome_scroll_jank/event_latency_track.ts
@@ -53,8 +53,8 @@
     });
   }
 
-  onDestroy() {
-    super.onDestroy();
+  async onDestroy(): Promise<void> {
+    await super.onDestroy();
     ScrollJankPluginState.getInstance().unregisterTrack(EventLatencyTrack.kind);
   }
 
diff --git a/ui/src/tracks/chrome_scroll_jank/scroll_delta_graph.ts b/ui/src/tracks/chrome_scroll_jank/scroll_delta_graph.ts
index 0bd3abe..eedf3be 100644
--- a/ui/src/tracks/chrome_scroll_jank/scroll_delta_graph.ts
+++ b/ui/src/tracks/chrome_scroll_jank/scroll_delta_graph.ts
@@ -16,7 +16,7 @@
 
 import {duration, Time, time} from '../../base/time';
 import {EngineProxy} from '../../trace_processor/engine';
-import {LONG, NUM, STR} from '../../trace_processor/query_result';
+import {LONG, NUM} from '../../trace_processor/query_result';
 import {VegaView} from '../../widgets/vega_view';
 
 const USER_CATEGORY = 'User';
@@ -27,14 +27,14 @@
   // to denote the color of the data point.
   category: string;
   offset: number;
-  scrollUpdateIds: string;
+  scrollUpdateId: number;
   ts: number;
   delta: number;
 }
 
 export interface ScrollDeltaDetails {
   ts: time;
-  scrollUpdateIds: string;
+  scrollUpdateId: number;
   scrollDelta: number;
   scrollOffset: number;
 }
@@ -54,9 +54,9 @@
 
     SELECT
       ts,
-      IFNULL(scroll_update_id, "") AS scrollUpdateId,
+      IFNULL(scroll_update_id, 0) AS scrollUpdateId,
       delta_y AS deltaY,
-      offset_y AS offsetY
+      relative_offset_y AS offsetY
     FROM chrome_scroll_input_offsets
     WHERE ts >= ${startTs} AND ts <= ${startTs + dur};
   `);
@@ -72,7 +72,7 @@
   for (; it.valid(); it.next()) {
     deltas.push({
       ts: Time.fromRaw(it.ts),
-      scrollUpdateIds: it.scrollUpdateId.toString(),
+      scrollUpdateId: it.scrollUpdateId,
       scrollOffset: it.offsetY,
       scrollDelta: it.deltaY,
     });
@@ -87,30 +87,21 @@
   dur: duration,
 ): Promise<ScrollDeltaDetails[]> {
   const queryResult = await engine.query(`
-    INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_offsets;
+    INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_offsets
 
-    WITH scroll_update_ids AS (
-      SELECT DISTINCT
-        ts,
-        GROUP_CONCAT(scroll_update_id, ', ')
-          OVER (PARTITION BY ts) AS scroll_update_ids
-      FROM chrome_presented_scroll_offsets
-    )
     SELECT
       ts,
-      IFNULL(scroll_update_ids, "") AS scrollUpdateIds,
+      IFNULL(scroll_update_id, 0) AS scrollUpdateId,
       delta_y AS deltaY,
-      offset_y AS offsetY
+      relative_offset_y AS offsetY
     FROM chrome_presented_scroll_offsets
-    LEFT JOIN scroll_update_ids
-      USING(ts)
     WHERE ts >= ${startTs} AND ts <= ${startTs + dur}
       AND delta_y IS NOT NULL;
   `);
 
   const it = queryResult.iter({
     ts: LONG,
-    scrollUpdateIds: STR,
+    scrollUpdateId: NUM,
     deltaY: NUM,
     offsetY: NUM,
   });
@@ -122,7 +113,7 @@
 
     deltas.push({
       ts: Time.fromRaw(it.ts),
-      scrollUpdateIds: it.scrollUpdateIds,
+      scrollUpdateId: it.scrollUpdateId,
       scrollOffset: offset,
       scrollDelta: it.deltaY,
     });
@@ -242,7 +233,11 @@
         },
         "tooltip": [
           {"field": "delta", "type": "quantitative", "title": "Delta"},
-          {"field": "scrollUpdateIds", "type": "nominal", "title": "Trace Ids"}
+          {
+            "field": "scrollUpdateId",
+            "type": "quantititive",
+            "title": "Trace Id"
+          }
         ]
       }
     }
@@ -262,7 +257,7 @@
     plotData.push({
       category: category,
       ts: Number(delta.ts) / 10e8,
-      scrollUpdateIds: delta.scrollUpdateIds,
+      scrollUpdateId: delta.scrollUpdateId,
       offset: delta.scrollOffset,
       delta: delta.scrollDelta,
     });
diff --git a/ui/src/tracks/chrome_scroll_jank/scroll_jank_v3_track.ts b/ui/src/tracks/chrome_scroll_jank/scroll_jank_v3_track.ts
index ba44b9b..fdb5ad1 100644
--- a/ui/src/tracks/chrome_scroll_jank/scroll_jank_v3_track.ts
+++ b/ui/src/tracks/chrome_scroll_jank/scroll_jank_v3_track.ts
@@ -76,8 +76,8 @@
     };
   }
 
-  onDestroy() {
-    super.onDestroy();
+  async onDestroy(): Promise<void> {
+    await super.onDestroy();
     ScrollJankPluginState.getInstance().unregisterTrack(ScrollJankV3Track.kind);
   }
 
diff --git a/ui/src/tracks/chrome_scroll_jank/scroll_track.ts b/ui/src/tracks/chrome_scroll_jank/scroll_track.ts
index 2967b97..8b47569 100644
--- a/ui/src/tracks/chrome_scroll_jank/scroll_track.ts
+++ b/ui/src/tracks/chrome_scroll_jank/scroll_track.ts
@@ -62,8 +62,8 @@
     });
   }
 
-  onDestroy() {
-    super.onDestroy();
+  async onDestroy(): Promise<void> {
+    await super.onDestroy();
     ScrollJankPluginState.getInstance().unregisterTrack(
       TopLevelScrollTrack.kind,
     );
diff --git a/ui/src/tracks/counter/index.ts b/ui/src/tracks/counter/index.ts
index 5fdf938..55773cd 100644
--- a/ui/src/tracks/counter/index.ts
+++ b/ui/src/tracks/counter/index.ts
@@ -136,22 +136,24 @@
     const time = visibleTimeScale.pxToHpTime(x).toTime('floor');
 
     const query = `
-      WITH X AS (
-        SELECT
-          id,
-          ts AS leftTs,
-          LEAD(ts) OVER (ORDER BY ts) AS rightTs
-        FROM counter
-        WHERE track_id = ${this.trackId}
-        ORDER BY ts
-      )
-      SELECT
+      select
         id,
-        leftTs,
-        rightTs
-      FROM X
-      WHERE rightTs > ${time}
-      LIMIT 1
+        ts as leftTs,
+        (
+          select ts
+          from ${this.rootTable}
+          where
+            track_id = ${this.trackId}
+            and ts >= ${time}
+          order by ts
+          limit 1
+        ) as rightTs
+      from ${this.rootTable}
+      where
+        track_id = ${this.trackId}
+        and ts < ${time}
+      order by ts DESC
+      limit 1
     `;
 
     this.engine.query(query).then((result) => {
diff --git a/ui/src/tracks/cpu_freq/index.ts b/ui/src/tracks/cpu_freq/index.ts
index 52708e9..b5fa5fa 100644
--- a/ui/src/tracks/cpu_freq/index.ts
+++ b/ui/src/tracks/cpu_freq/index.ts
@@ -12,13 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import {v4 as uuidv4} from 'uuid';
-
 import {BigintMath as BIMath} from '../../base/bigint_math';
 import {searchSegment} from '../../base/binary_search';
 import {assertTrue} from '../../base/logging';
 import {duration, time, Time} from '../../base/time';
-import {calcCachedBucketSize} from '../../common/cache_utils';
 import {drawTrackHoverTooltip} from '../../common/canvas_utils';
 import {colorForCpu} from '../../core/colorizer';
 import {TrackData} from '../../common/track_data';
@@ -33,20 +30,12 @@
   PluginDescriptor,
   Track,
 } from '../../public';
-import {
-  LONG,
-  LONG_NULL,
-  NUM,
-  NUM_NULL,
-  QueryResult,
-} from '../../trace_processor/query_result';
+import {LONG, NUM, NUM_NULL} from '../../trace_processor/query_result';
+import {uuidv4Sql} from '../../base/uuid';
 
 export const CPU_FREQ_TRACK_KIND = 'CpuFreqTrack';
 
 export interface Data extends TrackData {
-  maximumValue: number;
-  maxTsEnd: time;
-
   timestamps: BigInt64Array;
   minFreqKHz: Uint32Array;
   maxFreqKHz: Uint32Array;
@@ -58,8 +47,7 @@
   cpu: number;
   freqTrackId: number;
   idleTrackId?: number;
-  maximumValue?: number;
-  minimumValue?: number;
+  maximumValue: number;
 }
 
 // 0.5 Makes the horizontal lines sharp.
@@ -74,79 +62,72 @@
   private hoveredIdle: number | undefined = undefined;
   private fetcher = new TimelineFetcher<Data>(this.onBoundsChange.bind(this));
 
-  private maxDur: duration = 0n;
-  private maxTsEnd: time = Time.ZERO;
-  private maximumValueSeen = 0;
-  private cachedBucketSize = BIMath.INT64_MAX;
-
-  // This unique ID is just used to create the table names.
-  // In the future we should probably use the track instance ID, but for now we
-  // don't have access to it.
-  private uuid = uuidv4();
-
   private engine: EngineProxy;
   private config: Config;
+  private trackUuid = uuidv4Sql();
 
   constructor(config: Config, engine: EngineProxy) {
     this.config = config;
     this.engine = engine;
   }
 
-  // Returns a valid SQL table name with the given prefix that should be unique
-  // for each track.
-  private tableName(prefix: string) {
-    // Derive table name from, since that is unique for each track.
-    // Track ID can be UUID but '-' is not valid for sql table name.
-    const idSuffix = this.uuid.split('-').join('_');
-    return `${prefix}_${idSuffix}`;
-  }
-
   async onCreate() {
-    await this.createFreqIdleViews();
+    if (this.config.idleTrackId === undefined) {
+      await this.engine.execute(`
+        create view raw_freq_idle_${this.trackUuid} as
+        select ts, dur, value as freqValue, -1 as idleValue
+        from experimental_counter_dur c
+        where track_id = ${this.config.freqTrackId}
+      `);
+    } else {
+      await this.engine.execute(`
+        create view raw_freq_${this.trackUuid} as
+        select ts, dur, value as freqValue
+        from experimental_counter_dur c
+        where track_id = ${this.config.freqTrackId};
 
-    this.maximumValueSeen = await this.queryMaxFrequency();
-    this.maxDur = await this.queryMaxSourceDur();
+        create view raw_idle_${this.trackUuid} as
+        select
+          ts,
+          dur,
+          iif(value = 4294967295, -1, cast(value as int)) as idleValue
+        from experimental_counter_dur c
+        where track_id = ${this.config.idleTrackId};
 
-    const iter = (
-      await this.engine.query(`
-      select max(ts) as maxTs, dur, count(1) as rowCount
-      from ${this.tableName('freq_idle')}
-    `)
-    ).firstRow({maxTs: LONG_NULL, dur: LONG_NULL, rowCount: NUM});
-    if (iter.maxTs === null || iter.dur === null) {
-      // We shoulnd't really hit this because trackDecider shouldn't create
-      // the track in the first place if there are no entries. But could happen
-      // if only one cpu has no cpufreq data.
-      return;
-    }
-    this.maxTsEnd = Time.add(Time.fromRaw(iter.maxTs), iter.dur);
-
-    const rowCount = iter.rowCount;
-    const bucketSize = calcCachedBucketSize(rowCount);
-    if (bucketSize === undefined) {
-      return;
+        create virtual table raw_freq_idle_${this.trackUuid}
+        using span_join(raw_freq_${this.trackUuid}, raw_idle_${this.trackUuid});
+      `);
     }
 
-    await this.engine.query(`
-      create table ${this.tableName('freq_idle_cached')} as
-      select
-        (ts + ${bucketSize / 2n}) / ${bucketSize} * ${bucketSize} as cachedTsq,
-        min(freqValue) as minFreq,
-        max(freqValue) as maxFreq,
-        value_at_max_ts(ts, freqValue) as lastFreq,
-        value_at_max_ts(ts, idleValue) as lastIdleValue
-      from ${this.tableName('freq_idle')}
-      group by cachedTsq
-      order by cachedTsq
+    await this.engine.execute(`
+      create virtual table cpu_freq_${this.trackUuid}
+      using __intrinsic_counter_mipmap((
+        select ts, freqValue as value
+        from raw_freq_idle_${this.trackUuid}
+      ));
+
+      create virtual table cpu_idle_${this.trackUuid}
+      using __intrinsic_counter_mipmap((
+        select ts, idleValue as value
+        from raw_freq_idle_${this.trackUuid}
+      ));
     `);
-
-    this.cachedBucketSize = bucketSize;
   }
 
   async onUpdate() {
     await this.fetcher.requestDataForCurrentTime();
   }
 
+  async onDestroy(): Promise<void> {
+    if (this.engine.isAlive) {
+      await this.engine.query(`drop table cpu_freq_${this.trackUuid}`);
+      await this.engine.query(`drop table cpu_idle_${this.trackUuid}`);
+      await this.engine.query(`drop table raw_freq_idle_${this.trackUuid}`);
+      await this.engine.query(`drop view if exists raw_freq_${this.trackUuid}`);
+      await this.engine.query(`drop view if exists raw_idle_${this.trackUuid}`);
+    }
+  }
+
   async onBoundsChange(
     start: time,
     end: time,
@@ -156,164 +137,62 @@
     // function to make sense.
     assertTrue(BIMath.popcount(resolution) === 1, `${resolution} not pow of 2`);
 
-    const freqResult = await this.queryData(start, end, resolution);
-    assertTrue(freqResult.isComplete());
+    const freqResult = await this.engine.query(`
+      SELECT
+        min_value as minFreq,
+        max_value as maxFreq,
+        last_ts as ts,
+        last_value as lastFreq
+      FROM cpu_freq_${this.trackUuid}(
+        ${start},
+        ${end},
+        ${resolution}
+      );
+    `);
+    const idleResult = await this.engine.query(`
+      SELECT last_value as lastIdle
+      FROM cpu_idle_${this.trackUuid}(
+        ${start},
+        ${end},
+        ${resolution}
+      );
+    `);
 
-    const numRows = freqResult.numRows();
+    const freqRows = freqResult.numRows();
+    const idleRows = idleResult.numRows();
+    assertTrue(freqRows == idleRows);
+
     const data: Data = {
       start,
       end,
       resolution,
-      length: numRows,
-      maximumValue: this.maximumValue(),
-      maxTsEnd: this.maxTsEnd,
-      timestamps: new BigInt64Array(numRows),
-      minFreqKHz: new Uint32Array(numRows),
-      maxFreqKHz: new Uint32Array(numRows),
-      lastFreqKHz: new Uint32Array(numRows),
-      lastIdleValues: new Int8Array(numRows),
+      length: freqRows,
+      timestamps: new BigInt64Array(freqRows),
+      minFreqKHz: new Uint32Array(freqRows),
+      maxFreqKHz: new Uint32Array(freqRows),
+      lastFreqKHz: new Uint32Array(freqRows),
+      lastIdleValues: new Int8Array(freqRows),
     };
 
-    const it = freqResult.iter({
-      tsq: LONG,
+    const freqIt = freqResult.iter({
+      ts: LONG,
       minFreq: NUM,
       maxFreq: NUM,
       lastFreq: NUM,
-      lastIdleValue: NUM,
     });
-    for (let i = 0; it.valid(); ++i, it.next()) {
-      data.timestamps[i] = it.tsq;
-      data.minFreqKHz[i] = it.minFreq;
-      data.maxFreqKHz[i] = it.maxFreq;
-      data.lastFreqKHz[i] = it.lastFreq;
-      data.lastIdleValues[i] = it.lastIdleValue;
+    const idleIt = idleResult.iter({
+      lastIdle: NUM,
+    });
+    for (let i = 0; freqIt.valid(); ++i, freqIt.next(), idleIt.next()) {
+      data.timestamps[i] = freqIt.ts;
+      data.minFreqKHz[i] = freqIt.minFreq;
+      data.maxFreqKHz[i] = freqIt.maxFreq;
+      data.lastFreqKHz[i] = freqIt.lastFreq;
+      data.lastIdleValues[i] = idleIt.lastIdle;
     }
-
     return data;
   }
 
-  private async queryData(
-    start: time,
-    end: time,
-    bucketSize: duration,
-  ): Promise<QueryResult> {
-    const isCached = this.cachedBucketSize <= bucketSize;
-
-    if (isCached) {
-      return this.engine.query(`
-        select
-          cachedTsq / ${bucketSize} * ${bucketSize} as tsq,
-          min(minFreq) as minFreq,
-          max(maxFreq) as maxFreq,
-          value_at_max_ts(cachedTsq, lastFreq) as lastFreq,
-          value_at_max_ts(cachedTsq, lastIdleValue) as lastIdleValue
-        from ${this.tableName('freq_idle_cached')}
-        where
-          cachedTsq >= ${start - this.maxDur} and
-          cachedTsq <= ${end}
-        group by tsq
-        order by tsq
-      `);
-    }
-    const minTsFreq = await this.engine.query(`
-      select ifnull(max(ts), 0) as minTs from ${this.tableName('freq')}
-      where ts < ${start}
-    `);
-
-    let minTs = minTsFreq.iter({minTs: NUM}).minTs;
-    if (this.config.idleTrackId !== undefined) {
-      const minTsIdle = await this.engine.query(`
-        select ifnull(max(ts), 0) as minTs from ${this.tableName('idle')}
-        where ts < ${start}
-      `);
-      minTs = Math.min(minTsIdle.iter({minTs: NUM}).minTs, minTs);
-    }
-
-    const geqConstraint =
-      this.config.idleTrackId === undefined
-        ? `ts >= ${minTs}`
-        : `source_geq(ts, ${minTs})`;
-    return this.engine.query(`
-      select
-        (ts + ${bucketSize / 2n}) / ${bucketSize} * ${bucketSize} as tsq,
-        min(freqValue) as minFreq,
-        max(freqValue) as maxFreq,
-        value_at_max_ts(ts, freqValue) as lastFreq,
-        value_at_max_ts(ts, idleValue) as lastIdleValue
-      from ${this.tableName('freq_idle')}
-      where
-        ${geqConstraint} and
-        ts <= ${end}
-      group by tsq
-      order by tsq
-    `);
-  }
-
-  private async queryMaxFrequency(): Promise<number> {
-    const result = await this.engine.query(`
-      select max(freqValue) as maxFreq
-      from ${this.tableName('freq')}
-    `);
-    return result.firstRow({maxFreq: NUM_NULL}).maxFreq ?? 0;
-  }
-
-  private async queryMaxSourceDur(): Promise<duration> {
-    const maxDurFreqResult = await this.engine.query(
-      `select ifnull(max(dur), 0) as maxDur from ${this.tableName('freq')}`,
-    );
-    const maxDur = maxDurFreqResult.firstRow({maxDur: LONG}).maxDur;
-    if (this.config.idleTrackId === undefined) {
-      return maxDur;
-    }
-
-    const maxDurIdleResult = await this.engine.query(
-      `select ifnull(max(dur), 0) as maxDur from ${this.tableName('idle')}`,
-    );
-    return BIMath.max(maxDur, maxDurIdleResult.firstRow({maxDur: LONG}).maxDur);
-  }
-
-  private async createFreqIdleViews() {
-    await this.engine.query(`create view ${this.tableName('freq')} as
-      select
-        ts,
-        dur,
-        value as freqValue
-      from experimental_counter_dur c
-      where track_id = ${this.config.freqTrackId};
-    `);
-
-    if (this.config.idleTrackId === undefined) {
-      await this.engine.query(`create view ${this.tableName('freq_idle')} as
-        select
-          ts,
-          dur,
-          -1 as idleValue,
-          freqValue
-        from ${this.tableName('freq')};
-      `);
-      return;
-    }
-
-    await this.engine.query(`
-      create view ${this.tableName('idle')} as
-      select
-        ts,
-        dur,
-        iif(value = 4294967295, -1, cast(value as int)) as idleValue
-      from experimental_counter_dur c
-      where track_id = ${this.config.idleTrackId};
-    `);
-
-    await this.engine.query(`
-      create virtual table ${this.tableName('freq_idle')}
-      using span_join(${this.tableName('freq')}, ${this.tableName('idle')});
-    `);
-  }
-
-  private maximumValue() {
-    return Math.max(this.config.maximumValue ?? 0, this.maximumValueSeen);
-  }
-
   getHeight() {
     return MARGIN_TOP + RECT_HEIGHT;
   }
@@ -337,7 +216,7 @@
     const zeroY = MARGIN_TOP + RECT_HEIGHT;
 
     // Quantize the Y axis to quarters of powers of tens (7.5K, 10K, 12.5K).
-    let yMax = data.maximumValue;
+    let yMax = this.config.maximumValue;
     const kUnits = ['', 'K', 'M', 'G', 'T', 'E'];
     const exp = Math.ceil(Math.log10(Math.max(yMax, 1)));
     const pow10 = Math.pow(10, exp);
@@ -347,7 +226,6 @@
     // The values we have for cpufreq are in kHz so +1 to unitGroup.
     const yLabel = `${num} ${kUnits[unitGroup + 1]}Hz`;
 
-    // Draw the CPU frequency graph.
     const color = colorForCpu(this.config.cpu);
     let saturation = 45;
     if (globals.state.hoveredUtid !== -1) {
@@ -366,69 +244,69 @@
 
     const start = visibleWindowTime.start;
     const end = visibleWindowTime.end;
+
     const [rawStartIdx] = searchSegment(data.timestamps, start.toTime());
     const startIdx = rawStartIdx === -1 ? 0 : rawStartIdx;
 
     const [, rawEndIdx] = searchSegment(data.timestamps, end.toTime());
     const endIdx = rawEndIdx === -1 ? data.timestamps.length : rawEndIdx;
 
-    ctx.beginPath();
-    const timestamp = Time.fromRaw(data.timestamps[startIdx]);
-    ctx.moveTo(Math.max(calculateX(timestamp), 0), zeroY);
+    // Draw the CPU frequency graph.
+    {
+      ctx.beginPath();
+      const timestamp = Time.fromRaw(data.timestamps[startIdx]);
+      ctx.moveTo(Math.max(calculateX(timestamp), 0), zeroY);
 
-    let lastDrawnY = zeroY;
-    for (let i = startIdx; i < endIdx; i++) {
-      const timestamp = Time.fromRaw(data.timestamps[i]);
-      const x = calculateX(timestamp);
+      let lastDrawnY = zeroY;
+      for (let i = startIdx; i < endIdx; i++) {
+        const timestamp = Time.fromRaw(data.timestamps[i]);
+        const x = Math.max(0, calculateX(timestamp));
+        const minY = calculateY(data.minFreqKHz[i]);
+        const maxY = calculateY(data.maxFreqKHz[i]);
+        const lastY = calculateY(data.lastFreqKHz[i]);
 
-      const minY = calculateY(data.minFreqKHz[i]);
-      const maxY = calculateY(data.maxFreqKHz[i]);
-      const lastY = calculateY(data.lastFreqKHz[i]);
-
-      ctx.lineTo(x, lastDrawnY);
-      if (minY === maxY) {
-        assertTrue(lastY === minY);
-        ctx.lineTo(x, lastY);
-      } else {
-        ctx.lineTo(x, minY);
-        ctx.lineTo(x, maxY);
-        ctx.lineTo(x, lastY);
+        ctx.lineTo(x, lastDrawnY);
+        if (minY === maxY) {
+          assertTrue(lastY === minY);
+          ctx.lineTo(x, lastY);
+        } else {
+          ctx.lineTo(x, minY);
+          ctx.lineTo(x, maxY);
+          ctx.lineTo(x, lastY);
+        }
+        lastDrawnY = lastY;
       }
-      lastDrawnY = lastY;
+      ctx.lineTo(endPx, lastDrawnY);
+      ctx.lineTo(endPx, zeroY);
+      ctx.closePath();
+      ctx.fill();
+      ctx.stroke();
     }
-    // Find the end time for the last frequency event and then draw
-    // down to zero to show that we do not have data after that point.
-    const finalX = Math.min(calculateX(data.maxTsEnd), endPx);
-    ctx.lineTo(finalX, lastDrawnY);
-    ctx.lineTo(finalX, zeroY);
-    ctx.lineTo(endPx, zeroY);
-    ctx.closePath();
-    ctx.fill();
-    ctx.stroke();
 
     // Draw CPU idle rectangles that overlay the CPU freq graph.
     ctx.fillStyle = `rgba(240, 240, 240, 1)`;
+    {
+      for (let i = startIdx; i < endIdx; i++) {
+        if (data.lastIdleValues[i] < 0) {
+          continue;
+        }
 
-    for (let i = startIdx; i < endIdx; i++) {
-      if (data.lastIdleValues[i] < 0) {
-        continue;
+        // We intentionally don't use the floor function here when computing x
+        // coordinates. Instead we use floating point which prevents flickering as
+        // we pan and zoom; this relies on the browser anti-aliasing pixels
+        // correctly.
+        const timestamp = Time.fromRaw(data.timestamps[i]);
+        const x = visibleTimeScale.timeToPx(timestamp);
+        const xEnd =
+          i === data.lastIdleValues.length - 1
+            ? endPx
+            : visibleTimeScale.timeToPx(Time.fromRaw(data.timestamps[i + 1]));
+
+        const width = xEnd - x;
+        const height = calculateY(data.lastFreqKHz[i]) - zeroY;
+
+        ctx.fillRect(x, zeroY, width, height);
       }
-
-      // We intentionally don't use the floor function here when computing x
-      // coordinates. Instead we use floating point which prevents flickering as
-      // we pan and zoom; this relies on the browser anti-aliasing pixels
-      // correctly.
-      const timestamp = Time.fromRaw(data.timestamps[i]);
-      const x = visibleTimeScale.timeToPx(timestamp);
-      const xEnd =
-        i === data.lastIdleValues.length - 1
-          ? finalX
-          : visibleTimeScale.timeToPx(Time.fromRaw(data.timestamps[i + 1]));
-
-      const width = xEnd - x;
-      const height = calculateY(data.lastFreqKHz[i]) - zeroY;
-
-      ctx.fillRect(x, zeroY, width, height);
     }
 
     ctx.font = '10px Roboto Condensed';
@@ -504,6 +382,7 @@
     const time = visibleTimeScale.pxToHpTime(pos.x);
 
     const [left, right] = searchSegment(data.timestamps, time.toTime());
+
     this.hoveredTs =
       left === -1 ? undefined : Time.fromRaw(data.timestamps[left]);
     this.hoveredTsEnd =
@@ -529,16 +408,13 @@
     const maxCpuFreqResult = await engine.query(`
       select ifnull(max(value), 0) as freq
       from counter c
-      inner join cpu_counter_track t on c.track_id = t.id
+      join cpu_counter_track t on c.track_id = t.id
       where name = 'cpufreq';
     `);
     const maxCpuFreq = maxCpuFreqResult.firstRow({freq: NUM}).freq;
 
     for (const cpu of cpus) {
-      // Only add a cpu freq track if we have
-      // cpu freq data.
-      // TODO(hjd): Find a way to display cpu idle
-      // events even if there are no cpu freq events.
+      // Only add a cpu freq track if we have cpu freq data.
       const cpuFreqIdleResult = await engine.query(`
         select
           id as cpuFreqId,
diff --git a/ui/src/tracks/cpu_slices/index.ts b/ui/src/tracks/cpu_slices/index.ts
index 412ee6a..5c042dc 100644
--- a/ui/src/tracks/cpu_slices/index.ts
+++ b/ui/src/tracks/cpu_slices/index.ts
@@ -12,14 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import {v4 as uuidv4} from 'uuid';
-
 import {BigintMath as BIMath} from '../../base/bigint_math';
 import {search, searchEq, searchSegment} from '../../base/binary_search';
 import {assertExists, assertTrue} from '../../base/logging';
 import {Duration, duration, Time, time} from '../../base/time';
 import {Actions} from '../../common/actions';
-import {calcCachedBucketSize} from '../../common/cache_utils';
 import {getLegacySelection} from '../../common/state';
 import {
   cropText,
@@ -43,6 +40,7 @@
   Track,
 } from '../../public';
 import {LONG, NUM, STR_NULL} from '../../trace_processor/query_result';
+import {uuidv4Sql} from '../../base/uuid';
 
 export const CPU_SLICE_TRACK_KIND = 'CpuSliceTrack';
 
@@ -68,13 +66,11 @@
   private utidHoveredInThisTrack = -1;
   private fetcher = new TimelineFetcher<Data>(this.onBoundsChange.bind(this));
 
-  private uuid = uuidv4();
-  private cachedBucketSize = BIMath.INT64_MAX;
-  private maxDur: duration = 0n;
   private lastRowId = -1;
   private engine: EngineProxy;
   private cpu: number;
   private trackKey: string;
+  private trackUuid = uuidv4Sql();
 
   constructor(engine: EngineProxy, trackKey: string, cpu: number) {
     this.engine = engine;
@@ -82,62 +78,25 @@
     this.cpu = cpu;
   }
 
-  // Returns a valid SQL table name with the given prefix that should be unique
-  // for each track.
-  private tableName(prefix: string) {
-    // Derive table name from, since that is unique for each track.
-    // Track ID can be UUID but '-' is not valid for sql table name.
-    const idSuffix = this.uuid.split('-').join('_');
-    return `${prefix}_${idSuffix}`;
-  }
-
   async onCreate() {
     await this.engine.query(`
-      create view ${this.tableName('sched')} as
-      select
-        ts,
-        dur,
-        utid,
-        id,
-        dur = -1 as isIncomplete,
-        (case when priority < 100 then 1 else 0 end) as isRealtime
+      create virtual table cpu_slice_${this.trackUuid}
+      using __intrinsic_slice_mipmap((
+        select
+          id,
+          ts,
+          iif(dur = -1, lead(ts, 1, trace_end()) over (order by ts) - ts, dur),
+          0 as depth
+        from sched
+        where cpu = ${this.cpu} and utid != 0
+      ));
+    `);
+    const it = await this.engine.query(`
+      select coalesce(max(id), -1) as lastRowId
       from sched
       where cpu = ${this.cpu} and utid != 0
     `);
-
-    const queryRes = await this.engine.query(`
-      select ifnull(max(dur), 0) as maxDur, count(1) as rowCount
-      from ${this.tableName('sched')}
-    `);
-
-    const queryLastSlice = await this.engine.query(`
-      select ifnull(max(id), -1) as lastSliceId from ${this.tableName('sched')}
-    `);
-    this.lastRowId = queryLastSlice.firstRow({lastSliceId: NUM}).lastSliceId;
-
-    const row = queryRes.firstRow({maxDur: LONG, rowCount: NUM});
-    this.maxDur = row.maxDur;
-    const rowCount = row.rowCount;
-    const bucketSize = calcCachedBucketSize(rowCount);
-    if (bucketSize === undefined) {
-      return;
-    }
-
-    await this.engine.query(`
-      create table ${this.tableName('sched_cached')} as
-      select
-        (ts + ${bucketSize / 2n}) / ${bucketSize} * ${bucketSize} as cached_tsq,
-        ts,
-        max(dur) as dur,
-        utid,
-        id,
-        isIncomplete,
-        isRealtime
-      from ${this.tableName('sched')}
-      group by cached_tsq, isIncomplete
-      order by cached_tsq
-    `);
-    this.cachedBucketSize = bucketSize;
+    this.lastRowId = it.firstRow({lastRowId: NUM}).lastRowId;
   }
 
   async onUpdate() {
@@ -151,30 +110,16 @@
   ): Promise<Data> {
     assertTrue(BIMath.popcount(resolution) === 1, `${resolution} not pow of 2`);
 
-    const isCached = this.cachedBucketSize <= resolution;
-    const queryTsq = isCached
-      ? `cached_tsq / ${resolution} * ${resolution}`
-      : `(ts + ${resolution / 2n}) / ${resolution} * ${resolution}`;
-    const queryTable = isCached
-      ? this.tableName('sched_cached')
-      : this.tableName('sched');
-    const constraintColumn = isCached ? 'cached_tsq' : 'ts';
-
     const queryRes = await this.engine.query(`
       select
-        ${queryTsq} as tsq,
-        ts,
-        max(dur) as dur,
-        utid,
-        id,
-        isIncomplete,
-        isRealtime
-      from ${queryTable}
-      where
-        ${constraintColumn} >= ${start - this.maxDur} and
-        ${constraintColumn} <= ${end}
-      group by tsq, isIncomplete
-      order by tsq
+        (z.ts / ${resolution}) * ${resolution} as ts,
+        max(z.dur, ${resolution}) as dur,
+        s.utid,
+        s.id,
+        s.dur = -1 as isIncomplete,
+        ifnull(s.priority < 100, 0) as isRealtime
+      from cpu_slice_${this.trackUuid}(${start}, ${end}, ${resolution}) z
+      cross join sched s using (id)
     `);
 
     const numRows = queryRes.numRows();
@@ -192,7 +137,6 @@
     };
 
     const it = queryRes.iter({
-      tsq: LONG,
       ts: LONG,
       dur: LONG,
       utid: NUM,
@@ -201,19 +145,11 @@
       isRealtime: NUM,
     });
     for (let row = 0; it.valid(); it.next(), row++) {
-      const startQ = it.tsq;
       const start = it.ts;
       const dur = it.dur;
-      const end = start + dur;
 
-      // If the slice is incomplete, the end calculated later.
-      if (!it.isIncomplete) {
-        const minEnd = startQ + resolution;
-        const endQ = BIMath.max(BIMath.quant(end, resolution), minEnd);
-        slices.ends[row] = endQ;
-      }
-
-      slices.starts[row] = startQ;
+      slices.starts[row] = start;
+      slices.ends[row] = start + dur;
       slices.utids[row] = it.utid;
       slices.ids[row] = it.id;
 
@@ -225,26 +161,13 @@
         slices.flags[row] |= CPU_SLICE_FLAGS_REALTIME;
       }
     }
-
-    // If the slice is incomplete and it is the last slice in the track, the end
-    // of the slice would be the end of the visible window. Otherwise we end the
-    // slice with the beginning the next one.
-    for (let row = 0; row < slices.length; row++) {
-      if (!(slices.flags[row] & CPU_SLICE_FLAGS_INCOMPLETE)) {
-        continue;
-      }
-      const endTime = row === slices.length - 1 ? end : slices.starts[row + 1];
-      const minEnd = slices.starts[row] + resolution;
-      const endQ = BIMath.max(BIMath.quant(endTime, resolution), minEnd);
-      slices.ends[row] = endQ;
-    }
     return slices;
   }
 
   async onDestroy() {
     if (this.engine.isAlive) {
       await this.engine.query(
-        `drop table if exists ${this.tableName('sched_cached')}`,
+        `drop table if exists cpu_slice_${this.trackUuid}`,
       );
     }
     this.fetcher.dispose();
diff --git a/ui/src/tracks/debug/slice_track.ts b/ui/src/tracks/debug/slice_track.ts
index 4ea16dc..a53e4dc 100644
--- a/ui/src/tracks/debug/slice_track.ts
+++ b/ui/src/tracks/debug/slice_track.ts
@@ -90,13 +90,12 @@
     // TODO(altimin): Support removing this table when the track is closed.
     const dur = sliceColumns.dur === '0' ? 0 : sliceColumns.dur;
     await this.engine.query(`
-      create table ${this.sqlTableName} as
+      create perfetto table ${this.sqlTableName} as
       with data${dataColumns} as (
         ${data.sqlSource}
       ),
       prepared_data as (
         select
-          row_number() over () as id,
           ${sliceColumns.ts} as ts,
           ifnull(cast(${dur} as int), -1) as dur,
           printf('%s', ${sliceColumns.name}) as name
@@ -105,6 +104,7 @@
         from data
       )
       select
+        row_number() over (order by ts) as id,
         *
       from prepared_data
       order by ts;`);
diff --git a/ui/src/tracks/frames/index.ts b/ui/src/tracks/frames/index.ts
index 47e88ff..2cc877f 100644
--- a/ui/src/tracks/frames/index.ts
+++ b/ui/src/tracks/frames/index.ts
@@ -31,26 +31,17 @@
   async addExpectedFrames(ctx: PluginContextTrace): Promise<void> {
     const {engine} = ctx;
     const result = await engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where process_track.name = "Expected Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
-  `);
+        upid,
+        t.name as trackName,
+        t.track_ids as trackIds,
+        process.name as processName,
+        process.pid as pid,
+        __max_layout_depth(t.track_count, t.track_ids) as maxDepth
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name = "Expected Timeline"
+    `);
 
     const it = result.iter({
       upid: NUM,
@@ -58,7 +49,7 @@
       trackIds: STR,
       processName: STR_NULL,
       pid: NUM_NULL,
-      maxDepth: NUM_NULL,
+      maxDepth: NUM,
     });
 
     for (; it.valid(); it.next()) {
@@ -70,11 +61,6 @@
       const pid = it.pid;
       const maxDepth = it.maxDepth;
 
-      if (maxDepth === null) {
-        // If there are no slices in this track, skip it.
-        continue;
-      }
-
       const displayName = getTrackName({
         name: trackName,
         upid,
@@ -103,26 +89,17 @@
   async addActualFrames(ctx: PluginContextTrace): Promise<void> {
     const {engine} = ctx;
     const result = await engine.query(`
-      with process_async_tracks as materialized (
-        select
-          process_track.upid as upid,
-          process_track.name as trackName,
-          process.name as processName,
-          process.pid as pid,
-          group_concat(process_track.id) as trackIds,
-          count(1) as trackCount
-        from process_track
-        join process using(upid)
-        where process_track.name = "Actual Timeline"
-        group by
-          process_track.upid,
-          process_track.name
-      )
       select
-        t.*,
-        __max_layout_depth(t.trackCount, t.trackIds) as maxDepth
-      from process_async_tracks t;
-  `);
+        upid,
+        t.name as trackName,
+        t.track_ids as trackIds,
+        process.name as processName,
+        process.pid as pid,
+        __max_layout_depth(t.track_count, t.track_ids) as maxDepth
+      from _process_track_summary_by_upid_and_name t
+      join process using(upid)
+      where t.name = "Actual Timeline"
+    `);
 
     const it = result.iter({
       upid: NUM,
diff --git a/ui/src/tracks/ftrace/ftrace_explorer.ts b/ui/src/tracks/ftrace/ftrace_explorer.ts
index 9481b86..5e7eb32 100644
--- a/ui/src/tracks/ftrace/ftrace_explorer.ts
+++ b/ui/src/tracks/ftrace/ftrace_explorer.ts
@@ -24,27 +24,18 @@
   PopupMultiSelect,
 } from '../../widgets/multiselect';
 import {PopupPosition} from '../../widgets/popup';
-import {VirtualScrollContainer} from '../../widgets/virtual_scroll_container';
 
 import {globals} from '../../frontend/globals';
 import {Timestamp} from '../../frontend/widgets/timestamp';
 import {FtraceFilter, FtraceStat} from './common';
-import {
-  createStore,
-  EngineProxy,
-  LONG,
-  NUM,
-  Store,
-  STR,
-  STR_NULL,
-} from '../../public';
+import {EngineProxy, LONG, NUM, Store, STR, STR_NULL} from '../../public';
 import {raf} from '../../core/raf_scheduler';
 import {AsyncLimiter} from '../../base/async_limiter';
 import {Monitor} from '../../base/monitor';
 import {Button} from '../../widgets/button';
+import {VirtualTable, VirtualTableRow} from '../../widgets/virtual_table';
 
 const ROW_H = 20;
-const PAGE_SIZE = 250;
 
 interface FtraceExplorerAttrs {
   cache: FtraceExplorerCache;
@@ -69,8 +60,8 @@
 }
 
 interface Pagination {
-  page: number;
-  pageCount: number;
+  offset: number;
+  count: number;
 }
 
 export interface FtraceExplorerCache {
@@ -104,10 +95,10 @@
 }
 
 export class FtraceExplorer implements m.ClassComponent<FtraceExplorerAttrs> {
-  private readonly paginationStore = createStore<Pagination>({
-    page: 0,
-    pageCount: 0,
-  });
+  private pagination: Pagination = {
+    offset: 0,
+    count: 0,
+  };
   private readonly monitor: Monitor;
   private readonly queryLimiter = new AsyncLimiter();
 
@@ -119,7 +110,6 @@
       () => globals.state.frontendLocalState.visibleState.start,
       () => globals.state.frontendLocalState.visibleState.end,
       () => attrs.filterStore.state,
-      () => this.paginationStore.state,
     ]);
 
     if (attrs.cache.state === 'blank') {
@@ -136,60 +126,85 @@
   }
 
   view({attrs}: m.CVnode<FtraceExplorerAttrs>) {
-    this.monitor.ifStateChanged(() =>
-      this.queryLimiter.schedule(async () => {
-        this.data = await lookupFtraceEvents(
-          attrs.engine,
-          this.paginationStore.state.page * PAGE_SIZE,
-          this.paginationStore.state.pageCount * PAGE_SIZE,
-          attrs.filterStore.state,
-        );
-        raf.scheduleFullRedraw();
-      }),
-    );
+    this.monitor.ifStateChanged(() => {
+      this.reloadData(attrs);
+    });
 
     return m(
       DetailsShell,
       {
         title: this.renderTitle(),
         buttons: this.renderFilterPanel(attrs),
+        fillParent: true,
       },
-      m(
-        VirtualScrollContainer,
-        {
-          onScroll: this.onScroll.bind(this),
+      m(VirtualTable, {
+        className: 'pf-ftrace-explorer',
+        columns: [
+          {header: 'ID', width: '5em'},
+          {header: 'Timestamp', width: '13em'},
+          {header: 'Name', width: '24em'},
+          {header: 'CPU', width: '3em'},
+          {header: 'Process', width: '24em'},
+          {header: 'Args', width: '200em'},
+        ],
+        firstRowOffset: this.data?.offset ?? 0,
+        numRows: this.data?.numEvents ?? 0,
+        rowHeight: ROW_H,
+        rows: this.renderData(),
+        onReload: (offset, count) => {
+          this.pagination = {offset, count};
+          this.reloadData(attrs);
         },
-        m('.ftrace-panel', this.renderRows()),
-      ),
+        onRowHover: this.onRowOver.bind(this),
+        onRowOut: this.onRowOut.bind(this),
+      }),
     );
   }
 
-  onScroll(scrollContainer: HTMLElement) {
-    const paginationState = this.paginationStore.state;
-    const prevPage = paginationState.page;
-    const prevPageCount = paginationState.pageCount;
-
-    const visibleRowOffset = Math.floor(scrollContainer.scrollTop / ROW_H);
-    const visibleRowCount = Math.ceil(scrollContainer.clientHeight / ROW_H);
-
-    // Work out which "page" we're on
-    const page = Math.max(0, Math.floor(visibleRowOffset / PAGE_SIZE) - 1);
-    const pageCount = Math.ceil(visibleRowCount / PAGE_SIZE) + 2;
-
-    if (page !== prevPage || pageCount !== prevPageCount) {
-      this.paginationStore.edit((draft) => {
-        draft.page = page;
-        draft.pageCount = pageCount;
-      });
+  private reloadData(attrs: FtraceExplorerAttrs): void {
+    this.queryLimiter.schedule(async () => {
+      this.data = await lookupFtraceEvents(
+        attrs.engine,
+        this.pagination.offset,
+        this.pagination.count,
+        attrs.filterStore.state,
+      );
       raf.scheduleFullRedraw();
+    });
+  }
+
+  private renderData(): VirtualTableRow[] {
+    if (!this.data) {
+      return [];
+    }
+
+    return this.data.events.map((event) => {
+      const {ts, name, cpu, process, args, id} = event;
+      const timestamp = m(Timestamp, {ts});
+      const color = colorForFtrace(name).base.cssString;
+
+      return {
+        id,
+        cells: [
+          id,
+          timestamp,
+          m('', m('span.colour', {style: {background: color}}), name),
+          cpu,
+          process,
+          args,
+        ],
+      };
+    });
+  }
+
+  private onRowOver(id: number) {
+    const event = this.data?.events.find((event) => event.id === id);
+    if (event) {
+      globals.dispatch(Actions.setHoverCursorTimestamp({ts: event.ts}));
     }
   }
 
-  onRowOver(ts: time) {
-    globals.dispatch(Actions.setHoverCursorTimestamp({ts}));
-  }
-
-  onRowOut() {
+  private onRowOut() {
     globals.dispatch(Actions.setHoverCursorTimestamp({ts: Time.INVALID}));
   }
 
@@ -242,55 +257,6 @@
       },
     });
   }
-
-  // Render all the rows including the first title row
-  private renderRows() {
-    const data = this.data;
-    const rows: m.Children = [];
-
-    rows.push(
-      m(
-        `.row`,
-        m('.cell.row-header', 'Timestamp'),
-        m('.cell.row-header', 'Name'),
-        m('.cell.row-header', 'CPU'),
-        m('.cell.row-header', 'Process'),
-        m('.cell.row-header', 'Args'),
-      ),
-    );
-
-    if (data) {
-      const {events, offset, numEvents} = data;
-      for (let i = 0; i < events.length; i++) {
-        const {ts, name, cpu, process, args} = events[i];
-
-        const timestamp = m(Timestamp, {ts});
-
-        const rank = i + offset;
-
-        const color = colorForFtrace(name).base.cssString;
-
-        rows.push(
-          m(
-            `.row`,
-            {
-              style: {top: `${(rank + 1.0) * ROW_H}px`},
-              onmouseover: this.onRowOver.bind(this, ts),
-              onmouseout: this.onRowOut.bind(this),
-            },
-            m('.cell', timestamp),
-            m('.cell', m('span.colour', {style: {background: color}}), name),
-            m('.cell', cpu),
-            m('.cell', process),
-            m('.cell', args),
-          ),
-        );
-      }
-      return m('.rows', {style: {height: `${numEvents * ROW_H}px`}}, rows);
-    } else {
-      return m('.rows', rows);
-    }
-  }
 }
 
 async function lookupFtraceEvents(
diff --git a/ui/src/tracks/ftrace/ftrace_track.ts b/ui/src/tracks/ftrace/ftrace_track.ts
index 26c3f38..7b9def9 100644
--- a/ui/src/tracks/ftrace/ftrace_track.ts
+++ b/ui/src/tracks/ftrace/ftrace_track.ts
@@ -74,7 +74,6 @@
     const queryRes = await this.engine.query(`
       select
         cast(ts / ${resolution} as integer) * ${resolution} as tsQuant,
-        type,
         name
       from ftrace_event
       where
@@ -93,7 +92,7 @@
       names: [],
     };
 
-    const it = queryRes.iter({tsQuant: LONG, type: STR, name: STR});
+    const it = queryRes.iter({tsQuant: LONG, name: STR});
     for (let row = 0; it.valid(); it.next(), row++) {
       result.timestamps[row] = it.tsQuant;
       result.names[row] = it.name;
diff --git a/ui/src/tracks/ftrace/index.ts b/ui/src/tracks/ftrace/index.ts
index 7542232..3cc0616 100644
--- a/ui/src/tracks/ftrace/index.ts
+++ b/ui/src/tracks/ftrace/index.ts
@@ -97,7 +97,7 @@
 
     ctx.registerCommand({
       id: 'perfetto.FtraceRaw#ShowFtraceTab',
-      name: 'Show Ftrace Tab',
+      name: 'Show ftrace tab',
       callback: () => {
         ctx.tabs.showTab(ftraceTabUri);
       },
diff --git a/ui/src/tracks/process_summary/index.ts b/ui/src/tracks/process_summary/index.ts
index 47a93b0..ea6845f 100644
--- a/ui/src/tracks/process_summary/index.ts
+++ b/ui/src/tracks/process_summary/index.ts
@@ -12,17 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import {v4 as uuidv4} from 'uuid';
-
 import {Plugin, PluginContextTrace, PluginDescriptor} from '../../public';
-import {
-  LONG_NULL,
-  NUM,
-  NUM_NULL,
-  STR,
-  STR_NULL,
-} from '../../trace_processor/query_result';
-import {assertExists} from '../../base/logging';
+import {NUM, NUM_NULL} from '../../trace_processor/query_result';
 
 import {
   Config as ProcessSchedulingTrackConfig,
@@ -37,226 +28,101 @@
 
 // This plugin now manages both process "scheduling" and "summary" tracks.
 class ProcessSummaryPlugin implements Plugin {
-  private upidToUuid = new Map<number, string>();
-  private utidToUuid = new Map<number, string>();
-
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     await this.addProcessTrackGroups(ctx);
     await this.addKernelThreadSummary(ctx);
   }
 
   private async addProcessTrackGroups(ctx: PluginContextTrace): Promise<void> {
-    this.upidToUuid.clear();
-    this.utidToUuid.clear();
-
-    // We want to create groups of tracks in a specific order.
-    // The tracks should be grouped:
-    //    by upid
-    //    or (if upid is null) by utid
-    // the groups should be sorted by:
-    //  Chrome-based process rank based on process names (e.g. Browser)
-    //  has a heap profile or not
-    //  total cpu time *for the whole parent process*
-    //  process name
-    //  upid
-    //  thread name
-    //  utid
     const result = await ctx.engine.query(`
-    with candidateThreadsAndProcesses as materialized (
-      select upid, 0 as utid from process_track
-      union
-      select upid, 0 as utid from process_counter_track
-      union
-      select upid, utid from thread_counter_track join thread using(utid)
-      union
-      select upid, utid from thread_track join thread using(utid)
-      union
-      select upid, utid from (
-        select distinct utid from sched
-      ) join thread using(utid) group by utid
-      union
-      select upid, 0 as utid from (
-        select distinct utid from perf_sample where callsite_id is not null
-      ) join thread using (utid)
-      union
-      select upid, utid from (
-        select distinct utid from cpu_profile_stack_sample
-      ) join thread using(utid)
-      union
-      select upid as upid, 0 as utid from heap_profile_allocation
-      union
-      select upid as upid, 0 as utid from heap_graph_object
-    ),
-    schedSummary as materialized (
-      select
-        upid,
-        sum(thread_total_dur) as total_dur,
-        max(thread_max_dur) as total_max_dur,
-        sum(thread_event_count) as total_event_count
+      select *
       from (
         select
-          utid,
-          sum(dur) as thread_total_dur,
-          max(dur) as thread_max_dur,
-          count() as thread_event_count
-        from sched where dur != -1 and utid != 0
-        group by utid
+          _process_available_info_summary.upid,
+          null as utid,
+          pid,
+          null as tid,
+          process.name as processName,
+          null as threadName,
+          sum_running_dur > 0 as hasSched,
+          android_process_metadata.debuggable as isDebuggable
+        from _process_available_info_summary
+        join process using(upid)
+        left join android_process_metadata using(upid)
       )
-      join thread using (utid)
-      group by upid
-    ),
-    sliceSum as materialized (
-      select
-        process.upid as upid,
-        sum(cnt) as sliceCount
-      from (select track_id, count(*) as cnt from slice group by track_id)
-        left join thread_track on track_id = thread_track.id
-        left join thread on thread_track.utid = thread.utid
-        left join process_track on track_id = process_track.id
-        join process on process.upid = thread.upid
-          or process_track.upid = process.upid
-      where process.upid is not null
-      group by process.upid
-    )
-    select
-      the_tracks.upid,
-      the_tracks.utid,
-      total_dur as hasSched,
-      total_max_dur as schedMaxDur,
-      total_event_count as schedEventCount,
-      hasHeapProfiles,
-      process.pid as pid,
-      thread.tid as tid,
-      process.name as processName,
-      thread.name as threadName,
-      package_list.debuggable as isDebuggable,
-      ifnull((
-        select group_concat(string_value)
-        from args
-        where
-          process.arg_set_id is not null and
-          arg_set_id = process.arg_set_id and
-          flat_key = 'chrome.process_label'
-      ), '') AS chromeProcessLabels,
-      (case process.name
-         when 'Browser' then 3
-         when 'Gpu' then 2
-         when 'Renderer' then 1
-         else 0
-      end) as chromeProcessRank
-    from candidateThreadsAndProcesses the_tracks
-    left join schedSummary using(upid)
-    left join (
-      select
-        distinct(upid) as upid,
-        true as hasHeapProfiles
-      from heap_profile_allocation
-      union
-      select
-        distinct(upid) as upid,
-        true as hasHeapProfiles
-      from heap_graph_object
-    ) using (upid)
-    left join (
-      select
-        thread.upid as upid,
-        sum(cnt) as perfSampleCount
+      union all
+      select *
       from (
-          select utid, count(*) as cnt
-          from perf_sample where callsite_id is not null
-          group by utid
-      ) join thread using (utid)
-      group by thread.upid
-    ) using (upid)
-    left join sliceSum using (upid)
-    left join thread using(utid)
-    left join process using(upid)
-    left join package_list using(uid)
-    order by
-      chromeProcessRank desc,
-      hasHeapProfiles desc,
-      perfSampleCount desc,
-      total_dur desc,
-      sliceCount desc,
-      processName asc nulls last,
-      the_tracks.upid asc nulls last,
-      threadName asc nulls last,
-      the_tracks.utid asc nulls last;
+        select
+          null,
+          utid,
+          null as pid,
+          tid,
+          null as processName,
+          thread.name threadName,
+          sum_running_dur > 0 as hasSched,
+          0 as isDebuggable
+        from _thread_available_info_summary
+        join thread using (utid)
+        where upid is null
+      )
   `);
 
     const it = result.iter({
-      utid: NUM,
       upid: NUM_NULL,
-      tid: NUM_NULL,
+      utid: NUM_NULL,
       pid: NUM_NULL,
-      threadName: STR_NULL,
-      processName: STR_NULL,
+      tid: NUM_NULL,
       hasSched: NUM_NULL,
-      schedMaxDur: LONG_NULL,
-      schedEventCount: NUM_NULL,
-      hasHeapProfiles: NUM_NULL,
       isDebuggable: NUM_NULL,
-      chromeProcessLabels: STR,
     });
     for (; it.valid(); it.next()) {
-      const utid = it.utid;
-      const tid = it.tid;
       const upid = it.upid;
+      const utid = it.utid;
       const pid = it.pid;
+      const tid = it.tid;
       const hasSched = Boolean(it.hasSched);
-      const schedMaxDur = it.schedMaxDur;
-      const schedEventCount = it.schedEventCount;
       const isDebuggable = Boolean(it.isDebuggable);
 
       // Group by upid if present else by utid.
-      let pUuid =
-        upid === null ? this.utidToUuid.get(utid) : this.upidToUuid.get(upid);
-      // These should only happen once for each track group.
-      if (pUuid === undefined) {
-        pUuid = this.getOrCreateUuid(utid, upid);
-        const pidForColor = pid ?? tid ?? upid ?? utid ?? 0;
-        const type = hasSched ? 'schedule' : 'summary';
-        const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
+      const pidForColor = pid ?? tid ?? upid ?? utid ?? 0;
+      const type = hasSched ? 'schedule' : 'summary';
+      const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
 
-        if (hasSched) {
-          const config: ProcessSchedulingTrackConfig = {
-            pidForColor,
-            upid,
-            utid,
-          };
+      if (hasSched) {
+        const config: ProcessSchedulingTrackConfig = {
+          pidForColor,
+          upid,
+          utid,
+        };
 
-          ctx.registerTrack({
-            uri,
-            displayName: `${upid === null ? tid : pid} schedule`,
-            kind: PROCESS_SCHEDULING_TRACK_KIND,
-            tags: {
-              isDebuggable,
-            },
-            trackFactory: () =>
-              new ProcessSchedulingTrack(
-                ctx.engine,
-                config,
-                assertExists(schedMaxDur),
-                assertExists(schedEventCount),
-              ),
-          });
-        } else {
-          const config: ProcessSummaryTrackConfig = {
-            pidForColor,
-            upid,
-            utid,
-          };
+        ctx.registerTrack({
+          uri,
+          displayName: `${upid === null ? tid : pid} schedule`,
+          kind: PROCESS_SCHEDULING_TRACK_KIND,
+          tags: {
+            isDebuggable,
+          },
+          trackFactory: () => {
+            return new ProcessSchedulingTrack(ctx.engine, config);
+          },
+        });
+      } else {
+        const config: ProcessSummaryTrackConfig = {
+          pidForColor,
+          upid,
+          utid,
+        };
 
-          ctx.registerTrack({
-            uri,
-            displayName: `${upid === null ? tid : pid} summary`,
-            kind: PROCESS_SUMMARY_TRACK,
-            tags: {
-              isDebuggable,
-            },
-            trackFactory: () => new ProcessSummaryTrack(ctx.engine, config),
-          });
-        }
+        ctx.registerTrack({
+          uri,
+          displayName: `${upid === null ? tid : pid} summary`,
+          kind: PROCESS_SUMMARY_TRACK,
+          tags: {
+            isDebuggable,
+          },
+          trackFactory: () => new ProcessSummaryTrack(ctx.engine, config),
+        });
       }
     }
   }
@@ -313,25 +179,6 @@
       trackFactory: () => new ProcessSummaryTrack(ctx.engine, config),
     });
   }
-
-  private getOrCreateUuid(utid: number, upid: number | null) {
-    let uuid = this.getUuidUnchecked(utid, upid);
-    if (uuid === undefined) {
-      uuid = uuidv4();
-      if (upid === null) {
-        this.utidToUuid.set(utid, uuid);
-      } else {
-        this.upidToUuid.set(upid, uuid);
-      }
-    }
-    return uuid;
-  }
-
-  getUuidUnchecked(utid: number, upid: number | null) {
-    return upid === null
-      ? this.utidToUuid.get(utid)
-      : this.upidToUuid.get(upid);
-  }
 }
 
 export const plugin: PluginDescriptor = {
diff --git a/ui/src/tracks/process_summary/process_scheduling_track.ts b/ui/src/tracks/process_summary/process_scheduling_track.ts
index 07400ca..9725c29 100644
--- a/ui/src/tracks/process_summary/process_scheduling_track.ts
+++ b/ui/src/tracks/process_summary/process_scheduling_track.ts
@@ -12,14 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import {v4 as uuidv4} from 'uuid';
-
 import {BigintMath as BIMath} from '../../base/bigint_math';
 import {searchEq, searchRange} from '../../base/binary_search';
-import {assertTrue} from '../../base/logging';
+import {assertExists, assertTrue} from '../../base/logging';
 import {duration, time, Time} from '../../base/time';
 import {Actions} from '../../common/actions';
-import {calcCachedBucketSize} from '../../common/cache_utils';
 import {drawTrackHoverTooltip} from '../../common/canvas_utils';
 import {Color} from '../../core/color';
 import {colorForThread} from '../../core/colorizer';
@@ -30,6 +27,7 @@
 import {PanelSize} from '../../frontend/panel';
 import {EngineProxy, Track} from '../../public';
 import {LONG, NUM, QueryResult} from '../../trace_processor/query_result';
+import {uuidv4Sql} from '../../base/uuid';
 
 export const PROCESS_SCHEDULING_TRACK_KIND = 'ProcessSchedulingTrack';
 
@@ -50,8 +48,8 @@
 
 export interface Config {
   pidForColor: number;
-  upid: null | number;
-  utid: number;
+  upid: number | null;
+  utid: number | null;
 }
 
 export class ProcessSchedulingTrack implements Track {
@@ -59,60 +57,60 @@
   private utidHoveredInThisTrack = -1;
   private fetcher = new TimelineFetcher(this.onBoundsChange.bind(this));
   private maxCpu = 0;
-  private maxDur;
-  private eventCount;
-  private cachedBucketSize = BIMath.INT64_MAX;
   private engine: EngineProxy;
-  private uuid = uuidv4();
+  private trackUuid = uuidv4Sql();
   private config: Config;
 
-  constructor(
-    engine: EngineProxy,
-    config: Config,
-    maxDur: duration,
-    eventCount: number,
-  ) {
+  constructor(engine: EngineProxy, config: Config) {
     this.engine = engine;
     this.config = config;
-    this.maxDur = maxDur;
-    this.eventCount = eventCount;
-  }
-
-  // Returns a valid SQL table name with the given prefix that should be unique
-  // for each track.
-  private tableName(prefix: string) {
-    // Derive table name from, since that is unique for each track.
-    // Track ID can be UUID but '-' is not valid for sql table name.
-    const idSuffix = this.uuid.split('-').join('_');
-    return `${prefix}_${idSuffix}`;
   }
 
   async onCreate(): Promise<void> {
-    await this.createSchedView();
-
     const cpus = await this.engine.getCpus();
 
     // A process scheduling track should only exist in a trace that has cpus.
     assertTrue(cpus.length > 0);
     this.maxCpu = Math.max(...cpus) + 1;
 
-    const bucketSize = calcCachedBucketSize(this.eventCount);
-    if (bucketSize === undefined) {
-      return;
+    if (this.config.upid !== null) {
+      await this.engine.query(`
+        create virtual table process_scheduling_${this.trackUuid}
+        using __intrinsic_slice_mipmap((
+          select
+            id,
+            ts,
+            iif(
+              dur = -1,
+              lead(ts, 1, trace_end()) over (partition by cpu order by ts) - ts,
+              dur
+            ) as dur,
+            cpu as depth
+          from experimental_sched_upid
+          where
+            utid != 0 and
+            upid = ${this.config.upid}
+        ));
+      `);
+    } else {
+      assertExists(this.config.utid);
+      await this.engine.query(`
+        create virtual table process_scheduling_${this.trackUuid}
+        using __intrinsic_slice_mipmap((
+          select
+            id,
+            ts,
+            iif(
+              dur = -1,
+              lead(ts, 1, trace_end()) over (partition by cpu order by ts) - ts,
+              dur
+            ) as dur,
+            cpu as depth
+          from sched
+          where utid = ${this.config.utid}
+        ));
+      `);
     }
-    await this.engine.query(`
-      create table ${this.tableName('process_sched_cached')} as
-      select
-        (ts + ${bucketSize / 2n}) / ${bucketSize} * ${bucketSize} as cached_tsq,
-        ts,
-        max(dur) as dur,
-        cpu,
-        utid
-      from ${this.tableName('process_sched')}
-      group by cached_tsq, cpu
-      order by cached_tsq, cpu
-    `);
-    this.cachedBucketSize = bucketSize;
   }
 
   async onUpdate(): Promise<void> {
@@ -121,6 +119,11 @@
 
   async onDestroy(): Promise<void> {
     this.fetcher.dispose();
+    if (this.engine.isAlive) {
+      await this.engine.query(`
+        drop table process_scheduling_${this.trackUuid}
+      `);
+    }
   }
 
   async onBoundsChange(
@@ -128,8 +131,6 @@
     end: time,
     resolution: duration,
   ): Promise<Data> {
-    assertTrue(this.config.upid !== null);
-
     // Resolution must always be a power of 2 for this logic to work
     assertTrue(BIMath.popcount(resolution) === 1, `${resolution} not pow of 2`);
 
@@ -149,7 +150,6 @@
     };
 
     const it = queryRes.iter({
-      tsq: LONG,
       ts: LONG,
       dur: LONG,
       cpu: NUM,
@@ -157,61 +157,35 @@
     });
 
     for (let row = 0; it.valid(); it.next(), row++) {
-      const startQ = Time.fromRaw(it.tsq);
       const start = Time.fromRaw(it.ts);
       const dur = it.dur;
       const end = Time.add(start, dur);
-      const minEnd = Time.add(startQ, resolution);
-      const endQ = Time.max(Time.quant(end, resolution), minEnd);
 
-      slices.starts[row] = startQ;
-      slices.ends[row] = endQ;
+      slices.starts[row] = start;
+      slices.ends[row] = end;
       slices.cpus[row] = it.cpu;
       slices.utids[row] = it.utid;
-      slices.end = Time.max(endQ, slices.end);
+      slices.end = Time.max(end, slices.end);
     }
     return slices;
   }
 
-  private queryData(
+  private async queryData(
     start: time,
     end: time,
     bucketSize: duration,
   ): Promise<QueryResult> {
-    const isCached = this.cachedBucketSize <= bucketSize;
-    const tsq = isCached
-      ? `cached_tsq / ${bucketSize} * ${bucketSize}`
-      : `(ts + ${bucketSize / 2n}) / ${bucketSize} * ${bucketSize}`;
-    const queryTable = isCached
-      ? this.tableName('process_sched_cached')
-      : this.tableName('process_sched');
-    const constraintColumn = isCached ? 'cached_tsq' : 'ts';
-
-    // The mouse move handler depends on slices being sorted by cpu then tsq
     return this.engine.query(`
       select
-        ${tsq} as tsq,
-        ts,
-        max(dur) as dur,
-        cpu,
+        (z.ts / ${bucketSize}) * ${bucketSize} as ts,
+        iif(s.dur = -1, s.dur, max(z.dur, ${bucketSize})) as dur,
+        s.id,
+        z.depth as cpu,
         utid
-      from ${queryTable}
-      where
-        ${constraintColumn} >= ${start - this.maxDur} and
-        ${constraintColumn} <= ${end}
-      group by tsq, cpu
-      order by cpu, tsq
-    `);
-  }
-
-  private async createSchedView() {
-    await this.engine.query(`
-      create view ${this.tableName('process_sched')} as
-      select ts, dur, cpu, utid
-      from experimental_sched_upid
-      where
-        utid != 0 and
-        upid = ${this.config.upid}
+      from process_scheduling_${this.trackUuid}(
+        ${start}, ${end}, ${bucketSize}
+      ) z
+      cross join sched s using (id)
     `);
   }
 
@@ -252,10 +226,9 @@
       const utid = data.utids[i];
       const cpu = data.cpus[i];
 
-      const rectStart = visibleTimeScale.timeToPx(tStart);
-      const rectEnd = visibleTimeScale.timeToPx(tEnd);
-      const rectWidth = rectEnd - rectStart;
-      if (rectWidth < 0.3) continue;
+      const rectStart = Math.floor(visibleTimeScale.timeToPx(tStart));
+      const rectEnd = Math.floor(visibleTimeScale.timeToPx(tEnd));
+      const rectWidth = Math.max(1, rectEnd - rectStart);
 
       const threadInfo = globals.threads.get(utid);
       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
@@ -277,7 +250,7 @@
       }
       ctx.fillStyle = color.cssString;
       const y = MARGIN_TOP + cpuTrackHeight * cpu + cpu;
-      ctx.fillRect(rectStart, y, rectEnd - rectStart, cpuTrackHeight);
+      ctx.fillRect(rectStart, y, rectWidth, cpuTrackHeight);
     }
 
     const hoveredThread = globals.threads.get(this.utidHoveredInThisTrack);
diff --git a/ui/src/tracks/process_summary/process_summary_track.ts b/ui/src/tracks/process_summary/process_summary_track.ts
index 6a8e687..7acf36b 100644
--- a/ui/src/tracks/process_summary/process_summary_track.ts
+++ b/ui/src/tracks/process_summary/process_summary_track.ts
@@ -15,7 +15,7 @@
 import {v4 as uuidv4} from 'uuid';
 
 import {BigintMath} from '../../base/bigint_math';
-import {assertFalse} from '../../base/logging';
+import {assertExists, assertFalse} from '../../base/logging';
 import {duration, Time, time} from '../../base/time';
 import {colorForTid} from '../../core/colorizer';
 import {LIMIT, TrackData} from '../../common/track_data';
@@ -37,7 +37,7 @@
 export interface Config {
   pidForColor: number;
   upid: number | null;
-  utid: number;
+  utid: number | null;
 }
 
 const MARGIN_TOP = 5;
@@ -70,7 +70,7 @@
       `create virtual table ${this.tableName('window')} using window;`,
     );
 
-    let utids = [this.config.utid];
+    let utids: number[];
     // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
     if (this.config.upid) {
       const threadQuery = await this.engine.query(
@@ -80,6 +80,8 @@
       for (const it = threadQuery.iter({utid: NUM}); it.valid(); it.next()) {
         utids.push(it.utid);
       }
+    } else {
+      utids = [assertExists(this.config.utid)];
     }
 
     const trackQuery = await this.engine.query(
diff --git a/ui/src/tracks/sched/index.ts b/ui/src/tracks/sched/index.ts
index a8b4b76..ccebaa1 100644
--- a/ui/src/tracks/sched/index.ts
+++ b/ui/src/tracks/sched/index.ts
@@ -44,18 +44,18 @@
   onActivate(ctx: PluginContext): void {
     ctx.registerCommand({
       id: 'dev.perfetto.Sched.AddRunnableThreadCountTrackCommand',
-      name: 'Add runnable thread count track',
+      name: 'Add track: runnable thread count',
       callback: () => addRunnableThreadCountTrack(),
     });
     ctx.registerCommand({
       id: 'dev.perfetto.Sched.AddActiveCPUCountTrackCommand',
-      name: 'Add active CPU count track',
+      name: 'Add track: active CPU count',
       callback: () => addActiveCPUCountTrack(),
     });
     for (const cpuType of ['big', 'little', 'mid']) {
       ctx.registerCommand({
         id: `dev.perfetto.Sched.AddActiveCPUCountTrackCommand.${cpuType}`,
-        name: `Add active ${cpuType} CPU count track`,
+        name: `Add track: active ${cpuType} CPU count`,
         callback: () => addActiveCPUCountTrack(cpuType),
       });
     }
diff --git a/ui/src/tracks/thread_state/index.ts b/ui/src/tracks/thread_state/index.ts
index b38eb1d..73e2faf 100644
--- a/ui/src/tracks/thread_state/index.ts
+++ b/ui/src/tracks/thread_state/index.ts
@@ -32,14 +32,14 @@
   async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
     const {engine} = ctx;
     const result = await engine.query(`
-      with ts_distinct as materialized (select distinct utid from thread_state)
       select
         utid,
         upid,
         tid,
         thread.name as threadName
       from thread
-      where utid != 0 and utid in ts_distinct`);
+      join _sched_summary using (utid)
+    `);
 
     const it = result.iter({
       utid: NUM,
diff --git a/ui/src/widgets/details_shell.ts b/ui/src/widgets/details_shell.ts
index 159d016..e323d37 100644
--- a/ui/src/widgets/details_shell.ts
+++ b/ui/src/widgets/details_shell.ts
@@ -20,7 +20,8 @@
   title: m.Children;
   description?: m.Children;
   buttons?: m.Children;
-  // Stretch/shrink the content to fill the parent vertically.
+
+  // Vertically fill parent container and disable scrolling
   fillParent?: boolean;
 }
 
diff --git a/ui/src/widgets/virtual_scroll_container.ts b/ui/src/widgets/virtual_scroll_container.ts
deleted file mode 100644
index f6bd052..0000000
--- a/ui/src/widgets/virtual_scroll_container.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (C) 2023 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 m from 'mithril';
-
-import {findRef, toHTMLElement} from '../base/dom_utils';
-
-interface VirtualScrollContainerAttrs {
-  // Called when the scrolling element is created, updates, or scrolls.
-  onScroll?: (dom: HTMLElement) => void;
-}
-
-export class VirtualScrollContainer
-  implements m.ClassComponent<VirtualScrollContainerAttrs>
-{
-  private readonly REF = 'virtual-scroll-container';
-  view({attrs, children}: m.Vnode<VirtualScrollContainerAttrs>) {
-    const {onScroll = () => {}} = attrs;
-
-    return m(
-      '.pf-virtual-scroll-container',
-      {
-        ref: this.REF,
-        onscroll: (e: Event) => onScroll(e.target as HTMLElement),
-      },
-      children,
-    );
-  }
-
-  oncreate({dom, attrs}: m.VnodeDOM<VirtualScrollContainerAttrs, this>) {
-    const {onScroll = () => {}} = attrs;
-
-    const element = findRef(dom, this.REF);
-    if (element) {
-      onScroll(toHTMLElement(element));
-    }
-  }
-}
diff --git a/ui/src/widgets/virtual_scroll_helper.ts b/ui/src/widgets/virtual_scroll_helper.ts
new file mode 100644
index 0000000..4fbe5c1
--- /dev/null
+++ b/ui/src/widgets/virtual_scroll_helper.ts
@@ -0,0 +1,150 @@
+// 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 {Trash} from '../base/disposable';
+import * as Geometry from '../base/geom';
+
+export interface VirtualScrollHelperOpts {
+  overdrawPx: number;
+
+  // How close we can get to undrawn regions before updating
+  tolerancePx: number;
+
+  callback: (r: Geometry.Rect) => void;
+}
+
+export interface Data {
+  opts: VirtualScrollHelperOpts;
+  rect?: Geometry.Rect;
+}
+
+export class VirtualScrollHelper {
+  private readonly _trash = new Trash();
+  private readonly _data: Data[] = [];
+
+  constructor(
+    sliderElement: HTMLElement,
+    containerElement: Element,
+    opts: VirtualScrollHelperOpts[] = [],
+  ) {
+    this._data = opts.map((opts) => {
+      return {opts};
+    });
+
+    const recalculateRects = () => {
+      this._data.forEach((data) =>
+        recalculatePuckRect(sliderElement, containerElement, data),
+      );
+    };
+
+    containerElement.addEventListener('scroll', recalculateRects, {
+      passive: true,
+    });
+    this._trash.addCallback(() =>
+      containerElement.removeEventListener('scroll', recalculateRects),
+    );
+
+    // Resize observer callbacks are called once immediately
+    const resizeObserver = new ResizeObserver(() => {
+      recalculateRects();
+    });
+
+    resizeObserver.observe(containerElement);
+    resizeObserver.observe(sliderElement);
+    this._trash.addCallback(() => {
+      resizeObserver.disconnect();
+    });
+  }
+
+  dispose() {
+    this._trash.dispose();
+  }
+}
+
+function recalculatePuckRect(
+  sliderElement: HTMLElement,
+  containerElement: Element,
+  data: Data,
+): void {
+  const {tolerancePx, overdrawPx, callback} = data.opts;
+  if (!data.rect) {
+    const targetPuckRect = getTargetPuckRect(
+      sliderElement,
+      containerElement,
+      overdrawPx,
+    );
+    callback(targetPuckRect);
+    data.rect = targetPuckRect;
+  } else {
+    const viewportRect = containerElement.getBoundingClientRect();
+
+    // Expand the viewportRect by the tolerance
+    const viewportExpandedRect = Geometry.expandRect(viewportRect, tolerancePx);
+
+    const sliderClientRect = sliderElement.getBoundingClientRect();
+    const viewportClamped = Geometry.intersectRects(
+      viewportExpandedRect,
+      sliderClientRect,
+    );
+
+    // Translate the puck rect into client space (currently in slider space)
+    const puckClientRect = Geometry.translateRect(data.rect, {
+      x: sliderClientRect.x,
+      y: sliderClientRect.y,
+    });
+
+    // Check if the tolerance rect entirely contains the expanded viewport rect
+    // If not, request an update
+    if (!Geometry.containsRect(puckClientRect, viewportClamped)) {
+      const targetPuckRect = getTargetPuckRect(
+        sliderElement,
+        containerElement,
+        overdrawPx,
+      );
+      callback(targetPuckRect);
+      data.rect = targetPuckRect;
+    }
+  }
+}
+
+// Returns what the puck rect should look like
+function getTargetPuckRect(
+  sliderElement: HTMLElement,
+  containerElement: Element,
+  overdrawPx: number,
+) {
+  const sliderElementRect = sliderElement.getBoundingClientRect();
+  const containerRect = containerElement.getBoundingClientRect();
+
+  // Calculate the intersection of the container's viewport and the target
+  const intersection = Geometry.intersectRects(
+    containerRect,
+    sliderElementRect,
+  );
+
+  // Pad the intersection by the overdraw amount
+  const intersectionExpanded = Geometry.expandRect(intersection, overdrawPx);
+
+  // Intersect with the original target rect unless we want to avoid resizes
+  const targetRect = Geometry.intersectRects(
+    intersectionExpanded,
+    sliderElementRect,
+  );
+
+  return Geometry.rebaseRect(
+    targetRect,
+    sliderElementRect.x,
+    sliderElementRect.y,
+  );
+}
diff --git a/ui/src/widgets/virtual_table.ts b/ui/src/widgets/virtual_table.ts
new file mode 100644
index 0000000..0b97b96
--- /dev/null
+++ b/ui/src/widgets/virtual_table.ts
@@ -0,0 +1,262 @@
+// 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 m from 'mithril';
+import {Trash} from '../base/disposable';
+import {findRef, toHTMLElement} from '../base/dom_utils';
+import {Rect} from '../base/geom';
+import {assertExists} from '../base/logging';
+import {Style} from './common';
+import {scheduleFullRedraw} from './raf';
+import {VirtualScrollHelper} from './virtual_scroll_helper';
+
+/**
+ * The |VirtualTable| widget can be useful when attempting to render a large
+ * amount of tabular data - i.e. dumping the entire contents of a database
+ * table.
+ *
+ * A naive approach would be to load the entire dataset from the table and
+ * render it into the DOM. However, this has a number of disadvantages:
+ * - The query could potentially be very slow on large enough datasets.
+ * - The amount of data pulled could be larger than the available memory.
+ * - Rendering thousands of DOM elements using Mithril can get be slow.
+ * - Asking the browser to create and update thousands of elements on the DOM
+ *   can also be slow.
+ *
+ * This implementation takes advantage of the fact that computer monitors are
+ * only so tall, so most will only be able to display a small subset of rows at
+ * a given time, and the user will have to scroll to reveal more data.
+ *
+ * Thus, this widgets operates in such a way as to only render the DOM elements
+ * that are visible within the given scrolling container's viewport. To avoid
+ * spamming render updates, we render a few more rows above and below the
+ * current viewport, and only trigger an update once the user scrolls too close
+ * to the edge of the rendered data. These margins and tolerances are
+ * configurable with the |renderOverdrawPx| and |renderTolerancePx| attributes.
+ *
+ * When it comes to loading data, it's often more performant to run fewer large
+ * queries compared to more frequent smaller queries. Running a new query every
+ * time we want to update the DOM is usually too frequent, and results in
+ * flickering as the data is usually not loaded at the time the relevant row
+ * scrolls into view.
+ *
+ * Thus, this implementation employs two sets of limits, one to refresh the DOM
+ * and one larger one to re-query the data. The latter may be configured using
+ * the |queryOverdrawPx| and |queryTolerancePx| attributes.
+ *
+ * The smaller DOM refreshes and handled internally, but the user must be called
+ * to invoke a new query update. When new data is required, the |onReload|
+ * callback is called with the row offset and count.
+ *
+ * The data must be passed in the |data| attribute which contains the offset of
+ * the currently loaded data and a number of rows.
+ *
+ * Row and column content is flexible as m.Children are accepted and passed
+ * straight to mithril.
+ *
+ * The widget is quite opinionated in terms of its styling, but the entire
+ * widget and each row may be tweaked using |className| and |style| attributes
+ * which behave in the same way as they do on other Mithril components.
+ */
+
+export interface VirtualTableAttrs {
+  // A list of columns containing the header row content and column widths
+  columns: VirtualTableColumn[];
+
+  // Row height in px (each row must have the same height)
+  rowHeight: number;
+
+  // Offset of the first row
+  firstRowOffset: number;
+
+  // Total number of rows
+  numRows: number;
+
+  // The row data to render
+  rows: VirtualTableRow[];
+
+  // Optional: Called when we need to reload data
+  onReload?: (rowOffset: number, rowCount: number) => void;
+
+  // Additional class name applied to the table container element
+  className?: string;
+
+  // Additional styles applied to the table container element
+  style?: Style;
+
+  // Optional: Called when a row is hovered, passing the hovered row's id
+  onRowHover?: (id: number) => void;
+
+  // Optional: Called when a row is un-hovered, passing the un-hovered row's id
+  onRowOut?: (id: number) => void;
+
+  // Optional: Number of pixels equivalent of rows to overdraw above and below
+  // the viewport
+  // Defaults to a sensible value
+  renderOverdrawPx?: number;
+
+  // Optional: How close we can get to the edge before triggering a DOM redraw
+  // Defaults to a sensible value
+  renderTolerancePx?: number;
+
+  // Optional: Number of pixels equivalent of rows to query above and below the
+  // viewport
+  // Defaults to a sensible value
+  queryOverdrawPx?: number;
+
+  // Optional: How close we can get to the edge if the loaded data before we
+  // trigger another query
+  // Defaults to a sensible value
+  queryTolerancePx?: number;
+}
+
+export interface VirtualTableColumn {
+  // Content to render in the header row
+  header: m.Children;
+
+  // CSS width e.g. 12px, 4em, etc...
+  width: string;
+}
+
+export interface VirtualTableRow {
+  // Id for this row (must be unique within this dataset)
+  // Used for callbacks and as a Mithril key.
+  id: number;
+
+  // Data for each column in this row - must match number of elements in columns
+  cells: m.Children[];
+
+  // Optional: Additional class name applied to the row element
+  className?: string;
+}
+
+export class VirtualTable implements m.ClassComponent<VirtualTableAttrs> {
+  private readonly CONTAINER_REF = 'CONTAINER';
+  private readonly SLIDER_REF = 'SLIDER';
+  private readonly trash = new Trash();
+  private renderBounds = {rowStart: 0, rowEnd: 0};
+
+  view({attrs}: m.Vnode<VirtualTableAttrs>): m.Children {
+    const {columns, className, numRows, rowHeight, style} = attrs;
+    return m(
+      '.pf-vtable',
+      {className, style, ref: this.CONTAINER_REF},
+      m(
+        '.pf-vtable-content',
+        m(
+          '.pf-vtable-header',
+          columns.map((col) =>
+            m('.pf-vtable-data', {style: {width: col.width}}, col.header),
+          ),
+        ),
+        m(
+          '.pf-vtable-slider',
+          {ref: this.SLIDER_REF, style: {height: `${rowHeight * numRows}px`}},
+          m(
+            '.pf-vtable-puck',
+            {
+              style: {
+                transform: `translateY(${
+                  this.renderBounds.rowStart * rowHeight
+                }px)`,
+              },
+            },
+            this.renderContent(attrs),
+          ),
+        ),
+      ),
+    );
+  }
+
+  private renderContent(attrs: VirtualTableAttrs): m.Children {
+    const rows: m.ChildArray = [];
+    for (
+      let i = this.renderBounds.rowStart;
+      i < this.renderBounds.rowEnd;
+      ++i
+    ) {
+      rows.push(this.renderRow(attrs, i));
+    }
+    return rows;
+  }
+
+  private renderRow(attrs: VirtualTableAttrs, i: number): m.Children {
+    const {rows, firstRowOffset, rowHeight, columns, onRowHover, onRowOut} =
+      attrs;
+    if (i >= firstRowOffset && i < firstRowOffset + rows.length) {
+      // Render the row...
+      const index = i - firstRowOffset;
+      const rowData = rows[index];
+      return m(
+        '.pf-vtable-row',
+        {
+          className: rowData.className,
+          style: {height: `${rowHeight}px`},
+          onmouseover: () => {
+            onRowHover?.(rowData.id);
+          },
+          onmouseout: () => {
+            onRowOut?.(rowData.id);
+          },
+        },
+        rowData.cells.map((data, colIndex) =>
+          m('.pf-vtable-data', {style: {width: columns[colIndex].width}}, data),
+        ),
+      );
+    } else {
+      // Render a placeholder div with the same height as a row but a
+      // transparent background
+      return m('', {style: {height: `${rowHeight}px`}});
+    }
+  }
+
+  oncreate({dom, attrs}: m.VnodeDOM<VirtualTableAttrs>) {
+    const {
+      renderOverdrawPx = 200,
+      renderTolerancePx = 100,
+      queryOverdrawPx = 10_000,
+      queryTolerancePx = 5_000,
+    } = attrs;
+
+    const sliderEl = toHTMLElement(assertExists(findRef(dom, this.SLIDER_REF)));
+    const containerEl = assertExists(findRef(dom, this.CONTAINER_REF));
+    const virtualScrollHelper = new VirtualScrollHelper(sliderEl, containerEl, [
+      {
+        overdrawPx: renderOverdrawPx,
+        tolerancePx: renderTolerancePx,
+        callback: ({top, bottom}: Rect) => {
+          const height = bottom - top;
+          const rowStart = Math.floor(top / attrs.rowHeight / 2) * 2;
+          const rowCount = Math.ceil(height / attrs.rowHeight / 2) * 2;
+          this.renderBounds = {rowStart, rowEnd: rowStart + rowCount};
+          scheduleFullRedraw();
+        },
+      },
+      {
+        overdrawPx: queryOverdrawPx,
+        tolerancePx: queryTolerancePx,
+        callback: ({top, bottom}: Rect) => {
+          const rowStart = Math.floor(top / attrs.rowHeight / 2) * 2;
+          const rowEnd = Math.ceil(bottom / attrs.rowHeight);
+          attrs.onReload?.(rowStart, rowEnd - rowStart);
+        },
+      },
+    ]);
+    this.trash.add(virtualScrollHelper);
+  }
+
+  onremove(_: m.VnodeDOM<VirtualTableAttrs>) {
+    this.trash.dispose();
+  }
+}