[tracing] Add trace events about scroll deltas for scrolling.

Add trace events to help us monitor low-level scrolling signals:
- ScrollTree::ScrollBy
- perfetto::TracedValue support for gfx geometry primitives
- EventForwarder::OnTouchEvent
- List of inputs that were shown together in one GPU frame
- Add frame ids to Graphics.Pipeline event to make it possible to
  correlate this with PipelineReporter.
- Add trace_id to ScrollUpdate EventLatency to be able select all debug traces related to a particular input

# Example of using this tracing data
Screenshot: https://screenshot.googleplex.com/BrKjcNfpSR8V2xP
Script: https://paste.googleplex.com/6052006484508672

[email protected]
[email protected]

Bug: b/266910376
Change-Id: Ib72dcceb1218c77ac083c5ec7cae3e8ef0b6f8c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4194682
Reviewed-by: Robert Flack <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Jonathan Ross <[email protected]>
Commit-Queue: Violetta Fedotova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1101181}
diff --git a/cc/metrics/event_metrics.h b/cc/metrics/event_metrics.h
index b6cc6ba..1b1d68b 100644
--- a/cc/metrics/event_metrics.h
+++ b/cc/metrics/event_metrics.h
@@ -13,11 +13,12 @@
 #include "base/memory/raw_ptr.h"
 #include "base/time/tick_clock.h"
 #include "base/time/time.h"
+#include "base/types/id_type.h"
 #include "cc/cc_export.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "ui/events/types/event_type.h"
 #include "ui/events/types/scroll_input_type.h"
-
+#include "ui/latency/latency_info.h"
 namespace cc {
 class PinchEventMetrics;
 class ScrollEventMetrics;
@@ -28,7 +29,7 @@
 class CC_EXPORT EventMetrics {
  public:
   using List = std::vector<std::unique_ptr<EventMetrics>>;
-
+  using TraceId = base::IdType64<class ui::LatencyInfo>;
   // Event types we are interested in. This list should be in the same order as
   // values of EventLatencyEventType enum from enums.xml file.
   enum class EventType {
@@ -328,7 +329,8 @@
       ScrollUpdateType scroll_update_type,
       float delta,
       base::TimeTicks timestamp,
-      base::TimeTicks arrived_in_browser_main_timestamp);
+      base::TimeTicks arrived_in_browser_main_timestamp,
+      TraceId trace_id);
 
   // Prefer to use `Create()` above. This method is used only by the Browser
   // process which have own breakdowns.
@@ -339,7 +341,8 @@
       bool is_inertial,
       ScrollUpdateType scroll_update_type,
       float delta,
-      base::TimeTicks timestamp);
+      base::TimeTicks timestamp,
+      TraceId trace_id);
 
   // Similar to `Create()` with an extra `base::TickClock` to use in tests.
   // Should only be used for scroll-update events.
@@ -380,6 +383,9 @@
   float predicted_delta() const { return predicted_delta_; }
 
   int32_t coalesced_event_count() { return coalesced_event_count_; }
+
+  absl::optional<TraceId> trace_id() { return trace_id_; }
+
   void set_predicted_delta(float predicted_delta) {
     predicted_delta_ = predicted_delta;
   }
@@ -395,7 +401,8 @@
                            float delta,
                            base::TimeTicks timestamp,
                            base::TimeTicks arrived_in_browser_main_timestamp,
-                           const base::TickClock* tick_clock);
+                           const base::TickClock* tick_clock,
+                           absl::optional<TraceId> trace_id);
   ScrollUpdateEventMetrics(const ScrollUpdateEventMetrics&);
 
  private:
@@ -407,7 +414,8 @@
       float delta,
       base::TimeTicks timestamp,
       base::TimeTicks arrived_in_browser_main_timestamp,
-      const base::TickClock* tick_clock);
+      const base::TickClock* tick_clock,
+      absl::optional<TraceId> trace_id);
 
   float delta_;
   float predicted_delta_;
@@ -417,6 +425,10 @@
 
   // Total events that were coalesced into this into this ScrollUpdate
   int32_t coalesced_event_count_ = 1;
+  // This is a trace id of an input event. It can be null for events which don't
+  // have a corresponding input, for example a generated event based on existing
+  // event.
+  absl::optional<TraceId> trace_id_;
 };
 
 class CC_EXPORT PinchEventMetrics : public EventMetrics {