Introduce support for deferred start (fast triggering)

This CL introduces new Setup methods to both the
producer and consumer API. The API changes are designed
to be backwards compatible with the prior versions of
Android.

From the producer viewpoint: each data source now sees a
SetupDataSource() method before the StartDataSource() method.
The data source instance id and config is identical. This
gives the data source a chance to setup itself before actually
starting.

From the consumer viewpoint:
A new "deferred_start" field is added to the TraceConfig.
When deferred_start is true, the EnableTracing method
brings up all the tracing harness and calls the
SetupDataSource() methods on the producers, but doesn't
start them. Data sources are started only when calling
StartDataSource().

Note that in this CL, the ftrace data source doesn't
deal yet with the split Setup/Start phases and starts
directly upon creation. This will be fixed in a separate
CL.

Bug: 116547201
Change-Id: I2ab22c7f8ee2388f8158df733dddeef9dc9c0143
diff --git a/src/tracing/core/tracing_service_impl.h b/src/tracing/core/tracing_service_impl.h
index d50057e..9c325cd 100644
--- a/src/tracing/core/tracing_service_impl.h
+++ b/src/tracing/core/tracing_service_impl.h
@@ -83,8 +83,9 @@
     size_t shared_buffer_page_size_kb() const override;
 
     void OnTracingSetup();
+    void SetupDataSource(DataSourceInstanceID, const DataSourceConfig&);
     void StartDataSource(DataSourceInstanceID, const DataSourceConfig&);
-    void TearDownDataSource(DataSourceInstanceID);
+    void StopDataSource(DataSourceInstanceID);
     void Flush(FlushRequestID, const std::vector<DataSourceInstanceID>&);
 
    private:
@@ -122,6 +123,7 @@
 
     // TracingService::ConsumerEndpoint implementation.
     void EnableTracing(const TraceConfig&, base::ScopedFile) override;
+    void StartTracing() override;
     void DisableTracing() override;
     void ReadBuffers() override;
     void FreeBuffers() override;
@@ -167,6 +169,7 @@
   bool EnableTracing(ConsumerEndpointImpl*,
                      const TraceConfig&,
                      base::ScopedFile);
+  bool StartTracing(TracingSessionID);
   void DisableTracing(TracingSessionID, bool disable_immediately = false);
   void Flush(TracingSessionID tsid,
              uint32_t timeout_ms,
@@ -201,7 +204,12 @@
 
   // Represents an active data source for a tracing session.
   struct DataSourceInstance {
+    DataSourceInstance(const DataSourceInstance&) = delete;
+    DataSourceInstance& operator=(const DataSourceInstance&) = delete;
+    DataSourceInstance(DataSourceInstance&&) noexcept = default;
+
     DataSourceInstanceID instance_id;
+    DataSourceConfig config;
     std::string data_source_name;
     bool will_notify_on_stop;
   };
@@ -215,7 +223,12 @@
   // Holds the state of a tracing session. A tracing session is uniquely bound
   // a specific Consumer. Each Consumer can own one or more sessions.
   struct TracingSession {
-    enum State { DISABLED = 0, ENABLED, DISABLING_WAITING_STOP_ACKS };
+    enum State {
+      DISABLED = 0,
+      CONFIGURED,
+      STARTED,
+      DISABLING_WAITING_STOP_ACKS
+    };
 
     TracingSession(TracingSessionID, ConsumerEndpointImpl*, const TraceConfig&);
 
@@ -276,10 +289,10 @@
   TracingServiceImpl(const TracingServiceImpl&) = delete;
   TracingServiceImpl& operator=(const TracingServiceImpl&) = delete;
 
-  void StartDataSource(const TraceConfig::DataSource&,
-                       const TraceConfig::ProducerConfig&,
-                       const RegisteredDataSource&,
-                       TracingSession*);
+  DataSourceInstance* SetupDataSource(const TraceConfig::DataSource&,
+                                      const TraceConfig::ProducerConfig&,
+                                      const RegisteredDataSource&,
+                                      TracingSession*);
 
   // Returns the next available ProducerID that is not in |producers_|.
   ProducerID GetNextProducerID();