#include "services/tracing/public/cpp/perfetto/perfetto_tracing_backend.h"
#include "base/auto_reset.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/tracing/tracing_tls.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "services/tracing/public/cpp/perfetto/perfetto_producer.h"
#include "services/tracing/public/cpp/perfetto/shared_memory.h"
#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"
#include "services/tracing/public/cpp/perfetto/trace_packet_tokenizer.h"
#include "services/tracing/public/mojom/perfetto_service.mojom.h"
#include "services/tracing/public/mojom/tracing_service.mojom.h"
#include "third_party/perfetto/include/perfetto/base/task_runner.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/commit_data_request.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/consumer.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/producer.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_arbiter.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_packet.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_stats.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_writer.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h"
#include "third_party/perfetto/include/perfetto/tracing/core/trace_config.h"
ShmemMode;
namespace tracing {
namespace {
#if BUILDFLAG(IS_ANDROID)
constexpr size_t kDefaultSMBPageSizeBytes = 4 * 1024;
#else
constexpr size_t kDefaultSMBPageSizeBytes = …;
#endif
constexpr size_t kDefaultSMBSizeBytes = …;
constexpr char kErrorTracingFailed[] = …;
}
class ProducerEndpoint : public perfetto::ProducerEndpoint,
public mojom::ProducerClient { … };
class ConsumerEndpoint : public perfetto::ConsumerEndpoint,
public mojom::TracingSessionClient,
public mojo::DataPipeDrainer::Client { … };
PerfettoTracingBackend::PerfettoTracingBackend() { … }
PerfettoTracingBackend::~PerfettoTracingBackend() = default;
std::unique_ptr<perfetto::ConsumerEndpoint>
PerfettoTracingBackend::ConnectConsumer(const ConnectConsumerArgs& args) { … }
std::unique_ptr<perfetto::ProducerEndpoint>
PerfettoTracingBackend::ConnectProducer(const ConnectProducerArgs& args) { … }
void PerfettoTracingBackend::SetConsumerConnectionFactory(
ConsumerConnectionFactory factory,
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
void PerfettoTracingBackend::OnProducerConnected(
mojo::PendingRemote<mojom::PerfettoService> perfetto_service) { … }
void PerfettoTracingBackend::BindProducerConnectionIfNecessary() { … }
void PerfettoTracingBackend::CreateConsumerConnection(
base::WeakPtr<ConsumerEndpoint> consumer_endpoint) { … }
}