Commit aaf486c0 authored by Stephen Nusko's avatar Stephen Nusko Committed by Commit Bot

Add a "SystemProducer" layer which right now is just a dummy implementation.

This allows all platforms to have a empty implementation (which reduces
preprocessor macros), and later in this patch chain we will add a
implementation for android.

Bug: 966047
Change-Id: I5446f4da7f9de1e0cb4ecddf77a2142ad1868de6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624815Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Stephen Nusko <nuskos@chromium.org>
Auto-Submit: Stephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662591}
parent c4a40087
...@@ -72,12 +72,21 @@ MockProducerClient::MockProducerClient( ...@@ -72,12 +72,21 @@ MockProducerClient::MockProducerClient(
client_enabled_callback_(std::move(client_enabled_callback)), client_enabled_callback_(std::move(client_enabled_callback)),
client_disabled_callback_(std::move(client_disabled_callback)), client_disabled_callback_(std::move(client_disabled_callback)),
send_packet_count_(send_packet_count) { send_packet_count_(send_packet_count) {
old_producer_ = // We want to set the ProducerClient to this mock, but that 'requires' passing
PerfettoTracedProcess::Get()->SetProducerClientForTesting(this); // ownership of ourselves to PerfettoTracedProcess. Since someone else manages
// our deletion we need to be careful in the deconstructor to not double free
// ourselves.
std::unique_ptr<MockProducerClient> client;
client.reset(this);
old_producer_ = PerfettoTracedProcess::Get()->SetProducerClientForTesting(
std::move(client));
} }
MockProducerClient::~MockProducerClient() { MockProducerClient::~MockProducerClient() {
PerfettoTracedProcess::Get()->SetProducerClientForTesting(old_producer_); // See comment in the constructor. This prevents a double free.
auto client = PerfettoTracedProcess::Get()->SetProducerClientForTesting(
std::move(old_producer_));
client.release();
} }
void MockProducerClient::SetupDataSource(const std::string& data_source_name) { void MockProducerClient::SetupDataSource(const std::string& data_source_name) {
......
...@@ -77,7 +77,7 @@ class MockProducerClient : public ProducerClient { ...@@ -77,7 +77,7 @@ class MockProducerClient : public ProducerClient {
size_t send_packet_count_; size_t send_packet_count_;
std::string all_client_commit_data_requests_; std::string all_client_commit_data_requests_;
std::unique_ptr<TestDataSource> enabled_data_source_; std::unique_ptr<TestDataSource> enabled_data_source_;
ProducerClient* old_producer_; std::unique_ptr<ProducerClient> old_producer_;
}; };
class MockConsumer : public perfetto::Consumer { class MockConsumer : public perfetto::Consumer {
......
...@@ -26,6 +26,8 @@ if (!is_nacl && !is_ios) { ...@@ -26,6 +26,8 @@ if (!is_nacl && !is_ios) {
sources = [ sources = [
"base_agent.cc", "base_agent.cc",
"base_agent.h", "base_agent.h",
"perfetto/dummy_producer.cc",
"perfetto/dummy_producer.h",
"perfetto/interning_index.h", "perfetto/interning_index.h",
"perfetto/perfetto_config.cc", "perfetto/perfetto_config.cc",
"perfetto/perfetto_config.h", "perfetto/perfetto_config.h",
...@@ -37,6 +39,8 @@ if (!is_nacl && !is_ios) { ...@@ -37,6 +39,8 @@ if (!is_nacl && !is_ios) {
"perfetto/producer_client.h", "perfetto/producer_client.h",
"perfetto/shared_memory.cc", "perfetto/shared_memory.cc",
"perfetto/shared_memory.h", "perfetto/shared_memory.h",
"perfetto/system_producer.cc",
"perfetto/system_producer.h",
"perfetto/task_runner.cc", "perfetto/task_runner.cc",
"perfetto/task_runner.h", "perfetto/task_runner.h",
"perfetto/thread_local_event_sink.cc", "perfetto/thread_local_event_sink.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/tracing/public/cpp/perfetto/dummy_producer.h"
namespace tracing {
DummyProducer::DummyProducer(PerfettoTaskRunner* task_runner)
: SystemProducer(task_runner) {}
DummyProducer::~DummyProducer() {}
// perfetto::Producer functions.
void DummyProducer::OnConnect() {}
void DummyProducer::OnDisconnect() {}
void DummyProducer::OnTracingSetup() {}
void DummyProducer::SetupDataSource(perfetto::DataSourceInstanceID,
const perfetto::DataSourceConfig&) {}
void DummyProducer::StartDataSource(perfetto::DataSourceInstanceID,
const perfetto::DataSourceConfig&) {}
void DummyProducer::StopDataSource(perfetto::DataSourceInstanceID) {}
void DummyProducer::Flush(perfetto::FlushRequestID,
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources) {}
void DummyProducer::ClearIncrementalState(
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources) {}
// perfetto::TracingService::ProducerEndpoint functions.
void DummyProducer::RegisterDataSource(const perfetto::DataSourceDescriptor&) {}
void DummyProducer::UnregisterDataSource(const std::string& name) {}
void DummyProducer::RegisterTraceWriter(uint32_t writer_id,
uint32_t target_buffer) {}
void DummyProducer::UnregisterTraceWriter(uint32_t writer_id) {}
void DummyProducer::CommitData(const perfetto::CommitDataRequest& commit,
CommitDataCallback callback) {}
perfetto::SharedMemory* DummyProducer::shared_memory() const {
return nullptr;
}
size_t DummyProducer::shared_buffer_page_size_kb() const {
return 0;
}
perfetto::SharedMemoryArbiter* DummyProducer::GetSharedMemoryArbiter() {
return nullptr;
}
perfetto::SharedMemoryArbiter* DummyProducer::GetInProcessShmemArbiter() {
return nullptr;
}
void DummyProducer::NotifyFlushComplete(perfetto::FlushRequestID) {}
void DummyProducer::NotifyDataSourceStarted(perfetto::DataSourceInstanceID) {}
void DummyProducer::NotifyDataSourceStopped(perfetto::DataSourceInstanceID) {}
void DummyProducer::ActivateTriggers(const std::vector<std::string>&) {}
// tracing::PerfettoProducer functions.
void DummyProducer::NewDataSourceAdded(
const PerfettoTracedProcess::DataSourceBase* const data_source) {}
// Functions expected for SystemProducer
void DummyProducer::Disconnect() {}
} // namespace tracing
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_TRACING_PUBLIC_CPP_PERFETTO_DUMMY_PRODUCER_H_
#define SERVICES_TRACING_PUBLIC_CPP_PERFETTO_DUMMY_PRODUCER_H_
#include "services/tracing/public/cpp/perfetto/system_producer.h"
#include "third_party/perfetto/include/perfetto/tracing/core/producer.h"
namespace tracing {
class COMPONENT_EXPORT(TRACING_CPP) DummyProducer : public SystemProducer {
public:
DummyProducer(PerfettoTaskRunner* task_runner);
~DummyProducer() override;
// perfetto::Producer functions.
void OnConnect() override;
void OnDisconnect() override;
void OnTracingSetup() override;
void SetupDataSource(perfetto::DataSourceInstanceID,
const perfetto::DataSourceConfig&) override;
void StartDataSource(perfetto::DataSourceInstanceID,
const perfetto::DataSourceConfig&) override;
void StopDataSource(perfetto::DataSourceInstanceID) override;
void Flush(perfetto::FlushRequestID,
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources) override;
void ClearIncrementalState(
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources) override;
// perfetto::TracingService::ProducerEndpoint functions.
void RegisterDataSource(const perfetto::DataSourceDescriptor&) override;
void UnregisterDataSource(const std::string& name) override;
void RegisterTraceWriter(uint32_t writer_id, uint32_t target_buffer) override;
void UnregisterTraceWriter(uint32_t writer_id) override;
void CommitData(const perfetto::CommitDataRequest& commit,
CommitDataCallback callback) override;
perfetto::SharedMemory* shared_memory() const override;
size_t shared_buffer_page_size_kb() const override;
perfetto::SharedMemoryArbiter* GetSharedMemoryArbiter() override;
perfetto::SharedMemoryArbiter* GetInProcessShmemArbiter() override;
void NotifyFlushComplete(perfetto::FlushRequestID) override;
void NotifyDataSourceStarted(perfetto::DataSourceInstanceID) override;
void NotifyDataSourceStopped(perfetto::DataSourceInstanceID) override;
void ActivateTriggers(const std::vector<std::string>&) override;
// tracing::PerfettoProducer functions.
void NewDataSourceAdded(
const PerfettoTracedProcess::DataSourceBase* const data_source) override;
// Functions expected for SystemProducer
void Disconnect() override;
};
} // namespace tracing
#endif // SERVICES_TRACING_PUBLIC_CPP_PERFETTO_DUMMY_PRODUCER_H_
...@@ -8,7 +8,14 @@ ...@@ -8,7 +8,14 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "services/tracing/public/cpp/perfetto/producer_client.h" #include "services/tracing/public/cpp/perfetto/producer_client.h"
#include "services/tracing/public/cpp/perfetto/dummy_producer.h"
namespace tracing { namespace tracing {
namespace {
std::unique_ptr<SystemProducer> NewSystemProducer(PerfettoTaskRunner* runner) {
return std::make_unique<DummyProducer>(runner);
}
} // namespace
PerfettoTracedProcess::DataSourceBase::DataSourceBase(const std::string& name) PerfettoTracedProcess::DataSourceBase::DataSourceBase(const std::string& name)
: name_(name) { : name_(name) {
...@@ -32,7 +39,8 @@ PerfettoTracedProcess* PerfettoTracedProcess::Get() { ...@@ -32,7 +39,8 @@ PerfettoTracedProcess* PerfettoTracedProcess::Get() {
} }
PerfettoTracedProcess::PerfettoTracedProcess() PerfettoTracedProcess::PerfettoTracedProcess()
: producer_client_(new ProducerClient(GetTaskRunner())), : producer_client_(std::make_unique<ProducerClient>(GetTaskRunner())),
system_producer_endpoint_(NewSystemProducer(GetTaskRunner())),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DETACH_FROM_SEQUENCE(sequence_checker_); DETACH_FROM_SEQUENCE(sequence_checker_);
} }
...@@ -41,11 +49,12 @@ PerfettoTracedProcess::~PerfettoTracedProcess() { ...@@ -41,11 +49,12 @@ PerfettoTracedProcess::~PerfettoTracedProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
ProducerClient* PerfettoTracedProcess::SetProducerClientForTesting( std::unique_ptr<ProducerClient>
ProducerClient* client) { PerfettoTracedProcess::SetProducerClientForTesting(
std::unique_ptr<ProducerClient> client) {
data_sources_.clear(); data_sources_.clear();
auto* old_producer_client_for_testing = producer_client_; auto old_producer_client_for_testing = std::move(producer_client_);
producer_client_ = client; producer_client_ = std::move(client);
return old_producer_client_for_testing; return old_producer_client_for_testing;
} }
...@@ -78,7 +87,7 @@ void PerfettoTracedProcess::AddDataSource(DataSourceBase* data_source) { ...@@ -78,7 +87,7 @@ void PerfettoTracedProcess::AddDataSource(DataSourceBase* data_source) {
} }
ProducerClient* PerfettoTracedProcess::producer_client() { ProducerClient* PerfettoTracedProcess::producer_client() {
return producer_client_; return producer_client_.get();
} }
void PerfettoTracedProcess::AddDataSourceOnSequence( void PerfettoTracedProcess::AddDataSourceOnSequence(
...@@ -87,6 +96,7 @@ void PerfettoTracedProcess::AddDataSourceOnSequence( ...@@ -87,6 +96,7 @@ void PerfettoTracedProcess::AddDataSourceOnSequence(
if (data_sources_.insert(data_source).second) { if (data_sources_.insert(data_source).second) {
producer_client_->NewDataSourceAdded(data_source); producer_client_->NewDataSourceAdded(data_source);
system_producer_endpoint_->NewDataSourceAdded(data_source);
} }
} }
} // namespace tracing } // namespace tracing
...@@ -14,6 +14,7 @@ namespace tracing { ...@@ -14,6 +14,7 @@ namespace tracing {
class PerfettoProducer; class PerfettoProducer;
class ProducerClient; class ProducerClient;
class SystemProducer;
// This represents global process level state that the Perfetto tracing system // This represents global process level state that the Perfetto tracing system
// expects to exist. This includes a single base implementation of DataSources // expects to exist. This includes a single base implementation of DataSources
...@@ -65,7 +66,8 @@ class COMPONENT_EXPORT(TRACING_CPP) PerfettoTracedProcess final { ...@@ -65,7 +66,8 @@ class COMPONENT_EXPORT(TRACING_CPP) PerfettoTracedProcess final {
// Sets the ProducerClient and returns the old pointer. If tests want to // Sets the ProducerClient and returns the old pointer. If tests want to
// restore the state of the world they should store the pointer and call this // restore the state of the world they should store the pointer and call this
// method again with it as the parameter. // method again with it as the parameter.
ProducerClient* SetProducerClientForTesting(ProducerClient* client); std::unique_ptr<ProducerClient> SetProducerClientForTesting(
std::unique_ptr<ProducerClient> client);
static void DeleteSoonForTesting(std::unique_ptr<PerfettoTracedProcess>); static void DeleteSoonForTesting(std::unique_ptr<PerfettoTracedProcess>);
// Returns the taskrunner used by any Perfetto service. // Returns the taskrunner used by any Perfetto service.
...@@ -93,7 +95,12 @@ class COMPONENT_EXPORT(TRACING_CPP) PerfettoTracedProcess final { ...@@ -93,7 +95,12 @@ class COMPONENT_EXPORT(TRACING_CPP) PerfettoTracedProcess final {
std::set<DataSourceBase*> data_sources_; std::set<DataSourceBase*> data_sources_;
// A PerfettoProducer that connects to the chrome Perfetto service through // A PerfettoProducer that connects to the chrome Perfetto service through
// mojo. // mojo.
ProducerClient* producer_client_; std::unique_ptr<ProducerClient> producer_client_;
// A PerfettoProducer that connects to the system Perfetto service. If there
// is no system Perfetto service this pointer will be valid, but all function
// calls will be noops.
std::unique_ptr<SystemProducer> system_producer_endpoint_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
// NOTE: Weak pointers must be invalidated before all other member // NOTE: Weak pointers must be invalidated before all other member
// variables. // variables.
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/tracing/public/cpp/perfetto/system_producer.h"
namespace tracing {
SystemProducer::SystemProducer(PerfettoTaskRunner* task_runner)
: PerfettoProducer(task_runner) {}
} // namespace tracing
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_TRACING_PUBLIC_CPP_PERFETTO_SYSTEM_PRODUCER_H_
#define SERVICES_TRACING_PUBLIC_CPP_PERFETTO_SYSTEM_PRODUCER_H_
#include "services/tracing/public/cpp/perfetto/perfetto_producer.h"
#include "third_party/perfetto/include/perfetto/tracing/core/producer.h"
namespace tracing {
class SystemProducer : public PerfettoProducer, public perfetto::Producer {
public:
SystemProducer(PerfettoTaskRunner* task_runner);
// Since Chrome does not support concurrent tracing sessions, and system
// tracing is always lower priority than human or DevTools initiated tracing,
// all system producers must be able to disconnect and stop tracing.
virtual void Disconnect() = 0;
};
} // namespace tracing
#endif // SERVICES_TRACING_PUBLIC_CPP_PERFETTO_SYSTEM_PRODUCER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment