Merge "Add pivot tables to perfetto docs"
diff --git a/CHANGELOG b/CHANGELOG
index 128093a..0861716 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,10 @@
   Tracing service and probes:
     * Removed DCHECK that would cause crashes when a debug build of the service
       is used with a producer built with -DNDEBUG.
+    * Changed the service-side field-level filtering configuration protobuf
+      field number, because the feature had a bug. This is effectively
+      equivalent to deprecating the feature and reintroducing it under a
+      different name.
   Trace Processor:
     * Added reqiurement of separating queries by semi-colon (;) followed by
       new-line when specifying a query file with -q to trace processor shell.
diff --git a/protos/perfetto/config/perfetto_config.proto b/protos/perfetto/config/perfetto_config.proto
index c173c1c..2394168 100644
--- a/protos/perfetto/config/perfetto_config.proto
+++ b/protos/perfetto/config/perfetto_config.proto
@@ -1490,7 +1490,7 @@
 // It contains the general config for the logging buffer(s) and the configs for
 // all the data source being enabled.
 //
-// Next id: 33.
+// Next id: 34.
 message TraceConfig {
   message BufferConfig {
     optional uint32 size_kb = 1;
@@ -1890,10 +1890,17 @@
   // provided. The filter is applied at ReadBuffers() time and works both in the
   // case of IPC readback and write_into_file. This filter can be generated
   // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or
-  // `-T filter_out.escaped_string` (for .pbtx).
-  // Introduced in Android S. See go/trace-filtering for design.
-  message TraceFilter { optional bytes bytecode = 1; }
-  optional TraceFilter trace_filter = 32;
+  // `-T filter_out.escaped_string` (for .pbtx). See go/trace-filtering for
+  // design.
+  //
+  // Introduced in Android S, but it was broken (b/195065199). Reintroduced in
+  // Android T with a different field number.
+  message TraceFilter {
+    optional bytes bytecode = 1;
+  }
+  // old field number for trace_filter
+  reserved 32;
+  optional TraceFilter trace_filter = 33;
 }
 
 // End of protos/perfetto/config/trace_config.proto
diff --git a/protos/perfetto/config/trace_config.proto b/protos/perfetto/config/trace_config.proto
index dbc1bab..e845f17 100644
--- a/protos/perfetto/config/trace_config.proto
+++ b/protos/perfetto/config/trace_config.proto
@@ -16,17 +16,17 @@
 
 syntax = "proto2";
 
-import "protos/perfetto/config/data_source_config.proto";
-import "protos/perfetto/common/builtin_clock.proto";
-
 package perfetto.protos;
 
+import "protos/perfetto/common/builtin_clock.proto";
+import "protos/perfetto/config/data_source_config.proto";
+
 // The overall config that is used when starting a new tracing session through
 // ProducerPort::StartTracing().
 // It contains the general config for the logging buffer(s) and the configs for
 // all the data source being enabled.
 //
-// Next id: 33.
+// Next id: 34.
 message TraceConfig {
   message BufferConfig {
     optional uint32 size_kb = 1;
@@ -426,8 +426,15 @@
   // provided. The filter is applied at ReadBuffers() time and works both in the
   // case of IPC readback and write_into_file. This filter can be generated
   // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or
-  // `-T filter_out.escaped_string` (for .pbtx).
-  // Introduced in Android S. See go/trace-filtering for design.
-  message TraceFilter { optional bytes bytecode = 1; }
-  optional TraceFilter trace_filter = 32;
+  // `-T filter_out.escaped_string` (for .pbtx). See go/trace-filtering for
+  // design.
+  //
+  // Introduced in Android S, but it was broken (b/195065199). Reintroduced in
+  // Android T with a different field number.
+  message TraceFilter {
+    optional bytes bytecode = 1;
+  }
+  // old field number for trace_filter
+  reserved 32;
+  optional TraceFilter trace_filter = 33;
 }
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index e8c019e..b8f69c5 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -1490,7 +1490,7 @@
 // It contains the general config for the logging buffer(s) and the configs for
 // all the data source being enabled.
 //
-// Next id: 33.
+// Next id: 34.
 message TraceConfig {
   message BufferConfig {
     optional uint32 size_kb = 1;
@@ -1890,10 +1890,17 @@
   // provided. The filter is applied at ReadBuffers() time and works both in the
   // case of IPC readback and write_into_file. This filter can be generated
   // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or
-  // `-T filter_out.escaped_string` (for .pbtx).
-  // Introduced in Android S. See go/trace-filtering for design.
-  message TraceFilter { optional bytes bytecode = 1; }
-  optional TraceFilter trace_filter = 32;
+  // `-T filter_out.escaped_string` (for .pbtx). See go/trace-filtering for
+  // design.
+  //
+  // Introduced in Android S, but it was broken (b/195065199). Reintroduced in
+  // Android T with a different field number.
+  message TraceFilter {
+    optional bytes bytecode = 1;
+  }
+  // old field number for trace_filter
+  reserved 32;
+  optional TraceFilter trace_filter = 33;
 }
 
 // End of protos/perfetto/config/trace_config.proto
diff --git a/src/trace_processor/metrics/android/android_multiuser.sql b/src/trace_processor/metrics/android/android_multiuser.sql
index 0b94f89..bb5e4fc 100644
--- a/src/trace_processor/metrics/android/android_multiuser.sql
+++ b/src/trace_processor/metrics/android/android_multiuser.sql
@@ -19,7 +19,8 @@
     'start_event', 'user_start',
     'end_event', 'launcher_end');
 
+DROP VIEW IF EXISTS android_multiuser_output;
 CREATE VIEW android_multiuser_output AS
 SELECT AndroidMultiuserMetric(
   'user_switch', (SELECT * FROM event_user_switch)
-);
\ No newline at end of file
+);
diff --git a/src/trace_processor/metrics/android/android_multiuser_populator.sql b/src/trace_processor/metrics/android/android_multiuser_populator.sql
index b4d73b6..65dbab1 100644
--- a/src/trace_processor/metrics/android/android_multiuser_populator.sql
+++ b/src/trace_processor/metrics/android/android_multiuser_populator.sql
@@ -96,6 +96,7 @@
 
 
 -- Record the output for populating the proto.
+DROP VIEW IF EXISTS {{output_table_name}};
 CREATE VIEW {{output_table_name}} AS
 SELECT AndroidMultiuserMetric_EventData(
   'duration_ms', (
@@ -113,4 +114,4 @@
     )
     FROM cpu_usage
   )
-);
\ No newline at end of file
+);
diff --git a/src/trace_processor/metrics/chrome/gesture_flow_event.sql b/src/trace_processor/metrics/chrome/gesture_flow_event.sql
index 06c8124..b9b54c2 100644
--- a/src/trace_processor/metrics/chrome/gesture_flow_event.sql
+++ b/src/trace_processor/metrics/chrome/gesture_flow_event.sql
@@ -65,7 +65,7 @@
       SELECT
         id AS gesture_slice_id,
         ts AS gesture_ts,
