Merge "[Fuchsia] Set perfetto_unittests for CFv1"
diff --git a/CHANGELOG b/CHANGELOG
index 76b42be..2a1bfbd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,15 +9,18 @@
     *
 
 
+v24.2 - 2022-02-10:
+  SDK:
+    * Revert of incremental timestamps, introduced in v24.0.
+      Some clients were depending on non-incremental timestamps.
+      Future releases will re-enable this but offer an opt-out.
+
+
 v24.1 - 2022-02-09:
   Tracing service and probes:
     * Fixed build failures on Windows.
   Trace Processor:
     * Fixed build failures on Windows.
-  UI:
-    *
-  SDK:
-    *
 
 
 v24.0 - 2022-02-08:
@@ -50,7 +53,8 @@
     * Changed postMessage() API, suppressed confirmation dialog when the opener
       is in the same origin, for cases when the UI is self-hosted.
   SDK:
-    *
+    * Changed timestamps emitted by the SDK to be incremental by default, using
+      ClockSnapshot + TracePacketDefaults.
 
 
 v23.0 - 2022-01-11:
diff --git a/include/perfetto/tracing/internal/track_event_data_source.h b/include/perfetto/tracing/internal/track_event_data_source.h
index 3a3db7e..9229153 100644
--- a/include/perfetto/tracing/internal/track_event_data_source.h
+++ b/include/perfetto/tracing/internal/track_event_data_source.h
@@ -35,16 +35,14 @@
 
 namespace perfetto {
 
-// A function for converting an abstract timestamp into a
-// perfetto::TraceTimestamp struct. By specialising this template and defining
+// This template provides a way to convert an abstract timestamp into the trace
+// clock timebase in nanoseconds. By specialising this template and defining
 // static ConvertTimestampToTraceTimeNs function in it the user can register
-// additional timestamp types. The return value should specify the
-// clock domain used by the timestamp as well as its value.
+// additional timestamp types. The return value should specify the clock used by
+// the timestamp as well as its value in nanoseconds.
 //
-// The supported clock domains are the ones described in
-// perfetto.protos.ClockSnapshot. However, custom clock IDs (>=64) are
-// reserved for internal use by the SDK for the time being.
-// The timestamp value should be in nanoseconds regardless of the clock domain.
+// The users should see the specialisation for uint64_t below as an example.
+// Note that the specialisation should be defined in perfetto namespace.
 template <typename T>
 struct TraceTimestampTraits;
 
@@ -241,7 +239,7 @@
                                Arguments&&... args) PERFETTO_NO_INLINE {
     TraceForCategoryImpl(instances, category, event_name, type,
                          TrackEventInternal::kDefaultTrack,
-                         TrackEventInternal::GetTraceTime(),
+                         TrackEventInternal::GetTimeNs(),
                          std::forward<Arguments>(args)...);
   }
 
@@ -263,7 +261,7 @@
                                Arguments&&... args) PERFETTO_NO_INLINE {
     TraceForCategoryImpl(
         instances, category, event_name, type, std::forward<TrackType>(track),
-        TrackEventInternal::GetTraceTime(), std::forward<Arguments>(args)...);
+        TrackEventInternal::GetTimeNs(), std::forward<Arguments>(args)...);
   }
 
   // Trace point which takes a timestamp, but not track.
@@ -316,7 +314,7 @@
                                ValueType value) PERFETTO_ALWAYS_INLINE {
     PERFETTO_DCHECK(type == perfetto::protos::pbzero::TrackEvent::TYPE_COUNTER);
     TraceForCategory(instances, category, /*name=*/nullptr, type, track,
-                     TrackEventInternal::GetTraceTime(), value);
+                     TrackEventInternal::GetTimeNs(), value);
   }
 
   // Trace point with with a timestamp and a counter sample.
@@ -362,8 +360,7 @@
     TrackRegistry::Get()->UpdateTrack(track, desc.SerializeAsString());
     Base::template Trace([&](typename Base::TraceContext ctx) {
       TrackEventInternal::WriteTrackDescriptor(
-          track, ctx.tls_inst_->trace_writer.get(), ctx.GetIncrementalState(),
-          TrackEventInternal::GetTraceTime());
+          track, ctx.tls_inst_->trace_writer.get());
     });
   }
 
@@ -455,14 +452,14 @@
           TrackEventIncrementalState* incr_state = ctx.GetIncrementalState();
           if (incr_state->was_cleared) {
             incr_state->was_cleared = false;
-            TrackEventInternal::ResetIncrementalState(trace_writer, incr_state,
+            TrackEventInternal::ResetIncrementalState(trace_writer,
                                                       trace_timestamp);
           }
 
           // Write the track descriptor before any event on the track.
           if (track) {
             TrackEventInternal::WriteTrackDescriptorIfNeeded(
-                track, trace_writer, incr_state, trace_timestamp);
+                track, trace_writer, incr_state);
           }
 
           // Write the event itself.
