diff --git a/include/perfetto/tracing/tracing.h b/include/perfetto/tracing/tracing.h index 937aa9132f..f0c515f11e 100644 --- a/include/perfetto/tracing/tracing.h +++ b/include/perfetto/tracing/tracing.h @@ -108,6 +108,11 @@ struct TracingInitArgs { // delay, i.e. commits will be sent to the service at the next opportunity. uint32_t shmem_batch_commits_duration_ms = 0; + // [Optional] Enables direct producer-side patching of chunks that have not + // yet been committed to the service. This flag will only have an effect + // if the service supports direct patching, otherwise it will be ignored. + bool shmem_direct_patching_enabled = false; + // [Optional] If set, the policy object is notified when certain SDK events // occur and may apply policy decisions, such as denying connections. The // embedder is responsible for ensuring the object remains alive for the diff --git a/src/tracing/internal/tracing_muxer_impl.cc b/src/tracing/internal/tracing_muxer_impl.cc index 738cf319cf..73d1c8d429 100644 --- a/src/tracing/internal/tracing_muxer_impl.cc +++ b/src/tracing/internal/tracing_muxer_impl.cc @@ -167,10 +167,12 @@ struct CompareBackendByType { TracingMuxerImpl::ProducerImpl::ProducerImpl( TracingMuxerImpl* muxer, TracingBackendId backend_id, - uint32_t shmem_batch_commits_duration_ms) + uint32_t shmem_batch_commits_duration_ms, + bool shmem_direct_patching_enabled) : muxer_(muxer), backend_id_(backend_id), - shmem_batch_commits_duration_ms_(shmem_batch_commits_duration_ms) {} + shmem_batch_commits_duration_ms_(shmem_batch_commits_duration_ms), + shmem_direct_patching_enabled_(shmem_direct_patching_enabled) {} TracingMuxerImpl::ProducerImpl::~ProducerImpl() { muxer_ = nullptr; @@ -260,6 +262,9 @@ void TracingMuxerImpl::ProducerImpl::OnTracingSetup() { did_setup_tracing_ = true; service_->MaybeSharedMemoryArbiter()->SetBatchCommitsDuration( shmem_batch_commits_duration_ms_); + if (shmem_direct_patching_enabled_) { + service_->MaybeSharedMemoryArbiter()->EnableDirectSMBPatching(); + } } void TracingMuxerImpl::ProducerImpl::OnStartupTracingSetup() { @@ -956,8 +961,9 @@ void TracingMuxerImpl::AddProducerBackend(TracingProducerBackend* backend, rb.backend = backend; rb.id = backend_id; rb.type = type; - rb.producer.reset( - new ProducerImpl(this, backend_id, args.shmem_batch_commits_duration_ms)); + rb.producer.reset(new ProducerImpl(this, backend_id, + args.shmem_batch_commits_duration_ms, + args.shmem_direct_patching_enabled)); rb.producer_conn_args.producer = rb.producer.get(); rb.producer_conn_args.producer_name = platform_->GetCurrentProcessName(); rb.producer_conn_args.task_runner = task_runner_.get(); diff --git a/src/tracing/internal/tracing_muxer_impl.h b/src/tracing/internal/tracing_muxer_impl.h index ab132f3b2c..8af3092167 100644 --- a/src/tracing/internal/tracing_muxer_impl.h +++ b/src/tracing/internal/tracing_muxer_impl.h @@ -209,7 +209,8 @@ class TracingMuxerImpl : public TracingMuxer { public: ProducerImpl(TracingMuxerImpl*, TracingBackendId, - uint32_t shmem_batch_commits_duration_ms); + uint32_t shmem_batch_commits_duration_ms, + bool shmem_direct_patching_enabled); ~ProducerImpl() override; void Initialize(std::unique_ptr endpoint); @@ -250,6 +251,7 @@ class TracingMuxerImpl : public TracingMuxer { bool producer_provided_smb_failed_ = false; const uint32_t shmem_batch_commits_duration_ms_ = 0; + const bool shmem_direct_patching_enabled_ = false; // Set of data sources that have been actually registered on this producer. // This can be a subset of the global |data_sources_|, because data sources