Merge "trace_processor: make schema more explicit in tables"
diff --git a/include/perfetto/base/watchdog_noop.h b/include/perfetto/base/watchdog_noop.h
index 1c14b8a..e542aa6 100644
--- a/include/perfetto/base/watchdog_noop.h
+++ b/include/perfetto/base/watchdog_noop.h
@@ -31,7 +31,10 @@
     Timer(const Timer&) {}
     ~Timer() {}
   };
-  static Watchdog* GetInstance();
+  static Watchdog* GetInstance() {
+    static Watchdog* watchdog = new Watchdog();
+    return watchdog;
+  }
   Timer CreateFatalTimer(uint32_t /*ms*/) { return Timer(); }
   void Start() {}
   void SetMemoryLimit(uint32_t /*bytes*/, uint32_t /*window_ms*/) {}
diff --git a/include/perfetto/tracing/core/producer.h b/include/perfetto/tracing/core/producer.h
index 0c8506a..3f8698f 100644
--- a/include/perfetto/tracing/core/producer.h
+++ b/include/perfetto/tracing/core/producer.h
@@ -35,7 +35,7 @@
 //    API TracingService::ProducerEndpoint::OnPageAcquired()/OnPageReleased()).
 // 3. At some point later on, the Service asks the Producer to turn on some of
 //    the previously registered data sources, together with some configuration
-//    parameters. This happens via the CreateDataSourceInstance() callback.
+//    parameters. This happens via the StartDataSource() callback.
 // 4. In response to that the Producer will spawn an instance of the given data
 //    source and inject its data into the shared memory buffer (obtained during
 //    OnConnect).
@@ -60,22 +60,19 @@
   // instance.
   virtual void OnDisconnect() = 0;
 
-  // TODO(primiano): rename the methods below to Start/StopDataSourceInstance
-  // in the next CLs.
-
   // Called by the Service to turn on one of the data source previously
   // registered through TracingService::ProducerEndpoint::RegisterDataSource().
   // Args:
   // - DataSourceInstanceID is an identifier chosen by the Service that should
   //   be assigned to the newly created data source instance. It is used to
-  //   match the TearDownDataSourceInstance() request below.
+  //   match the StopDataSource() request below.
   // - DataSourceConfig is the configuration for the new data source (e.g.,
   //   tells which trace categories to enable).
-  virtual void CreateDataSourceInstance(DataSourceInstanceID,
-                                        const DataSourceConfig&) = 0;
+  virtual void StartDataSource(DataSourceInstanceID,
+                               const DataSourceConfig&) = 0;
 
   // Called by the Service to shut down an existing data source instance.
-  virtual void TearDownDataSourceInstance(DataSourceInstanceID) = 0;
+  virtual void StopDataSource(DataSourceInstanceID) = 0;
 
   // Called by the Service after OnConnect but before the first DataSource is
   // created. Can be used for any setup required before tracing begins.
diff --git a/include/perfetto/tracing/core/tracing_service.h b/include/perfetto/tracing/core/tracing_service.h
index c542af87..5759368 100644
--- a/include/perfetto/tracing/core/tracing_service.h
+++ b/include/perfetto/tracing/core/tracing_service.h
@@ -92,7 +92,7 @@
     // Args:
     // |target_buffer| is the target buffer ID where the data produced by the
     // writer should be stored by the tracing service. This value is passed
-    // upon creation of the data source (CreateDataSourceInstance()) in the
+    // upon creation of the data source (StartDataSource()) in the
     // DataSourceConfig.target_buffer().
     virtual std::unique_ptr<TraceWriter> CreateTraceWriter(
         BufferID target_buffer) = 0;
@@ -101,7 +101,7 @@
     // for the flush request has been committed.
     virtual void NotifyFlushComplete(FlushRequestID) = 0;
 
-    // Called in response to one or more Producer::TearDownDataSourceInstance(),
+    // Called in response to one or more Producer::StopDataSource(),
     // if the data source registered setting the flag
     // DataSourceDescriptor.will_notify_on_stop.
     virtual void NotifyDataSourceStopped(DataSourceInstanceID) = 0;