@@ -516,8 +513,7 @@
     TrackRegistry::Get()->UpdateTrack(track, std::move(callback));
     Base::template Trace([&](typename Base::TraceContext ctx) {
       TrackEventInternal::WriteTrackDescriptor(
-          track, ctx.tls_inst_->trace_writer.get(), ctx.GetIncrementalState(),
-          TrackEventInternal::GetTraceTime());
+          track, ctx.tls_inst_->trace_writer.get());
     });
   }
 
diff --git a/include/perfetto/tracing/internal/track_event_internal.h b/include/perfetto/tracing/internal/track_event_internal.h
index 6fed09e..037dc09 100644
--- a/include/perfetto/tracing/internal/track_event_internal.h
+++ b/include/perfetto/tracing/internal/track_event_internal.h
@@ -35,24 +35,13 @@
 
 // Represents a point in time for the clock specified by |clock_id|.
 struct TraceTimestamp {
-  // Clock IDs have the following semantic:
-  // [1, 63]:    Builtin types, see BuiltinClock from
-  //             ../common/builtin_clock.proto.
-  // [64, 127]:  User-defined clocks. These clocks are sequence-scoped. They
-  //             are only valid within the same |trusted_packet_sequence_id|
-  //             (i.e. only for TracePacket(s) emitted by the same TraceWriter
-  //             that emitted the clock snapshot).
-  // [128, MAX]: Reserved for future use. The idea is to allow global clock
-  //             IDs and setting this ID to hash(full_clock_name) & ~127.
-  // Learn more: `clock_snapshot.proto`
-  uint32_t clock_id;
-  uint64_t value;
+  protos::pbzero::BuiltinClock clock_id;
+  uint64_t nanoseconds;
 };
 
 class EventContext;
 class TrackEventSessionObserver;
 struct Category;
-struct TraceTimestamp;
 namespace protos {
 namespace gen {
 class TrackEventConfig;
@@ -96,12 +85,6 @@
 struct TrackEventIncrementalState {
   static constexpr size_t kMaxInternedDataFields = 32;
 
-  // Packet-sequence-scoped clock that encodes microsecond timestamps in the
-  // domain of the clock returned by GetClockId() as delta values - see
-  // Clock::is_incremental in perfetto/trace/clock_snapshot.proto.
-  // Default unit: nanoseconds.
-  static constexpr uint32_t kClockIdIncremental = 64;
-
   bool was_cleared = true;
 
   // A heap-allocated message for storing newly seen interned data while we are
@@ -133,11 +116,6 @@
   // this tracing session. The value in the map indicates whether the category
   // is enabled or disabled.
   std::unordered_map<std::string, bool> dynamic_categories;
-
-  // The latest reference timestamp that was used in a TracePacket or in a
-  // ClockSnapshot. The increment between this timestamp and the current trace
-  // time (GetTimeNs) is a value in kClockIdIncremental's domain.
-  uint64_t last_timestamp_ns = 0;
 };
 
 // The backend portion of the track event trace point implemention. Outlined to
@@ -168,11 +146,9 @@
       const Category* category,
       const char* name,
       perfetto::protos::pbzero::TrackEvent::Type,
-      const TraceTimestamp& timestamp);
+      TraceTimestamp timestamp = {GetClockId(), GetTimeNs()});
 
-  static void ResetIncrementalState(TraceWriterBase* trace_writer,
-                                    TrackEventIncrementalState* incr_state,
-                                    const TraceTimestamp& timestamp);
+  static void ResetIncrementalState(TraceWriterBase*, TraceTimestamp);
 
   // TODO(altimin): Remove this method once Chrome uses
   // EventContext::AddDebugAnnotation directly.
@@ -192,29 +168,24 @@
   static void WriteTrackDescriptorIfNeeded(
       const TrackType& track,
       TraceWriterBase* trace_writer,
-      TrackEventIncrementalState* incr_state,
-      const TraceTimestamp& timestamp) {
+      TrackEventIncrementalState* incr_state) {
     auto it_and_inserted = incr_state->seen_tracks.insert(track.uuid);
     if (PERFETTO_LIKELY(!it_and_inserted.second))
       return;
-    WriteTrackDescriptor(track, trace_writer, incr_state, timestamp);
+    WriteTrackDescriptor(track, trace_writer);
   }
 
   // Unconditionally write a track descriptor into the trace.
   template <typename TrackType>
   static void WriteTrackDescriptor(const TrackType& track,
-                                   TraceWriterBase* trace_writer,
-                                   TrackEventIncrementalState* incr_state,
-                                   const TraceTimestamp& timestamp) {
+                                   TraceWriterBase* trace_writer) {
     TrackRegistry::Get()->SerializeTrack(
-        track, NewTracePacket(trace_writer, incr_state, timestamp));
+        track, NewTracePacket(trace_writer, {GetClockId(), GetTimeNs()}));
   }
 
   // Get the current time in nanoseconds in the trace clock timebase.
   static uint64_t GetTimeNs();
 
-  static TraceTimestamp GetTraceTime();
-
   // Get the clock used by GetTimeNs().
   static constexpr protos::pbzero::BuiltinClock GetClockId() {
 #if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) && \
@@ -233,8 +204,7 @@
  private:
   static protozero::MessageHandle<protos::pbzero::TracePacket> NewTracePacket(
       TraceWriterBase*,
-      TrackEventIncrementalState*,
-      const TraceTimestamp&,
+      TraceTimestamp,
       uint32_t seq_flags =
           protos::pbzero::TracePacket::SEQ_NEEDS_INCREMENTAL_STATE);
   static protos::pbzero::DebugAnnotation* AddDebugAnnotation(
diff --git a/include/perfetto/tracing/track_event_state_tracker.h b/include/perfetto/tracing/track_event_state_tracker.h
index e97f035..7b2437e 100644
--- a/include/perfetto/tracing/track_event_state_tracker.h
+++ b/include/perfetto/tracing/track_event_state_tracker.h
@@ -80,10 +80,6 @@
     std::map<uint64_t /*iid*/, std::string> event_names;
     std::map<uint64_t /*iid*/, std::string> event_categories;
     std::map<uint64_t /*iid*/, std::string> debug_annotation_names;
-    // Current absolute timestamp of the incremental clock.
-    uint64_t most_recent_absolute_time_ns = 0;
-    // default_clock_id == 0 means, no default clock_id is set.
-    uint32_t default_clock_id = 0;
   };
 
   // State for the entire tracing session. Shared by all trace writer sequences
diff --git a/infra/luci/generated/cr-buildbucket.cfg b/infra/luci/generated/cr-buildbucket.cfg
index 95f68d7..a835dad 100644
--- a/infra/luci/generated/cr-buildbucket.cfg
+++ b/infra/luci/generated/cr-buildbucket.cfg
@@ -34,10 +34,6 @@
         '  "recipe": "perfetto"'
         '}'
       service_account: "perfetto-luci-official-builder@chops-service-accounts.iam.gserviceaccount.com"
-      experiments {
-        key: "luci.use_realms"
-        value: 100
-      }
     }
     builders {
       name: "perfetto-official-builder-linux"
@@ -55,10 +51,6 @@
         '  "recipe": "perfetto"'
         '}'
       service_account: "perfetto-luci-official-builder@chops-service-accounts.iam.gserviceaccount.com"
-      experiments {
-        key: "luci.use_realms"
-        value: 100
-      }
     }
     builders {
       name: "perfetto-official-builder-mac"
@@ -80,10 +72,6 @@
         path: "macos_sdk"
       }
       service_account: "perfetto-luci-official-builder@chops-service-accounts.iam.gserviceaccount.com"
-      experiments {
-        key: "luci.use_realms"
-        value: 100
-      }
     }
     builders {
       name: "perfetto-official-builder-windows"
@@ -105,10 +93,6 @@
         path: "windows_sdk"
       }
       service_account: "perfetto-luci-official-builder@chops-service-accounts.iam.gserviceaccount.com"
-      experiments {
-        key: "luci.use_realms"
-        value: 100
-      }
     }
   }
 }
diff --git a/infra/luci/generated/luci-scheduler.cfg b/infra/luci/generated/luci-scheduler.cfg
index 89ae71b..dd7f20b 100644
--- a/infra/luci/generated/luci-scheduler.cfg
+++ b/infra/luci/generated/luci-scheduler.cfg
@@ -10,7 +10,7 @@
   acl_sets: "official"
   buildbucket {
     server: "cr-buildbucket.appspot.com"
-    bucket: "luci.perfetto.official"
+    bucket: "official"
     builder: "perfetto-official-builder-android"
   }
 }
@@ -20,7 +20,7 @@
   acl_sets: "official"
   buildbucket {
     server: "cr-buildbucket.appspot.com"
-    bucket: "luci.perfetto.official"
+    bucket: "official"
     builder: "perfetto-official-builder-linux"
   }
 }