-        dur AS gesture_dur,
+        dur AS {{prefix}}_dur,
         track_id AS gesture_track_id,
         trace_id AS {{id_field}},
         jank,
@@ -92,7 +92,7 @@
     0 AS ancestor_dur_one,
     id AS gesture_slice_id,
     ts AS gesture_ts,
-    dur AS gesture_dur,
+    dur AS {{prefix}}_dur,
     track_id AS gesture_track_id,
     trace_id AS {{id_field}},
     jank,
@@ -139,7 +139,7 @@
   FROM {{prefix}}_latency_info_flow_step
   WHERE
     trace_id = {{id_field}} AND
-    ts > gesture_ts + gesture_dur
+    ts > gesture_ts + {{prefix}}_dur
   GROUP BY gesture_slice_id;
 
 -- As described by the comments about this uses the heuristic to remove any flow
@@ -185,7 +185,7 @@
     curr.{{id_field}},
     curr.gesture_slice_id,
     curr.gesture_ts,
-    curr.gesture_dur,
+    curr.{{prefix}}_dur,
     curr.gesture_track_id,
     curr.jank,
     curr.ancestor_id,
@@ -232,7 +232,7 @@
     curr.{{id_field}},
     curr.gesture_slice_id AS {{prefix}}_slice_id,
     curr.gesture_ts AS {{prefix}}_ts,
