class TracingService
Defined at line 352 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h
The public API of the tracing Service business logic.
Exposed to:
1. The transport layer (e.g., src/unix_rpc/unix_service_host.cc),
which forwards commands received from a remote producer or consumer to
the actual service implementation.
2. Tests.
Subclassed by:
The service business logic in src/core/tracing_service_impl.cc.
Public Members
static const size_t kDefaultShmPageSize
static const size_t kDefaultShmSize
Public Methods
std::unique_ptr<TracingService> CreateInstance (std::unique_ptr<SharedMemory::Factory> , base::TaskRunner * , InitOpts init_opts)
Implemented in src/core/tracing_service_impl.cc . CompressorFn can be
nullptr, in which case TracingService will not support compression.
void ~TracingService ()
std::unique_ptr<ProducerEndpoint> ConnectProducer (Producer * , const ClientIdentity & client_identity, const std::string & name, size_t shared_memory_size_hint_bytes, bool in_process, ProducerSMBScrapingMode smb_scraping_mode, size_t shared_memory_page_size_hint_bytes, std::unique_ptr<SharedMemory> shm, const std::string & sdk_version, const std::string & machine_name)
Connects a Producer instance and obtains a ProducerEndpoint, which is
essentially a 1:1 channel between one Producer and the Service.
The caller has to guarantee that the passed Producer will be alive as long
as the returned ProducerEndpoint is alive. Both the passed Producer and the
returned ProducerEndpoint must live on the same task runner of the service,
specifically:
1) The Service will call Producer::* methods on the Service's task runner.
2) The Producer should call ProducerEndpoint::* methods only on the
service's task runner, except for ProducerEndpoint::CreateTraceWriter(),
which can be called on any thread. To disconnect just destroy the
returned ProducerEndpoint object. It is safe to destroy the Producer
once the Producer::OnDisconnect() has been invoked.
|uid| is the trusted user id of the producer process, used by the consumers
for validating the origin of trace data. |shared_memory_size_hint_bytes|
and |shared_memory_page_size_hint_bytes| are optional hints on the size of
the shared memory buffer and its pages. The service can ignore the hints
(e.g., if the hints are unreasonably large or other sizes were configured
in a tracing session's config). |in_process| enables the ProducerEndpoint
to manage its own shared memory and enables use of
|ProducerEndpoint::CreateTraceWriter|.
The producer can optionally provide a non-null |shm|, which the service
will adopt for the connection to the producer, provided it is correctly
sized. In this case, |shared_memory_page_size_hint_bytes| indicates the
page size used in this SMB. The producer can use this mechanism to record
tracing data to an SMB even before the tracing session is started by the
service. This is used in Chrome to implement startup tracing. If the buffer
is incorrectly sized, the service will discard the SMB and allocate a new
one, provided to the producer via ProducerEndpoint::shared_memory() after
OnTracingSetup(). To verify that the service accepted the SMB, the producer
may check via ProducerEndpoint::IsShmemProvidedByProducer(). If the service
accepted the SMB, the producer can then commit any data that is already in
the SMB after the tracing session was started by the service via
Producer::StartDataSource(). The |shm| will also be rejected when
connecting to a service that is too old (pre Android-11).
Can return null in the unlikely event that service has too many producers
connected.
std::unique_ptr<ConsumerEndpoint> ConnectConsumer (Consumer * , uid_t )
Connects a Consumer instance and obtains a ConsumerEndpoint, which is
essentially a 1:1 channel between one Consumer and the Service.
The caller has to guarantee that the passed Consumer will be alive as long
as the returned ConsumerEndpoint is alive.
To disconnect just destroy the returned ConsumerEndpoint object. It is safe
to destroy the Consumer once the Consumer::OnDisconnect() has been invoked.
void SetSMBScrapingEnabled (bool enabled)
Enable/disable scraping of chunks in the shared memory buffer. If enabled,
the service will copy uncommitted but non-empty chunks from the SMB when
flushing (e.g. to handle unresponsive producers or producers unable to
flush their active chunks), on producer disconnect (e.g. to recover data
from crashed producers), and after disabling a tracing session (e.g. to
gather data from producers that didn't stop their data sources in time).
This feature is currently used by Chrome.
std::unique_ptr<RelayEndpoint> ConnectRelayClient (RelayClientID )
Connects a remote RelayClient instance and obtains a RelayEndpoint, which
is a 1:1 channel between one RelayClient and the Service. To disconnect
just call Disconnect() of the RelayEndpoint instance. The relay client is
connected using an identifier of MachineID and client ID. The service
doesn't hold an object that represents the client because the relay port
only has a client-to-host SyncClock() method.
TODO(chinglinyu): connect the relay client using a RelayClient* object when
we need host-to-client RPC method.
Enumerations
enum ProducerSMBScrapingMode
| Name | Value |
|---|---|
| kDefault | 0 |
| kEnabled | 1 |
| kDisabled | 2 |
Defined at line 363 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h