@@ -30,7 +30,7 @@
   acl_sets: "official"
   buildbucket {
     server: "cr-buildbucket.appspot.com"
-    bucket: "luci.perfetto.official"
+    bucket: "official"
     builder: "perfetto-official-builder-mac"
   }
 }
@@ -40,7 +40,7 @@
   acl_sets: "official"
   buildbucket {
     server: "cr-buildbucket.appspot.com"
-    bucket: "luci.perfetto.official"
+    bucket: "official"
     builder: "perfetto-official-builder-windows"
   }
 }
diff --git a/infra/luci/generated/project.cfg b/infra/luci/generated/project.cfg
index 809a993..2aad4e1 100644
--- a/infra/luci/generated/project.cfg
+++ b/infra/luci/generated/project.cfg
@@ -7,8 +7,9 @@
 name: "perfetto"
 access: "group:all"
 lucicfg {
-  version: "1.30.5"
+  version: "1.30.9"
   package_dir: ".."
   config_dir: "generated"
   entry_point: "main.star"
+  experiments: "crbug.com/1182002"
 }
diff --git a/infra/luci/main.star b/infra/luci/main.star
index 5cf3b0c..316a505 100755
--- a/infra/luci/main.star
+++ b/infra/luci/main.star
@@ -13,10 +13,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-lucicfg.check_version("1.23.3", "Please update depot_tools")
+lucicfg.check_version("1.30.9", "Please update depot_tools")
 
-# Launch all builds in realms-aware mode.
-luci.builder.defaults.experiments.set({"luci.use_realms": 100})
+# Use LUCI Scheduler BBv2 names and add Scheduler realms configs.
+lucicfg.enable_experiment("crbug.com/1182002")
 
 # Enable bbagent.
 luci.recipe.defaults.use_bbagent.set(True)
diff --git a/src/tracing/internal/track_event_internal.cc b/src/tracing/internal/track_event_internal.cc
index 0c27e4a..3717fb2 100644
--- a/src/tracing/internal/track_event_internal.cc
+++ b/src/tracing/internal/track_event_internal.cc
@@ -26,14 +26,11 @@
 #include "perfetto/tracing/track_event_interned_data_index.h"
 #include "protos/perfetto/common/data_source_descriptor.gen.h"
 #include "protos/perfetto/common/track_event_descriptor.pbzero.h"
-#include "protos/perfetto/trace/clock_snapshot.pbzero.h"
 #include "protos/perfetto/trace/interned_data/interned_data.pbzero.h"
 #include "protos/perfetto/trace/trace_packet_defaults.pbzero.h"
 #include "protos/perfetto/trace/track_event/debug_annotation.pbzero.h"
 #include "protos/perfetto/trace/track_event/track_descriptor.pbzero.h"
 
-using perfetto::protos::pbzero::ClockSnapshot;
-
 namespace perfetto {
 
 TrackEventSessionObserver::~TrackEventSessionObserver() = default;
@@ -51,13 +48,6 @@
 static constexpr const char kLegacySlowPrefix[] = "disabled-by-default-";
 static constexpr const char kSlowTag[] = "slow";
 static constexpr const char kDebugTag[] = "debug";
-// Allows to specify a custom unit different than the default (ns) for
-// the incremental clock.
-// A multiplier of 1000 means that a timestamp = 3 should be
-// interpreted as 3000 ns = 3 us.
-// TODO(mohitms): Move it to TrackEventConfig.
-constexpr uint64_t kIncrementalTimestampUnitMultiplier = 1;
-static_assert(kIncrementalTimestampUnitMultiplier >= 1, "");
 
 void ForEachObserver(
     std::function<bool(TrackEventSessionObserver*&)> callback) {
@@ -313,94 +303,50 @@
 }
 
 // static
-TraceTimestamp TrackEventInternal::GetTraceTime() {
-  return {TrackEventIncrementalState::kClockIdIncremental, GetTimeNs()};
-}
-
-// static
 int TrackEventInternal::GetSessionCount() {
   return session_count_.load();
 }
 
 // static
-void TrackEventInternal::ResetIncrementalState(
-    TraceWriterBase* trace_writer,
-    TrackEventIncrementalState* incr_state,
-    const TraceTimestamp& timestamp) {
-  auto sequence_timestamp = timestamp;
-  if (timestamp.clock_id != TrackEventInternal::GetClockId() &&
-      timestamp.clock_id != TrackEventIncrementalState::kClockIdIncremental) {
-    sequence_timestamp = TrackEventInternal::GetTraceTime();
-  }
-
-  incr_state->last_timestamp_ns = sequence_timestamp.value;
+void TrackEventInternal::ResetIncrementalState(TraceWriterBase* trace_writer,
+                                               TraceTimestamp timestamp) {
   auto default_track = ThreadTrack::Current();
   {
     // Mark any incremental state before this point invalid. Also set up
     // defaults so that we don't need to repeat constant data for each packet.
     auto packet = NewTracePacket(
-        trace_writer, incr_state, timestamp,
+        trace_writer, timestamp,
         protos::pbzero::TracePacket::SEQ_INCREMENTAL_STATE_CLEARED);
     auto defaults = packet->set_trace_packet_defaults();
-    defaults->set_timestamp_clock_id(
-        TrackEventIncrementalState::kClockIdIncremental);
+    defaults->set_timestamp_clock_id(GetClockId());
 
     // Establish the default track for this event sequence.
     auto track_defaults = defaults->set_track_event_defaults();
     track_defaults->set_track_uuid(default_track.uuid);
-
-    ClockSnapshot* clocks = packet->set_clock_snapshot();
-    // Trace clock.
-    ClockSnapshot::Clock* trace_clock = clocks->add_clocks();
-    trace_clock->set_clock_id(GetClockId());
-    trace_clock->set_timestamp(sequence_timestamp.value);
-    // Delta-encoded incremental clock in nano seconds.
-    // TODO(b/168311581): Make the unit of this clock configurable to allow
-    // trade-off between precision and encoded trace size.
-    ClockSnapshot::Clock* clock_incremental = clocks->add_clocks();
-    clock_incremental->set_clock_id(
-        TrackEventIncrementalState::kClockIdIncremental);
-    auto ts_unit_multiplier = kIncrementalTimestampUnitMultiplier;
-    clock_incremental->set_timestamp(sequence_timestamp.value /
-                                     ts_unit_multiplier);
-    clock_incremental->set_is_incremental(true);
-    clock_incremental->set_unit_multiplier_ns(ts_unit_multiplier);
   }
 
   // Every thread should write a descriptor for its default track, because most
   // trace points won't explicitly reference it. We also write the process
   // descriptor from every thread that writes trace events to ensure it gets
   // emitted at least once.
-  WriteTrackDescriptor(default_track, trace_writer, incr_state,
-                       sequence_timestamp);
-
-  WriteTrackDescriptor(ProcessTrack::Current(), trace_writer, incr_state,
-                       sequence_timestamp);
+  WriteTrackDescriptor(default_track, trace_writer);
+  WriteTrackDescriptor(ProcessTrack::Current(), trace_writer);
 }
 
 // static
 protozero::MessageHandle<protos::pbzero::TracePacket>
 TrackEventInternal::NewTracePacket(TraceWriterBase* trace_writer,
-                                   TrackEventIncrementalState* incr_state,
-                                   const TraceTimestamp& timestamp,
+                                   TraceTimestamp timestamp,
                                    uint32_t seq_flags) {
   auto packet = trace_writer->NewTracePacket();
-  if (timestamp.clock_id == TrackEventIncrementalState::kClockIdIncremental) {
-    if (incr_state->last_timestamp_ns <= timestamp.value) {
-      // No need to set the clock id here, since kClockIdIncremental is the
-      // clock id assumed by default.
-      auto ts_unit_multiplier = kIncrementalTimestampUnitMultiplier;
-      auto time_diff_ns = timestamp.value - incr_state->last_timestamp_ns;
-      packet->set_timestamp(time_diff_ns / ts_unit_multiplier);
-      incr_state->last_timestamp_ns = timestamp.value;
-    } else {
-      // TODO(mohitms): Consider using kIncrementalTimestampUnitMultiplier.
-      packet->set_timestamp(timestamp.value);
-      packet->set_timestamp_clock_id(GetClockId());
-    }
-  } else {
-    packet->set_timestamp(timestamp.value);
-    packet->set_timestamp_clock_id(timestamp.clock_id);
+  packet->set_timestamp(timestamp.nanoseconds);
+  if (timestamp.clock_id != GetClockId()) {
+    packet->set_timestamp_clock_id(static_cast<uint32_t>(timestamp.clock_id));
+  } else if (GetClockId() != protos::pbzero::BUILTIN_CLOCK_BOOTTIME) {
+    // TODO(skyostil): Stop emitting the clock id for the default trace clock
+    // for every event once the trace processor understands trace packet
+    // defaults.
+    packet->set_timestamp_clock_id(GetClockId());
   }
   packet->set_sequence_flags(seq_flags);
   return packet;
@@ -413,10 +359,11 @@
     const Category* category,
     const char* name,
     perfetto::protos::pbzero::TrackEvent::Type type,
-    const TraceTimestamp& timestamp) {
+    TraceTimestamp timestamp) {
   PERFETTO_DCHECK(g_main_thread);
   PERFETTO_DCHECK(!incr_state->was_cleared);
-  auto packet = NewTracePacket(trace_writer, incr_state, timestamp);
+
+  auto packet = NewTracePacket(trace_writer, timestamp);
   EventContext ctx(std::move(packet), incr_state);
 
   auto track_event = ctx.event();
diff --git a/src/tracing/test/api_integrationtest.cc b/src/tracing/test/api_integrationtest.cc
index 8aa589c..26d8a03 100644
--- a/src/tracing/test/api_integrationtest.cc
+++ b/src/tracing/test/api_integrationtest.cc
@@ -59,7 +59,6 @@
 #include "protos/perfetto/common/track_event_descriptor.pbzero.h"
 #include "protos/perfetto/config/interceptor_config.gen.h"
 #include "protos/perfetto/config/track_event/track_event_config.gen.h"
-#include "protos/perfetto/trace/clock_snapshot.gen.h"
 #include "protos/perfetto/trace/clock_snapshot.pbzero.h"
 #include "protos/perfetto/trace/gpu/gpu_render_stage_event.gen.h"
 #include "protos/perfetto/trace/gpu/gpu_render_stage_event.pbzero.h"
@@ -73,7 +72,6 @@
 #include "protos/perfetto/trace/trace.pbzero.h"
 #include "protos/perfetto/trace/trace_packet.gen.h"
 #include "protos/perfetto/trace/trace_packet.pbzero.h"
-#include "protos/perfetto/trace/trace_packet_defaults.gen.h"
 #include "protos/perfetto/trace/track_event/chrome_process_descriptor.gen.h"
 #include "protos/perfetto/trace/track_event/chrome_process_descriptor.pbzero.h"
 #include "protos/perfetto/trace/track_event/counter_descriptor.gen.h"
@@ -970,11 +968,6 @@
   bool process_descriptor_found = false;
   uint32_t sequence_id = 0;
   int32_t cur_pid = perfetto::test::GetCurrentProcessId();
-  uint64_t recent_absolute_time_ns = 0;
-  bool found_incremental_clock = false;
-  constexpr auto kClockIdIncremental =
-      perfetto::internal::TrackEventIncrementalState::kClockIdIncremental;
-
   for (const auto& packet : trace.packet()) {
     if (packet.has_track_descriptor()) {
       const auto& desc = packet.track_descriptor();
@@ -991,17 +984,6 @@
       incremental_state_was_cleared = true;
       categories.clear();
       event_names.clear();
-      EXPECT_EQ(kClockIdIncremental,
-                packet.trace_packet_defaults().timestamp_clock_id());
-    }
-    if (packet.has_clock_snapshot()) {
-      for (auto& clock : packet.clock_snapshot().clocks()) {
-        if (clock.is_incremental()) {
-          found_incremental_clock = true;
-          recent_absolute_time_ns = clock.timestamp();
-          EXPECT_EQ(kClockIdIncremental, clock.clock_id());
-        }
-      }
     }
 
     if (!packet.has_track_event())
@@ -1031,13 +1013,18 @@
         event_names[it.iid()] = it.name();
       }
     }
-    EXPECT_TRUE(found_incremental_clock);
-    uint64_t absolute_timestamp = packet.timestamp() + recent_absolute_time_ns;
-    recent_absolute_time_ns = absolute_timestamp;
-    EXPECT_GT(absolute_timestamp, 0u);
-    EXPECT_LE(absolute_timestamp, now);
-    // Packet uses default (incremental) clock.
+
+    EXPECT_GT(packet.timestamp(), 0u);
+    EXPECT_LE(packet.timestamp(), now);
+#if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) && \
+    !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
     EXPECT_FALSE(packet.has_timestamp_clock_id());
+#else
+    constexpr auto kClockMonotonic =
+        perfetto::protos::pbzero::ClockSnapshot::Clock::MONOTONIC;
+    EXPECT_EQ(packet.timestamp_clock_id(),
+              static_cast<uint32_t>(kClockMonotonic));
+#endif
     if (track_event.type() ==
         perfetto::protos::gen::TrackEvent::TYPE_SLICE_BEGIN) {
       EXPECT_FALSE(begin_found);
@@ -1064,84 +1051,6 @@
   TestCategoryAsTemplateParameter<kTestCategory>();
 }
 
-TEST_P(PerfettoApiTest, TrackEventWithIncrementalTimestamp) {
-  // Create a new trace session.
-  auto* tracing_session = NewTraceWithCategories({"bar"});
-  constexpr auto kClockIdIncremental =
-      perfetto::internal::TrackEventIncrementalState::kClockIdIncremental;
-  tracing_session->get()->StartBlocking();
-
-  std::map<uint64_t, std::string> event_names;
-
-  auto empty_lambda = [](perfetto::EventContext) {};
-
-  constexpr uint64_t kInstantEvent1Time = 92718891479583;
-  TRACE_EVENT_INSTANT(
-      "bar", "InstantEvent1",
-      perfetto::TraceTimestamp{kClockIdIncremental, kInstantEvent1Time},
-      empty_lambda);
-
-  constexpr uint64_t kInstantEvent2Time = 92718891618959;
-  TRACE_EVENT_INSTANT(
-      "bar", "InstantEvent2",
-      perfetto::TraceTimestamp{kClockIdIncremental, kInstantEvent2Time},
-      empty_lambda);
-
-  perfetto::TrackEvent::Flush();
-  tracing_session->get()->StopBlocking();
-
-  std::vector<char> raw_trace = tracing_session->get()->ReadTraceBlocking();
-  perfetto::protos::gen::Trace trace;
-  ASSERT_TRUE(trace.ParseFromArray(raw_trace.data(), raw_trace.size()));
-
-  uint64_t absolute_timestamp = 0;
-  int event_count = 0;
-  // Go through the packets and add the timestamps of those packets that use the
-  // incremental clock - in order to get the absolute timestamps of the track
-  // events.
-  for (const auto& packet : trace.packet()) {
-    if (packet.has_clock_snapshot()) {
-      for (auto& clock : packet.clock_snapshot().clocks()) {
-        if (clock.is_incremental()) {
-          absolute_timestamp = clock.timestamp();
-          EXPECT_EQ(clock.clock_id(), kClockIdIncremental);
-        }
-      }
-    } else if (!packet.has_timestamp_clock_id()) {
-      // Packets that don't have a timestamp_clock_id default to the incremental
-      // clock.
-      absolute_timestamp += packet.timestamp();
-    }
-
-    if (packet.sequence_flags() &
-        perfetto::protos::pbzero::TracePacket::SEQ_INCREMENTAL_STATE_CLEARED) {
-      event_names.clear();
-    }
-
-    if (!packet.has_track_event())
-      continue;
-
-    // Update incremental state.
-    if (packet.has_interned_data()) {
-      const auto& interned_data = packet.interned_data();
-      for (const auto& it : interned_data.event_names()) {
-        EXPECT_EQ(event_names.find(it.iid()), event_names.end());
-        event_names[it.iid()] = it.name();
-      }
-    }
-
-    if (event_names[packet.track_event().name_iid()] == "InstantEvent1") {
-      event_count++;
-      ASSERT_EQ(absolute_timestamp, kInstantEvent1Time);
-    } else if (event_names[packet.track_event().name_iid()] ==
-               "InstantEvent2") {
-      event_count++;
-      ASSERT_EQ(absolute_timestamp, kInstantEvent2Time);
-    }
-  }
-  ASSERT_EQ(event_count, 2);
-}
-
 TEST_P(PerfettoApiTest, TrackEventCategories) {
   // Create a new trace session.
   auto* tracing_session = NewTraceWithCategories({"bar"});
@@ -1845,9 +1754,6 @@
   for (const auto& packet : trace.packet()) {
     if (!packet.has_track_event())
       continue;
-
-    EXPECT_EQ(packet.timestamp_clock_id(),
-              static_cast<uint32_t>(perfetto::TrackEvent::GetTraceClockId()));
     event_count++;
     switch (packet.track_event().type()) {
       case perfetto::protos::gen::TrackEvent::TYPE_SLICE_BEGIN:
diff --git a/src/tracing/track_event_state_tracker.cc b/src/tracing/track_event_state_tracker.cc
index 7ff50ac..7cb1b09 100644
--- a/src/tracing/track_event_state_tracker.cc
+++ b/src/tracing/track_event_state_tracker.cc
@@ -17,10 +17,8 @@
 #include "perfetto/tracing/track_event_state_tracker.h"
 
 #include "perfetto/ext/base/hash.h"
-#include "perfetto/tracing/internal/track_event_internal.h"
 
 #include "protos/perfetto/common/interceptor_descriptor.gen.h"
-#include "protos/perfetto/trace/clock_snapshot.pbzero.h"
 #include "protos/perfetto/trace/interned_data/interned_data.pbzero.h"
 #include "protos/perfetto/trace/trace_packet.pbzero.h"
 #include "protos/perfetto/trace/trace_packet_defaults.pbzero.h"
@@ -32,8 +30,6 @@
 
 namespace perfetto {
 
-using internal::TrackEventIncrementalState;
-
 TrackEventStateTracker::~TrackEventStateTracker() = default;
 TrackEventStateTracker::Delegate::~Delegate() = default;
 
@@ -49,15 +45,8 @@
   perfetto::protos::pbzero::TrackEvent::Decoder track_event(
       packet.track_event());
 
-  auto clock_id = packet.timestamp_clock_id();
-  if (!packet.has_timestamp_clock_id())
-    clock_id = sequence_state.default_clock_id;
+  // TODO(skyostil): Support incremental timestamps.
   uint64_t timestamp = packet.timestamp();
-  // TODO(mohitms): Incorporate unit multiplier as well.
-  if (clock_id == TrackEventIncrementalState::kClockIdIncremental) {
-    timestamp += sequence_state.most_recent_absolute_time_ns;
-    sequence_state.most_recent_absolute_time_ns = timestamp;
-  }
 
   Track* track = &sequence_state.track;
   if (track_event.has_track_uuid()) {
@@ -174,19 +163,6 @@
   }
 #endif
 
-  perfetto::protos::pbzero::ClockSnapshot::Decoder snapshot(
-      packet.clock_snapshot());
-  for (auto it = snapshot.clocks(); it; ++it) {
-    perfetto::protos::pbzero::ClockSnapshot::Clock::Decoder clock(*it);
-    // TODO(mohitms) : Handle the incremental clock other than default one.
-    if (clock.is_incremental() &&
-        clock.clock_id() == TrackEventIncrementalState::kClockIdIncremental) {
-      sequence_state.most_recent_absolute_time_ns =
-          clock.timestamp() * clock.unit_multiplier_ns();
-      break;
-    }
-  }
-
   if (packet.sequence_flags() &
       perfetto::protos::pbzero::TracePacket::SEQ_INCREMENTAL_STATE_CLEARED) {
     // Convert any existing event names and categories on the stack to
@@ -232,8 +208,6 @@
       perfetto::protos::pbzero::TrackEventDefaults::Decoder
           track_event_defaults(defaults.track_event_defaults());
       sequence_state.track.uuid = track_event_defaults.track_uuid();
-      if (defaults.has_timestamp_clock_id())
-        sequence_state.default_clock_id = defaults.timestamp_clock_id();
     }
   }
   if (packet.has_track_descriptor()) {
diff --git a/ui/src/assets/common.scss b/ui/src/assets/common.scss
index c98a6a1..a42e3b5 100644
--- a/ui/src/assets/common.scss
+++ b/ui/src/assets/common.scss
@@ -720,6 +720,11 @@
   &.query-error {
     color: red;
   }
+
+  .total-values {
+    text-align: right;
+    padding-right: 10px;
+  }
 }
 
 .pivot-table-editor-container {
diff --git a/ui/src/frontend/pivot_table_redux.ts b/ui/src/frontend/pivot_table_redux.ts
index c2c129a..c35abaa 100644
--- a/ui/src/frontend/pivot_table_redux.ts
+++ b/ui/src/frontend/pivot_table_redux.ts
@@ -159,7 +159,7 @@
 
     // Avoid rendering the intermediate results row if it has only one leaf
     // row.
-    if (!tree.isCollapsed && tree.rows.length > 1) {
+    if (!tree.isCollapsed && path.length > 0 && tree.rows.length > 1) {
       sink.push(this.renderSectionRow(path, tree, result));
     }
     for (const row of tree.rows) {
@@ -181,6 +181,17 @@
     }
   }
 
+  renderTotalsRow(queryResult: PivotTableReduxResult) {
+    const overallValuesRow =
+        [m('td.total-values',
+           {'colspan': queryResult.metadata.pivotColumns.length},
+           m('strong', 'Total values:'))];
+    for (const aggValue of queryResult.tree.aggregates) {
+      overallValuesRow.push(m('td', `${aggValue}`));
+    }
+    return m('tr', overallValuesRow);
+  }
+
   renderResultsTable() {
     const state = globals.state.pivotTableRedux;
     if (state.query !== null || state.queryResult === null) {
@@ -196,7 +207,7 @@
     return m(
         'table.query-table.pivot-table',
         m('thead', m('tr', allColumns.map(column => m('td', column)))),
-        m('tbody', renderedRows));
+        m('tbody', this.renderTotalsRow(state.queryResult), renderedRows));
   }
 
   renderQuery(): m.Vnode {