diff --git a/src/base/BUILD.gn b/src/base/BUILD.gn
index db88974..68939a9 100644
--- a/src/base/BUILD.gn
+++ b/src/base/BUILD.gn
@@ -44,8 +44,6 @@
 
   if (!build_with_chromium && (is_linux || is_android)) {
     sources += [ "watchdog_posix.cc" ]
-  } else {
-    sources += [ "watchdog_noop.cc" ]
   }
   if (is_debug && build_standalone && !is_wasm) {
     deps += [ ":debug_crash_stack_trace" ]
diff --git a/src/base/watchdog_noop.cc b/src/base/watchdog_noop.cc
deleted file mode 100644
index 97f0777..0000000
--- a/src/base/watchdog_noop.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "perfetto/base/watchdog_noop.h"
-
-namespace perfetto {
-namespace base {
-
-Watchdog* Watchdog::GetInstance() {
-  static Watchdog* watchdog = new Watchdog();
-  return watchdog;
-}
-
-}  // namespace base
-}  // namespace perfetto
diff --git a/src/traced/probes/probes_producer.cc b/src/traced/probes/probes_producer.cc
index cc90242..5b37165 100644
--- a/src/traced/probes/probes_producer.cc
+++ b/src/traced/probes/probes_producer.cc
@@ -129,8 +129,8 @@
   ConnectWithRetries(socket_name, task_runner);
 }
 
-void ProbesProducer::CreateDataSourceInstance(DataSourceInstanceID instance_id,
-                                              const DataSourceConfig& config) {
+void ProbesProducer::StartDataSource(DataSourceInstanceID instance_id,
+                                     const DataSourceConfig& config) {
   PERFETTO_DCHECK(data_sources_.count(instance_id) == 0);
   TracingSessionID session_id = config.tracing_session_id();
   PERFETTO_CHECK(session_id > 0);
@@ -241,7 +241,7 @@
   return data_source;
 }
 
-void ProbesProducer::TearDownDataSourceInstance(DataSourceInstanceID id) {
+void ProbesProducer::StopDataSource(DataSourceInstanceID id) {
   PERFETTO_LOG("Producer stop (id=%" PRIu64 ")", id);
   auto it = data_sources_.find(id);
   if (it == data_sources_.end()) {
diff --git a/src/traced/probes/probes_producer.h b/src/traced/probes/probes_producer.h
index c3670ce..e7b9403 100644
--- a/src/traced/probes/probes_producer.h
+++ b/src/traced/probes/probes_producer.h
@@ -49,9 +49,8 @@
   // Producer Impl:
   void OnConnect() override;
   void OnDisconnect() override;
-  void CreateDataSourceInstance(DataSourceInstanceID,
-                                const DataSourceConfig&) override;
-  void TearDownDataSourceInstance(DataSourceInstanceID) override;
+  void StartDataSource(DataSourceInstanceID, const DataSourceConfig&) override;
+  void StopDataSource(DataSourceInstanceID) override;
   void OnTracingSetup() override;
   void Flush(FlushRequestID,
              const DataSourceInstanceID* data_source_ids,
diff --git a/src/tracing/core/shared_memory_arbiter_impl.h b/src/tracing/core/shared_memory_arbiter_impl.h
index 0ba1c14..44bfbd5 100644
--- a/src/tracing/core/shared_memory_arbiter_impl.h
+++ b/src/tracing/core/shared_memory_arbiter_impl.h
@@ -73,7 +73,7 @@
   // service to move it to the central tracing buffer. |target_buffer| is the
   // absolute trace buffer ID where the service should move the chunk onto (the
   // producer is just to copy back the same number received in the
-  // DataSourceConfig upon the CreateDataSourceInstance() reques).
+  // DataSourceConfig upon the StartDataSource() reques).
   // PatchList is a pointer to the list of patches for previous chunks. The
   // first patched entries will be removed from the patched list and sent over
   // to the service in the same CommitData() IPC request.
diff --git a/src/tracing/core/tracing_service_impl.cc b/src/tracing/core/tracing_service_impl.cc
index ef344a9..2483235 100644
--- a/src/tracing/core/tracing_service_impl.cc
+++ b/src/tracing/core/tracing_service_impl.cc
@@ -353,8 +353,8 @@
           break;
         }
       }
-      CreateDataSourceInstance(cfg_data_source, producer_config, it->second,
-                               tracing_session);
+      StartDataSource(cfg_data_source, producer_config, it->second,
+                      tracing_session);
     }
   }
 
@@ -886,8 +886,8 @@
     for (const TraceConfig::DataSource& cfg_data_source :
          tracing_session.config.data_sources()) {
       if (cfg_data_source.config().name() == desc.name())
-        CreateDataSourceInstance(cfg_data_source, producer_config,
-                                 reg_ds->second, &tracing_session);
+        StartDataSource(cfg_data_source, producer_config, reg_ds->second,
+                        &tracing_session);
     }
   }
 }