-    curr.gesture_dur AS {{prefix}}_dur,
+    curr.{{prefix}}_dur AS {{prefix}}_dur,
     curr.gesture_track_id AS {{prefix}}_track_id,
     curr.jank,
     curr.step,
diff --git a/src/trace_processor/metrics/chrome/gesture_jank.sql b/src/trace_processor/metrics/chrome/gesture_jank.sql
index e88faaf..981e246 100644
--- a/src/trace_processor/metrics/chrome/gesture_jank.sql
+++ b/src/trace_processor/metrics/chrome/gesture_jank.sql
@@ -264,7 +264,7 @@
   FROM (
     SELECT
       curr.*,
-      curr.maybe_gesture_end - curr.begin_ts AS gesture_dur,
+      curr.maybe_gesture_end - curr.begin_ts AS {{prefix}}_dur,
       prev.ts AS prev_ts,
       prev.{{id_field}} AS prev_{{id_field}},
       prev.gesture_frames_exact AS prev_gesture_frames_exact
@@ -301,10 +301,10 @@
       ),
       '{{prefix}}_ms', (
         SELECT
-          CAST(SUM(gesture_dur)/1e6 AS REAL)
+          CAST(SUM({{prefix}}_dur)/1e6 AS REAL)
         FROM (
           SELECT
-            MAX(gesture_dur) AS gesture_dur
+            MAX({{prefix}}_dur) AS {{prefix}}_dur
           FROM {{prefix}}_jank
           GROUP BY {{id_field}}
         )
diff --git a/src/trace_processor/metrics/chrome/scroll_jank.sql b/src/trace_processor/metrics/chrome/scroll_jank.sql
index ddb8b20..984a6c7 100644
--- a/src/trace_processor/metrics/chrome/scroll_jank.sql
+++ b/src/trace_processor/metrics/chrome/scroll_jank.sql
@@ -32,3 +32,7 @@
     'gesture_end', 'GestureScrollEnd',
     'id_field', 'gesture_scroll_id',
     'proto_name', 'ScrollJank');
+
+-- TODO(b/200149773): Remove this once chrometto no longer depends on it.
+DROP VIEW IF EXISTS gesture_scroll_update;
+CREATE VIEW gesture_scroll_update AS SELECT * FROM gesture_scroll_id_update;
diff --git a/ui/release/channels.json b/ui/release/channels.json
index 6c58310..f95714a 100644
--- a/ui/release/channels.json
+++ b/ui/release/channels.json
@@ -2,11 +2,11 @@
   "channels": [
     {
       "name": "stable",
-      "rev": "5958067b9deacabd88fa1952a011f6a3c98a238c"
+      "rev": "d996f9e27fef14001401a4ae3c82dc24e71517ee"
     },
     {
       "name": "canary",
-      "rev": "e3da8549f8b4877442f7293d8e2f7357513f2d6b"
+      "rev": "990cb8e7e909695ddadde04848a18cf7f9c45358"
     },
     {
       "name": "autopush",
diff --git a/ui/src/controller/heap_profile_controller.ts b/ui/src/controller/heap_profile_controller.ts
index ef9df65..ecbbacc 100644
--- a/ui/src/controller/heap_profile_controller.ts
+++ b/ui/src/controller/heap_profile_controller.ts
@@ -273,7 +273,7 @@
     const callsites = await this.args.engine.query(`
         SELECT
         id as hash,
-        IFNULL(DEMANGLE(name), name) as name,
+        IFNULL(IFNULL(DEMANGLE(name), name), '[NULL]') as name,
         IFNULL(parent_id, -1) as parentHash,
         depth,
         cumulative_size as cumulativeSize,