class ProducerEndpoint
Defined at line 107 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h
The API for the Producer port of the Service.
Subclassed by:
1. The tracing_service_impl.cc business logic when returning it in response
to the ConnectProducer() method.
2. The transport layer (e.g., src/ipc) when the producer and
the service don't talk locally but via some IPC mechanism.
Public Methods
void ~ProducerEndpoint ()
void Disconnect ()
Disconnects the endpoint from the service, while keeping the shared memory
valid. After calling this, the endpoint will no longer call any methods
on the Producer.
void RegisterDataSource (const DataSourceDescriptor & )
Called by the Producer to (un)register data sources. Data sources are
identified by their name (i.e. DataSourceDescriptor.name)
void UpdateDataSource (const DataSourceDescriptor & )
void UnregisterDataSource (const std::string & name)
void RegisterTraceWriter (uint32_t writer_id, uint32_t target_buffer)
Associate the trace writer with the given |writer_id| with
|target_buffer|. The service may use this information to retrieve and
copy uncommitted chunks written by the trace writer into its associated
buffer, e.g. when a producer process crashes or when a flush is
necessary.
void UnregisterTraceWriter (uint32_t writer_id)
Remove the association of the trace writer previously created via
RegisterTraceWriter.
void CommitData (const CommitDataRequest & , CommitDataCallback callback)
SharedMemory * shared_memory ()
void AttachV2RingBuffer (const std::shared_ptr<SharedMemory> &memory,uint32_tchunk_size_bytes,std::function<void (bool)>callback)
Attaches the producer's tracing v2 ring buffer to the service, which
installs a reader for it. The producer calls this on the endpoint
sequence, before any DrainV2RingBuffer().
- The producer owns |memory| and keeps it mapped for its writers.
- Over IPC, ProducerIPCClientImpl sends the descriptor of |memory| in the
AttachV2RingBuffer IPC. ProducerIPCService maps it and calls this on the
service's ProducerEndpointImpl.
- The ring buffer must be new: the reader starts at position 0. A ring
buffer that another reader drained fails on the first drain.
Results:
- Accepted: the layout is valid and the reader exists. Data that the
producer published before the call is kept. The service takes a
reference to |memory| and keeps it until the producer disconnects.
- Rejected: the connection and any existing attachment stay unchanged.
The service keeps no reference to |memory|.
If no ring buffer is attached, the producer can retry with a valid
mapping.
- |callback| runs on the endpoint sequence, possibly inline.
- |memory| refers to the caller's shared_ptr, and |callback| may reset it.
An implementation that needs the mapping after running |callback| must
copy |memory| first.
void DrainV2RingBuffer ()
Requests a drain of the tracing v2 ring buffer, the equivalent of
CommitData() for the v2 protocol.
- Called on the producer endpoint sequence. The call has no reply.
- Without an accepted ring buffer, the call does nothing.
- The service processes requests from each producer in order. Flush relies
on the drain completing before later requests, such as
NotifyDataSourceStopped().
See RFC 0046: https://github.com/google/perfetto/discussions/7120.
size_t shared_buffer_page_size_kb ()
Size of shared memory buffer pages. It's always a multiple of 4K.
See shared_memory_abi.h
std::unique_ptr<TraceWriter> CreateTraceWriter (BufferID target_buffer, BufferExhaustedPolicy buffer_exhausted_policy)
Creates a trace writer, which allows to create events, handling the
underying shared memory buffer and signalling to the Service. This method
is thread-safe but the returned object is not. A TraceWriter should be
used only from a single thread, or the caller has to handle sequencing
via a mutex or equivalent. This method can only be called if
TracingService::ConnectProducer was called with |in_process=true|.
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 (StartDataSource()) in the
DataSourceConfig.target_buffer().
SharedMemoryArbiter * MaybeSharedMemoryArbiter ()
In some cases you can access the producer's SharedMemoryArbiter (for
example if TracingService::ConnectProducer is called with
|in_process=true|). The SharedMemoryArbiter can be used to create
TraceWriters which is able to directly commit chunks. For the
|in_process=true| case this can be done without going through an IPC layer.
bool IsShmemProvidedByProducer ()
Whether the service accepted a shared memory buffer provided by the
producer.
void NotifyFlushComplete (FlushRequestID )
Called in response to a Producer::Flush(request_id) call after all data
for the flush request has been committed.
void NotifyDataSourceStarted (DataSourceInstanceID )
Called in response to one or more Producer::StartDataSource(),
if the data source registered setting the flag
DataSourceDescriptor.will_notify_on_start.
void NotifyDataSourceStopped (DataSourceInstanceID )
Called in response to one or more Producer::StopDataSource(),
if the data source registered setting the flag
DataSourceDescriptor.will_notify_on_stop.
void ActivateTriggers (const std::vector<std::string> & )
This informs the service to activate any of these triggers if any tracing
session was waiting for them.
void Sync (std::function<void ()> callback)
Emits a synchronization barrier to linearize with the service. When
|callback| is invoked, the caller has the guarantee that the service has
seen and processed all the requests sent by this producer prior to the
Sync() call. Used mainly in tests.