@@ -926,7 +926,7 @@
   PERFETTO_DCHECK(false);
 }
 
-void TracingServiceImpl::CreateDataSourceInstance(
+void TracingServiceImpl::StartDataSource(
     const TraceConfig::DataSource& cfg_data_source,
     const TraceConfig::ProducerConfig& producer_config,
     const RegisteredDataSource& data_source,
@@ -1011,7 +1011,7 @@
     producer->OnTracingSetup();
     UpdateMemoryGuardrail();
   }
-  producer->CreateDataSourceInstance(inst_id, ds_config);
+  producer->StartDataSource(inst_id, ds_config);
 }
 
 // Note: all the fields % *_trusted ones are untrusted, as in, the Producer
@@ -1482,7 +1482,7 @@
   auto weak_this = weak_ptr_factory_.GetWeakPtr();
   task_runner_->PostTask([weak_this, ds_inst_id] {
     if (weak_this)
-      weak_this->producer_->TearDownDataSourceInstance(ds_inst_id);
+      weak_this->producer_->StopDataSource(ds_inst_id);
   });
 }
 
@@ -1524,14 +1524,14 @@
   });
 }
 
-void TracingServiceImpl::ProducerEndpointImpl::CreateDataSourceInstance(
+void TracingServiceImpl::ProducerEndpointImpl::StartDataSource(
     DataSourceInstanceID ds_id,
     const DataSourceConfig& config) {
   PERFETTO_DCHECK_THREAD(thread_checker_);
   auto weak_this = weak_ptr_factory_.GetWeakPtr();
   task_runner_->PostTask([weak_this, ds_id, config] {
     if (weak_this)
-      weak_this->producer_->CreateDataSourceInstance(ds_id, std::move(config));
+      weak_this->producer_->StartDataSource(ds_id, std::move(config));
   });
 }
 
diff --git a/src/tracing/core/tracing_service_impl.h b/src/tracing/core/tracing_service_impl.h
index 62961b3..d50057e 100644
--- a/src/tracing/core/tracing_service_impl.h
+++ b/src/tracing/core/tracing_service_impl.h
@@ -83,8 +83,7 @@
     size_t shared_buffer_page_size_kb() const override;
 
     void OnTracingSetup();
-    void CreateDataSourceInstance(DataSourceInstanceID,
-                                  const DataSourceConfig&);
+    void StartDataSource(DataSourceInstanceID, const DataSourceConfig&);
     void TearDownDataSource(DataSourceInstanceID);
     void Flush(FlushRequestID, const std::vector<DataSourceInstanceID>&);
 
@@ -277,10 +276,10 @@
   TracingServiceImpl(const TracingServiceImpl&) = delete;
   TracingServiceImpl& operator=(const TracingServiceImpl&) = delete;
 
-  void CreateDataSourceInstance(const TraceConfig::DataSource&,
-                                const TraceConfig::ProducerConfig&,
-                                const RegisteredDataSource&,
-                                TracingSession*);
+  void StartDataSource(const TraceConfig::DataSource&,
+                       const TraceConfig::ProducerConfig&,
+                       const RegisteredDataSource&,
+                       TracingSession*);
 
   // Returns the next available ProducerID that is not in |producers_|.
   ProducerID GetNextProducerID();
diff --git a/src/tracing/ipc/producer/producer_ipc_client_impl.cc b/src/tracing/ipc/producer/producer_ipc_client_impl.cc
index b90331b..2abdcf7 100644
--- a/src/tracing/ipc/producer/producer_ipc_client_impl.cc
+++ b/src/tracing/ipc/producer/producer_ipc_client_impl.cc
@@ -114,13 +114,13 @@
     const DataSourceInstanceID dsid = req.new_instance_id();
     DataSourceConfig cfg;
     cfg.FromProto(req.config());
-    producer_->CreateDataSourceInstance(dsid, cfg);
+    producer_->StartDataSource(dsid, cfg);
     return;
   }
 
   if (cmd.cmd_case() == protos::GetAsyncCommandResponse::kStopDataSource) {
     const DataSourceInstanceID dsid = cmd.stop_data_source().instance_id();
-    producer_->TearDownDataSourceInstance(dsid);
+    producer_->StopDataSource(dsid);
     return;
   }
 
