#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/tracing/public/cpp/perfetto/posix_system_producer.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_log.h"
#include "build/build_config.h"
#include "services/tracing/public/cpp/perfetto/shared_memory.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "services/tracing/public/cpp/traced_process_impl.h"
#include "services/tracing/public/cpp/tracing_features.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/commit_data_request.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_arbiter.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_writer.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/ipc/producer_ipc_client.h"
#include "third_party/perfetto/include/perfetto/protozero/scattered_heap_buffer.h"
#include "third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h"
#include "third_party/perfetto/protos/perfetto/common/track_event_descriptor.pbzero.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
#if !BUILDFLAG(IS_ANDROID)
#include "mojo/public/cpp/bindings/remote.h"
#include "services/tracing/public/cpp/system_tracing_service.h"
#endif
#if BUILDFLAG(IS_FUCHSIA)
#include "base/files/scoped_file.h"
#endif
namespace tracing {
namespace {
constexpr uint32_t kInitialConnectionBackoffMs = …;
constexpr uint32_t kMaxConnectionBackoffMs = …;
perfetto::DataSourceConfig EnsureGuardRailsAreFollowed(
const perfetto::DataSourceConfig& data_source_config) { … }
uint32_t IncreaseBackoff(uint32_t current, uint32_t max) { … }
}
PosixSystemProducer::PosixSystemProducer(
const char* socket,
base::tracing::PerfettoTaskRunner* task_runner)
: … { … }
PosixSystemProducer::~PosixSystemProducer() { … }
void PosixSystemProducer::SetDisallowPreAndroidPieForTesting(bool disallow) { … }
void PosixSystemProducer::SetNewSocketForTesting(const char* socket) { … }
perfetto::SharedMemoryArbiter* PosixSystemProducer::MaybeSharedMemoryArbiter() { … }
void PosixSystemProducer::NewDataSourceAdded(
const PerfettoTracedProcess::DataSourceBase* const data_source) { … }
bool PosixSystemProducer::IsTracingActive() { … }
void PosixSystemProducer::ConnectToSystemService() { … }
void PosixSystemProducer::ActivateTriggers(
const std::vector<std::string>& triggers) { … }
void PosixSystemProducer::DisconnectWithReply(
base::OnceClosure on_disconnect_complete) { … }
void PosixSystemProducer::OnConnect() { … }
void PosixSystemProducer::FinishDisconnectingAndThenDelayedReconnect(
State previous_state) { … }
void PosixSystemProducer::OnDisconnect() { … }
void PosixSystemProducer::OnTracingSetup() { … }
void PosixSystemProducer::SetupDataSource(perfetto::DataSourceInstanceID,
const perfetto::DataSourceConfig&) { … }
void PosixSystemProducer::StartDataSource(
perfetto::DataSourceInstanceID id,
const perfetto::DataSourceConfig& config) { … }
void PosixSystemProducer::StopDataSource(perfetto::DataSourceInstanceID id) { … }
void PosixSystemProducer::Flush(
perfetto::FlushRequestID id,
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources,
perfetto::FlushFlags ) { … }
void PosixSystemProducer::ClearIncrementalState(
const perfetto::DataSourceInstanceID* data_source_ids,
size_t num_data_sources) { … }
bool PosixSystemProducer::SetupSharedMemoryForStartupTracing() { … }
void PosixSystemProducer::ConnectSocket() { … }
bool PosixSystemProducer::SkipIfOnAndroidAndPreAndroidPie() const { … }
void PosixSystemProducer::InvokeStoredOnDisconnectCallbacks() { … }
void PosixSystemProducer::Connect() { … }
bool PosixSystemProducer::SandboxForbidsSocketConnection() { … }
void PosixSystemProducer::DelayedReconnect() { … }
void PosixSystemProducer::NotifyDataSourceFlushComplete(
perfetto::FlushRequestID id) { … }
perfetto::TracingService::ProducerEndpoint* PosixSystemProducer::GetService() { … }
}