Record a periodic clock snapshot

Periodically (every 10s when packets are read) record a snapshot of all
system clocks. This will allow the consumer to align clocks between
multiple data sources.

Change-Id: I0f0d07764cff141d8874c4e225f90094d0836e7d
diff --git a/src/tracing/core/service_impl.h b/src/tracing/core/service_impl.h
index d06f550..ac6b780 100644
--- a/src/tracing/core/service_impl.h
+++ b/src/tracing/core/service_impl.h
@@ -24,6 +24,7 @@
 
 #include "gtest/gtest_prod.h"
 #include "perfetto/base/page_allocator.h"
+#include "perfetto/base/time.h"
 #include "perfetto/base/weak_ptr.h"
 #include "perfetto/tracing/core/basic_types.h"
 #include "perfetto/tracing/core/commit_data_request.h"
@@ -45,6 +46,7 @@
 class SharedMemory;
 class TraceBuffez;
 class TraceConfig;
+class TracePacket;
 
 // The tracing service business logic.
 class ServiceImpl : public Service {
@@ -189,6 +191,9 @@
     // BufferID (shared namespace amongst all consumers). This vector has as
     // many entries as |config.buffers_size()|.
     std::vector<BufferID> buffers_index;
+
+    // When the last clock snapshot was emitted into the output stream.
+    base::TimeMillis last_clock_snapshot = {};
   };
 
   ServiceImpl(const ServiceImpl&) = delete;
@@ -209,6 +214,8 @@
   // shared memory and trace buffers.
   void UpdateMemoryGuardrail();
 
+  void MaybeSnapshotClocks(TracingSession*, std::vector<TracePacket>*);
+
   TraceBuffez* GetBufferByID(BufferID);
 
   base::TaskRunner* const task_runner_;