diff --git a/src/tracing/ipc/service/producer_ipc_service.cc b/src/tracing/ipc/service/producer_ipc_service.cc
index f3c474b..e2c2ab9 100644
--- a/src/tracing/ipc/service/producer_ipc_service.cc
+++ b/src/tracing/ipc/service/producer_ipc_service.cc
@@ -213,7 +213,7 @@
 
 // Invoked by the |core_service_| business logic when it wants to start a new
 // data source.
-void ProducerIPCService::RemoteProducer::CreateDataSourceInstance(
+void ProducerIPCService::RemoteProducer::StartDataSource(
     DataSourceInstanceID dsid,
     const DataSourceConfig& cfg) {
   if (!async_producer_commands.IsBound()) {
@@ -229,7 +229,7 @@
   async_producer_commands.Resolve(std::move(cmd));
 }
 
-void ProducerIPCService::RemoteProducer::TearDownDataSourceInstance(
+void ProducerIPCService::RemoteProducer::StopDataSource(
     DataSourceInstanceID dsid) {
   if (!async_producer_commands.IsBound()) {
     PERFETTO_DLOG(
diff --git a/src/tracing/ipc/service/producer_ipc_service.h b/src/tracing/ipc/service/producer_ipc_service.h
index b6aff02..8446804 100644
--- a/src/tracing/ipc/service/producer_ipc_service.h
+++ b/src/tracing/ipc/service/producer_ipc_service.h
@@ -71,9 +71,9 @@
     // no connection here, these methods are posted straight away.
     void OnConnect() override;
     void OnDisconnect() override;
-    void CreateDataSourceInstance(DataSourceInstanceID,
-                                  const DataSourceConfig&) override;
-    void TearDownDataSourceInstance(DataSourceInstanceID) override;
+    void StartDataSource(DataSourceInstanceID,
+                         const DataSourceConfig&) override;
+    void StopDataSource(DataSourceInstanceID) override;
     void OnTracingSetup() override;
     void Flush(FlushRequestID,
                const DataSourceInstanceID* data_source_ids,
diff --git a/src/tracing/test/mock_producer.cc b/src/tracing/test/mock_producer.cc
index 32a00f8..8c2f9c5 100644
--- a/src/tracing/test/mock_producer.cc
+++ b/src/tracing/test/mock_producer.cc
@@ -80,8 +80,8 @@
   static int i = 0;
   auto checkpoint_name = "on_ds_start_" + name + "_" + std::to_string(i++);
   auto on_ds_start = task_runner_->CreateCheckpoint(checkpoint_name);
-  EXPECT_CALL(*this, CreateDataSourceInstance(
-                         _, Property(&DataSourceConfig::name, Eq(name))))
+  EXPECT_CALL(*this,
+              StartDataSource(_, Property(&DataSourceConfig::name, Eq(name))))
       .WillOnce(Invoke([on_ds_start, this](DataSourceInstanceID ds_id,
                                            const DataSourceConfig& cfg) {
         EXPECT_FALSE(data_source_instances_.count(cfg.name()));
@@ -101,7 +101,7 @@
   auto on_ds_stop = task_runner_->CreateCheckpoint(checkpoint_name);
   ASSERT_EQ(1u, data_source_instances_.count(name));
   DataSourceInstanceID ds_id = data_source_instances_[name].id;
-  EXPECT_CALL(*this, TearDownDataSourceInstance(ds_id))
+  EXPECT_CALL(*this, StopDataSource(ds_id))
       .WillOnce(InvokeWithoutArgs(on_ds_stop));
   task_runner_->RunUntilCheckpoint(checkpoint_name);
   data_source_instances_.erase(name);
diff --git a/src/tracing/test/mock_producer.h b/src/tracing/test/mock_producer.h
index 1cf1967..590a64e 100644
--- a/src/tracing/test/mock_producer.h
+++ b/src/tracing/test/mock_producer.h
@@ -68,9 +68,9 @@
   // Producer implementation.
   MOCK_METHOD0(OnConnect, void());
   MOCK_METHOD0(OnDisconnect, void());
-  MOCK_METHOD2(CreateDataSourceInstance,
+  MOCK_METHOD2(StartDataSource,
                void(DataSourceInstanceID, const DataSourceConfig&));
-  MOCK_METHOD1(TearDownDataSourceInstance, void(DataSourceInstanceID));
+  MOCK_METHOD1(StopDataSource, void(DataSourceInstanceID));
   MOCK_METHOD0(OnTracingSetup, void());
   MOCK_METHOD3(Flush,
                void(FlushRequestID, const DataSourceInstanceID*, size_t));
diff --git a/src/tracing/test/tracing_integration_test.cc b/src/tracing/test/tracing_integration_test.cc
index ef8bc7a..26aa5cd 100644
--- a/src/tracing/test/tracing_integration_test.cc
+++ b/src/tracing/test/tracing_integration_test.cc
@@ -56,9 +56,9 @@
   // Producer implementation.
   MOCK_METHOD0(OnConnect, void());
   MOCK_METHOD0(OnDisconnect, void());
-  MOCK_METHOD2(CreateDataSourceInstance,
+  MOCK_METHOD2(StartDataSource,
                void(DataSourceInstanceID, const DataSourceConfig&));
-  MOCK_METHOD1(TearDownDataSourceInstance, void(DataSourceInstanceID));
+  MOCK_METHOD1(StopDataSource, void(DataSourceInstanceID));
   MOCK_METHOD0(uid, uid_t());
   MOCK_METHOD0(OnTracingSetup, void());
   MOCK_METHOD3(Flush,
@@ -187,7 +187,7 @@
   auto on_create_ds_instance =
       task_runner_->CreateCheckpoint("on_create_ds_instance");
   EXPECT_CALL(producer_, OnTracingSetup());
-  EXPECT_CALL(producer_, CreateDataSourceInstance(_, _))
+  EXPECT_CALL(producer_, StartDataSource(_, _))
       .WillOnce(
           Invoke([on_create_ds_instance, &ds_iid, &global_buf_id](
                      DataSourceInstanceID id, const DataSourceConfig& cfg) {
@@ -286,7 +286,7 @@
 
   auto on_tracing_disabled =
       task_runner_->CreateCheckpoint("on_tracing_disabled");
-  EXPECT_CALL(producer_, TearDownDataSourceInstance(_));
+  EXPECT_CALL(producer_, StopDataSource(_));
   EXPECT_CALL(consumer_, OnTracingDisabled())
       .WillOnce(Invoke(on_tracing_disabled));
   task_runner_->RunUntilCheckpoint("on_tracing_disabled");
@@ -309,7 +309,7 @@
   auto on_create_ds_instance =
       task_runner_->CreateCheckpoint("on_create_ds_instance");
   EXPECT_CALL(producer_, OnTracingSetup());
-  EXPECT_CALL(producer_, CreateDataSourceInstance(_, _))
+  EXPECT_CALL(producer_, StartDataSource(_, _))
       .WillOnce(Invoke([on_create_ds_instance, &global_buf_id](
                            DataSourceInstanceID, const DataSourceConfig& cfg) {
         global_buf_id = static_cast<BufferID>(cfg.target_buffer());
@@ -337,7 +337,7 @@
 
   auto on_tracing_disabled =
       task_runner_->CreateCheckpoint("on_tracing_disabled");
-  EXPECT_CALL(producer_, TearDownDataSourceInstance(_));
+  EXPECT_CALL(producer_, StopDataSource(_));
   EXPECT_CALL(consumer_, OnTracingDisabled())
       .WillOnce(Invoke(on_tracing_disabled));
   task_runner_->RunUntilCheckpoint("on_tracing_disabled");
diff --git a/test/end_to_end_shared_memory_fuzzer.cc b/test/end_to_end_shared_memory_fuzzer.cc
index 6d29512..7bd70b3 100644
--- a/test/end_to_end_shared_memory_fuzzer.cc
+++ b/test/end_to_end_shared_memory_fuzzer.cc
@@ -76,9 +76,8 @@
 
   void OnDisconnect() override {}
 
-  void CreateDataSourceInstance(
-      DataSourceInstanceID,
-      const DataSourceConfig& source_config) override {
+  void StartDataSource(DataSourceInstanceID,
+                       const DataSourceConfig& source_config) override {
     auto trace_writer = endpoint_->CreateTraceWriter(
         static_cast<BufferID>(source_config.target_buffer()));
     {
@@ -94,7 +93,7 @@
     trace_writer->Flush(on_produced_and_committed_);
   }
 
-  void TearDownDataSourceInstance(DataSourceInstanceID) override {}
+  void StopDataSource(DataSourceInstanceID) override {}
   void OnTracingSetup() override {}
   void Flush(FlushRequestID, const DataSourceInstanceID*, size_t) override {}
 
diff --git a/test/fake_producer.cc b/test/fake_producer.cc
index 823759c..ae8ea07 100644
--- a/test/fake_producer.cc
+++ b/test/fake_producer.cc
@@ -57,9 +57,8 @@
   FAIL() << "Producer unexpectedly disconnected from the service";
 }
 
-void FakeProducer::CreateDataSourceInstance(
-    DataSourceInstanceID,
-    const DataSourceConfig& source_config) {
+void FakeProducer::StartDataSource(DataSourceInstanceID,
+                                   const DataSourceConfig& source_config) {
   PERFETTO_DCHECK_THREAD(thread_checker_);
   trace_writer_ = endpoint_->CreateTraceWriter(
       static_cast<BufferID>(source_config.target_buffer()));
@@ -75,7 +74,7 @@
   }
 }
 
-void FakeProducer::TearDownDataSourceInstance(DataSourceInstanceID) {
+void FakeProducer::StopDataSource(DataSourceInstanceID) {
   PERFETTO_DCHECK_THREAD(thread_checker_);
   trace_writer_.reset();
 }
diff --git a/test/fake_producer.h b/test/fake_producer.h
index b9101e7..cc55640 100644
--- a/test/fake_producer.h
+++ b/test/fake_producer.h
@@ -46,9 +46,9 @@
   // Producer implementation.
   void OnConnect() override;
   void OnDisconnect() override;
-  void CreateDataSourceInstance(DataSourceInstanceID,
-                                const DataSourceConfig& source_config) override;
-  void TearDownDataSourceInstance(DataSourceInstanceID) override;
+  void StartDataSource(DataSourceInstanceID,
+                       const DataSourceConfig& source_config) override;
+  void StopDataSource(DataSourceInstanceID) override;
   void OnTracingSetup() override;
   void Flush(FlushRequestID, const DataSourceInstanceID*, size_t) override;