xref: /aosp_15_r20/external/perfetto/docs/design-docs/api-and-abi.md (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker# Tracing API and ABI: surfaces and stability
2*6dbdd20aSAndroid Build Coastguard Worker
3*6dbdd20aSAndroid Build Coastguard WorkerThis document describes the API and ABI surface of the
4*6dbdd20aSAndroid Build Coastguard Worker[Perfetto Client Library][cli_lib], what can be expected to be stable long-term
5*6dbdd20aSAndroid Build Coastguard Workerand what not.
6*6dbdd20aSAndroid Build Coastguard Worker
7*6dbdd20aSAndroid Build Coastguard Worker#### In summary
8*6dbdd20aSAndroid Build Coastguard Worker
9*6dbdd20aSAndroid Build Coastguard Worker* The public C++ API in `include/perfetto/tracing/` is mostly stable but can
10*6dbdd20aSAndroid Build Coastguard Worker  occasionally break at compile-time throughout 2020.
11*6dbdd20aSAndroid Build Coastguard Worker* The C++ API within `include/perfetto/ext/` is internal-only and exposed only
12*6dbdd20aSAndroid Build Coastguard Worker  for Chromium.
13*6dbdd20aSAndroid Build Coastguard Worker* A new C API/ABI for a tracing shared library is in the works in
14*6dbdd20aSAndroid Build Coastguard Worker  `include/perfetto/public`. It is not stable yet.
15*6dbdd20aSAndroid Build Coastguard Worker* The tracing protocol ABI is based on protobuf-over-UNIX-socket and shared
16*6dbdd20aSAndroid Build Coastguard Worker  memory. It is long-term stable and maintains compatibility in both directions
17*6dbdd20aSAndroid Build Coastguard Worker  (old service + newer client and vice-versa).
18*6dbdd20aSAndroid Build Coastguard Worker* The [DataSourceDescriptor][data_source_descriptor.proto],
19*6dbdd20aSAndroid Build Coastguard Worker  [DataSourceConfig][data_source_config.proto] and
20*6dbdd20aSAndroid Build Coastguard Worker  [TracePacket][trace-packet-ref] protos are updated maintaining backwards
21*6dbdd20aSAndroid Build Coastguard Worker  compatibility unless a message is marked as experimental. Trace Processor
22*6dbdd20aSAndroid Build Coastguard Worker  deals with importing older trace formats.
23*6dbdd20aSAndroid Build Coastguard Worker* There isn't a version number neither in the trace file nor in the tracing
24*6dbdd20aSAndroid Build Coastguard Worker  protocol and there will never be one. Feature flags are used when necessary.
25*6dbdd20aSAndroid Build Coastguard Worker
26*6dbdd20aSAndroid Build Coastguard Worker## C++ API
27*6dbdd20aSAndroid Build Coastguard Worker
28*6dbdd20aSAndroid Build Coastguard WorkerThe Client Library C++ API allows an app to contribute to the trace with custom
29*6dbdd20aSAndroid Build Coastguard Workertrace events. Its headers live under [`include/perfetto/`](/include/perfetto).
30*6dbdd20aSAndroid Build Coastguard Worker
31*6dbdd20aSAndroid Build Coastguard WorkerThere are three different tiers of this API, offering increasingly higher
32*6dbdd20aSAndroid Build Coastguard Workerexpressive power, at the cost of increased complexity. The three tiers are built
33*6dbdd20aSAndroid Build Coastguard Workeron top of each other. (Googlers, for more details see also
34*6dbdd20aSAndroid Build Coastguard Worker[go/perfetto-client-api](http://go/perfetto-client-api)).
35*6dbdd20aSAndroid Build Coastguard Worker
36*6dbdd20aSAndroid Build Coastguard Worker![C++ API](/docs/images/api-and-abi.png)
37*6dbdd20aSAndroid Build Coastguard Worker
38*6dbdd20aSAndroid Build Coastguard Worker### Track Event (public)
39*6dbdd20aSAndroid Build Coastguard Worker
40*6dbdd20aSAndroid Build Coastguard WorkerThis mainly consists of the `TRACE_EVENT*` macros defined in
41*6dbdd20aSAndroid Build Coastguard Worker[`track_event.h`](/include/perfetto/tracing/track_event.h).
42*6dbdd20aSAndroid Build Coastguard WorkerThose macros provide apps with a quick and easy way to add common types of
43*6dbdd20aSAndroid Build Coastguard Workerinstrumentation points (slices, counters, instant events).
44*6dbdd20aSAndroid Build Coastguard WorkerFor details and instructions see the [Client Library doc][cli_lib].
45*6dbdd20aSAndroid Build Coastguard Worker
46*6dbdd20aSAndroid Build Coastguard Worker### Custom Data Sources (public)
47*6dbdd20aSAndroid Build Coastguard Worker
48*6dbdd20aSAndroid Build Coastguard WorkerThis consists of the `perfetto::DataSource` base class and the
49*6dbdd20aSAndroid Build Coastguard Worker`perfetto::Tracing` controller class defined in
50*6dbdd20aSAndroid Build Coastguard Worker[`tracing.h`](/include/perfetto/tracing.h).
51*6dbdd20aSAndroid Build Coastguard WorkerThese classes allow an app to create custom data sources which can get
52*6dbdd20aSAndroid Build Coastguard Workernotifications about tracing sessions lifecycle and emit custom protos in the
53*6dbdd20aSAndroid Build Coastguard Workertrace (e.g. memory snapshots, compositor layers, etc).
54*6dbdd20aSAndroid Build Coastguard Worker
55*6dbdd20aSAndroid Build Coastguard WorkerFor details and instructions see the [Client Library doc][cli_lib].
56*6dbdd20aSAndroid Build Coastguard Worker
57*6dbdd20aSAndroid Build Coastguard WorkerBoth the Track Event API and the custom data source are meant to be a public
58*6dbdd20aSAndroid Build Coastguard WorkerAPI.
59*6dbdd20aSAndroid Build Coastguard Worker
60*6dbdd20aSAndroid Build Coastguard WorkerWARNING: The team is still iterating on this API surface. While we try to avoid
61*6dbdd20aSAndroid Build Coastguard Worker         deliberate breakages, some occasional compile-time breakages might be
62*6dbdd20aSAndroid Build Coastguard Worker         encountered when updating the library. The interface is expected to
63*6dbdd20aSAndroid Build Coastguard Worker         stabilize by the end of 2020.
64*6dbdd20aSAndroid Build Coastguard Worker
65*6dbdd20aSAndroid Build Coastguard Worker### Producer / Consumer API (internal)
66*6dbdd20aSAndroid Build Coastguard Worker
67*6dbdd20aSAndroid Build Coastguard WorkerThis consists of all the interfaces defined in the
68*6dbdd20aSAndroid Build Coastguard Worker[`include/perfetto/ext`](/include/perfetto/ext) directory. These provide access
69*6dbdd20aSAndroid Build Coastguard Workerto the lowest levels of the Perfetto internals (manually registering producers
70*6dbdd20aSAndroid Build Coastguard Workerand data sources, handling all IPCs).
71*6dbdd20aSAndroid Build Coastguard Worker
72*6dbdd20aSAndroid Build Coastguard WorkerThese interfaces will always be highly unstable. We highly discourage
73*6dbdd20aSAndroid Build Coastguard Workerany project from depending on this API because it is too complex and extremely
74*6dbdd20aSAndroid Build Coastguard Workerhard to get right.
75*6dbdd20aSAndroid Build Coastguard WorkerThis API surface exists only for the Chromium project, which has unique
76*6dbdd20aSAndroid Build Coastguard Workerchallenges (e.g., its own IPC system, complex sandboxing models) and has dozens
77*6dbdd20aSAndroid Build Coastguard Workerof subtle use cases accumulated through over ten years of legacy of
78*6dbdd20aSAndroid Build Coastguard Workerchrome://tracing. The team is continuously reshaping this surface to gradually
79*6dbdd20aSAndroid Build Coastguard Workermigrate all Chrome Tracing use cases over to Perfetto.
80*6dbdd20aSAndroid Build Coastguard Worker
81*6dbdd20aSAndroid Build Coastguard Worker## Tracing Protocol ABI
82*6dbdd20aSAndroid Build Coastguard Worker
83*6dbdd20aSAndroid Build Coastguard WorkerThe Tracing Protocol ABI consists of the following binary interfaces that allow
84*6dbdd20aSAndroid Build Coastguard Workervarious processes in the operating system to contribute to tracing sessions and
85*6dbdd20aSAndroid Build Coastguard Workerinject tracing data into the tracing service:
86*6dbdd20aSAndroid Build Coastguard Worker
87*6dbdd20aSAndroid Build Coastguard Worker * [Socket protocol](#socket-protocol)
88*6dbdd20aSAndroid Build Coastguard Worker * [Shared memory layout](#shmem-abi)
89*6dbdd20aSAndroid Build Coastguard Worker * [Protobuf messages](#protos)
90*6dbdd20aSAndroid Build Coastguard Worker
91*6dbdd20aSAndroid Build Coastguard WorkerThe whole tracing protocol ABI is binary stable across platforms and is updated
92*6dbdd20aSAndroid Build Coastguard Workermaintaining both backwards and forward compatibility. No breaking changes
93*6dbdd20aSAndroid Build Coastguard Workerhave been introduced since its first revision in Android 9 (Pie, 2018).
94*6dbdd20aSAndroid Build Coastguard WorkerSee also the [ABI Stability](#abi-stability) section below.
95*6dbdd20aSAndroid Build Coastguard Worker
96*6dbdd20aSAndroid Build Coastguard Worker![Tracing protocol](/docs/images/tracing-protocol.png)
97*6dbdd20aSAndroid Build Coastguard Worker
98*6dbdd20aSAndroid Build Coastguard Worker### {#socket-protocol} Socket protocol
99*6dbdd20aSAndroid Build Coastguard Worker
100*6dbdd20aSAndroid Build Coastguard WorkerAt the lowest level, the tracing protocol is initiated with a UNIX socket of
101*6dbdd20aSAndroid Build Coastguard Workertype `SOCK_STREAM` to the tracing service.
102*6dbdd20aSAndroid Build Coastguard WorkerThe tracing service listens on two distinct sockets: producer and consumer.
103*6dbdd20aSAndroid Build Coastguard Worker
104*6dbdd20aSAndroid Build Coastguard Worker![Socket protocol](/docs/images/socket-protocol.png)
105*6dbdd20aSAndroid Build Coastguard Worker
106*6dbdd20aSAndroid Build Coastguard WorkerBoth sockets use the same wire protocol, the `IPCFrame` message defined in
107*6dbdd20aSAndroid Build Coastguard Worker[wire_protocol.proto](/protos/perfetto/ipc/wire_protocol.proto). The wire
108*6dbdd20aSAndroid Build Coastguard Workerprotocol is simply based on a sequence of length-prefixed messages of the form:
109*6dbdd20aSAndroid Build Coastguard Worker```
110*6dbdd20aSAndroid Build Coastguard Worker< 4 bytes len little-endian > < proto-encoded IPCFrame >
111*6dbdd20aSAndroid Build Coastguard Worker
112*6dbdd20aSAndroid Build Coastguard Worker04 00 00 00 A0 A1 A2 A3   05 00 00 00 B0 B1 B2 B3 B4  ...
113*6dbdd20aSAndroid Build Coastguard Worker{ len: 4  } [ Frame 1 ]   { len: 5  } [   Frame 2  ]
114*6dbdd20aSAndroid Build Coastguard Worker```
115*6dbdd20aSAndroid Build Coastguard Worker
116*6dbdd20aSAndroid Build Coastguard WorkerThe `IPCFrame` proto message defines a request/response protocol that is
117*6dbdd20aSAndroid Build Coastguard Workercompatible with the [protobuf services syntax][proto_rpc]. `IPCFrame` defines
118*6dbdd20aSAndroid Build Coastguard Workerthe following frame types:
119*6dbdd20aSAndroid Build Coastguard Worker
120*6dbdd20aSAndroid Build Coastguard Worker1. `BindService   {producer, consumer} -> service`<br>
121*6dbdd20aSAndroid Build Coastguard Worker    Binds to one of the two service ports (either `producer_port` or
122*6dbdd20aSAndroid Build Coastguard Worker    `consumer_port`).
123*6dbdd20aSAndroid Build Coastguard Worker
124*6dbdd20aSAndroid Build Coastguard Worker2. `BindServiceReply  service -> {producer, consumer}`<br>
125*6dbdd20aSAndroid Build Coastguard Worker    Replies to the bind request, listing all the RPC methods available, together
126*6dbdd20aSAndroid Build Coastguard Worker    with their method ID.
127*6dbdd20aSAndroid Build Coastguard Worker
128*6dbdd20aSAndroid Build Coastguard Worker3. `InvokeMethod   {producer, consumer} -> service`<br>
129*6dbdd20aSAndroid Build Coastguard Worker    Invokes a RPC method, identified by the ID returned by `BindServiceReply`.
130*6dbdd20aSAndroid Build Coastguard Worker    The invocation takes as unique argument a proto sub-message. Each method
131*6dbdd20aSAndroid Build Coastguard Worker    defines a pair of _request_ and _response_ method types.<br>
132*6dbdd20aSAndroid Build Coastguard Worker    For instance the `RegisterDataSource` defined in [producer_port.proto] takes
133*6dbdd20aSAndroid Build Coastguard Worker    a `perfetto.protos.RegisterDataSourceRequest` and returns a
134*6dbdd20aSAndroid Build Coastguard Worker    `perfetto.protos.RegisterDataSourceResponse`.
135*6dbdd20aSAndroid Build Coastguard Worker
136*6dbdd20aSAndroid Build Coastguard Worker4. `InvokeMethodReply  service -> {producer, consumer}`<br>
137*6dbdd20aSAndroid Build Coastguard Worker    Returns the result of the corresponding invocation or an error flag.
138*6dbdd20aSAndroid Build Coastguard Worker    If a method return signature is marked as `stream` (e.g.
139*6dbdd20aSAndroid Build Coastguard Worker    `returns (stream GetAsyncCommandResponse)`), the method invocation can be
140*6dbdd20aSAndroid Build Coastguard Worker    followed by more than one `InvokeMethodReply`, all with the same
141*6dbdd20aSAndroid Build Coastguard Worker    `request_id`. All replies in the stream except for the last one will have
142*6dbdd20aSAndroid Build Coastguard Worker    `has_more: true`, to notify the client more responses for the same invocation
143*6dbdd20aSAndroid Build Coastguard Worker    will follow.
144*6dbdd20aSAndroid Build Coastguard Worker
145*6dbdd20aSAndroid Build Coastguard WorkerHere is how the traffic over the IPC socket looks like:
146*6dbdd20aSAndroid Build Coastguard Worker
147*6dbdd20aSAndroid Build Coastguard Worker```
148*6dbdd20aSAndroid Build Coastguard Worker# [Prd > Svc] Bind request for the remote service named "producer_port"
149*6dbdd20aSAndroid Build Coastguard Workerrequest_id: 1
150*6dbdd20aSAndroid Build Coastguard Workermsg_bind_service { service_name: "producer_port" }
151*6dbdd20aSAndroid Build Coastguard Worker
152*6dbdd20aSAndroid Build Coastguard Worker# [Svc > Prd] Service reply.
153*6dbdd20aSAndroid Build Coastguard Workerrequest_id: 1
154*6dbdd20aSAndroid Build Coastguard Workermsg_bind_service_reply: {
155*6dbdd20aSAndroid Build Coastguard Worker  success:    true
156*6dbdd20aSAndroid Build Coastguard Worker  service_id: 42
157*6dbdd20aSAndroid Build Coastguard Worker  methods:    {id: 2; name: "InitializeConnection" }
158*6dbdd20aSAndroid Build Coastguard Worker  methods:    {id: 5; name: "RegisterDataSource" }
159*6dbdd20aSAndroid Build Coastguard Worker  methods:    {id: 3; name: "UnregisterDataSource" }
160*6dbdd20aSAndroid Build Coastguard Worker  ...
161*6dbdd20aSAndroid Build Coastguard Worker}
162*6dbdd20aSAndroid Build Coastguard Worker
163*6dbdd20aSAndroid Build Coastguard Worker# [Prd > Svc] Method invocation (RegisterDataSource)
164*6dbdd20aSAndroid Build Coastguard Workerrequest_id: 2
165*6dbdd20aSAndroid Build Coastguard Workermsg_invoke_method: {
166*6dbdd20aSAndroid Build Coastguard Worker  service_id: 42  # "producer_port"
167*6dbdd20aSAndroid Build Coastguard Worker  method_id:  5   # "RegisterDataSource"
168*6dbdd20aSAndroid Build Coastguard Worker
169*6dbdd20aSAndroid Build Coastguard Worker  # Proto-encoded bytes for the RegisterDataSourceRequest message.
170*6dbdd20aSAndroid Build Coastguard Worker  args_proto: [XX XX XX XX]
171*6dbdd20aSAndroid Build Coastguard Worker}
172*6dbdd20aSAndroid Build Coastguard Worker
173*6dbdd20aSAndroid Build Coastguard Worker# [Svc > Prd] Result of RegisterDataSource method invocation.
174*6dbdd20aSAndroid Build Coastguard Workerrequest_id: 2
175*6dbdd20aSAndroid Build Coastguard Workermsg_invoke_method_reply: {
176*6dbdd20aSAndroid Build Coastguard Worker  success:     true
177*6dbdd20aSAndroid Build Coastguard Worker  has_more:    false  # EOF for this request
178*6dbdd20aSAndroid Build Coastguard Worker
179*6dbdd20aSAndroid Build Coastguard Worker  # Proto-encoded bytes for the RegisterDataSourceResponse message.
180*6dbdd20aSAndroid Build Coastguard Worker  reply_proto: [XX XX XX XX]
181*6dbdd20aSAndroid Build Coastguard Worker}
182*6dbdd20aSAndroid Build Coastguard Worker```
183*6dbdd20aSAndroid Build Coastguard Worker
184*6dbdd20aSAndroid Build Coastguard Worker#### Producer socket
185*6dbdd20aSAndroid Build Coastguard Worker
186*6dbdd20aSAndroid Build Coastguard WorkerThe producer socket exposes the RPC interface defined in [producer_port.proto].
187*6dbdd20aSAndroid Build Coastguard WorkerIt allows processes to advertise data sources and their capabilities, receive
188*6dbdd20aSAndroid Build Coastguard Workernotifications about the tracing session lifecycle (trace being started, stopped)
189*6dbdd20aSAndroid Build Coastguard Workerand signal trace data commits and flush requests.
190*6dbdd20aSAndroid Build Coastguard Worker
191*6dbdd20aSAndroid Build Coastguard WorkerThis socket is also used by the producer and the service to exchange a
192*6dbdd20aSAndroid Build Coastguard Workertmpfs file descriptor during initialization for setting up the
193*6dbdd20aSAndroid Build Coastguard Worker[shared memory buffer](/docs/concepts/buffers.md) where tracing data will be
194*6dbdd20aSAndroid Build Coastguard Workerwritten (asynchronously).
195*6dbdd20aSAndroid Build Coastguard Worker
196*6dbdd20aSAndroid Build Coastguard WorkerOn Android this socket is linked at `/dev/socket/traced_producer`. On all
197*6dbdd20aSAndroid Build Coastguard Workerplatforms it is overridable via the `PERFETTO_PRODUCER_SOCK_NAME` env var.
198*6dbdd20aSAndroid Build Coastguard Worker
199*6dbdd20aSAndroid Build Coastguard WorkerOn Android all apps and most system processes can connect to it
200*6dbdd20aSAndroid Build Coastguard Worker(see [`perfetto_producer` in SELinux policies][selinux_producer]).
201*6dbdd20aSAndroid Build Coastguard Worker
202*6dbdd20aSAndroid Build Coastguard WorkerIn the Perfetto codebase, the [`traced_probes`](/src/traced/probes/) and
203*6dbdd20aSAndroid Build Coastguard Worker[`heapprofd`](/src/profiling/memory) processes use the producer socket for
204*6dbdd20aSAndroid Build Coastguard Workerinjecting system-wide tracing / profiling data.
205*6dbdd20aSAndroid Build Coastguard Worker
206*6dbdd20aSAndroid Build Coastguard Worker#### Consumer socket
207*6dbdd20aSAndroid Build Coastguard Worker
208*6dbdd20aSAndroid Build Coastguard WorkerThe consumer socket exposes the RPC interface defined in [consumer_port.proto].
209*6dbdd20aSAndroid Build Coastguard WorkerThe consumer socket allows processes to control tracing sessions (start / stop
210*6dbdd20aSAndroid Build Coastguard Workertracing) and read back trace data.
211*6dbdd20aSAndroid Build Coastguard Worker
212*6dbdd20aSAndroid Build Coastguard WorkerOn Android this socket is linked at `/dev/socket/traced_consumer`. On all
213*6dbdd20aSAndroid Build Coastguard Workerplatforms it is overridable via the `PERFETTO_CONSUMER_SOCK_NAME` env var.
214*6dbdd20aSAndroid Build Coastguard Worker
215*6dbdd20aSAndroid Build Coastguard WorkerTrace data contains sensitive information that discloses the activity the
216*6dbdd20aSAndroid Build Coastguard Workersystem (e.g., which processes / threads are running) and can allow side-channel
217*6dbdd20aSAndroid Build Coastguard Workerattacks. For this reason the consumer socket is intended to be exposed only to
218*6dbdd20aSAndroid Build Coastguard Workera few privileged processes.
219*6dbdd20aSAndroid Build Coastguard Worker
220*6dbdd20aSAndroid Build Coastguard WorkerOn Android, only the `adb shell` domain (used by various UI tools like
221*6dbdd20aSAndroid Build Coastguard Worker[Perfetto UI](https://ui.perfetto.dev/),
222*6dbdd20aSAndroid Build Coastguard Worker[Android Studio](https://developer.android.com/studio) or the
223*6dbdd20aSAndroid Build Coastguard Worker[Android GPU Inspector](https://github.com/google/agi))
224*6dbdd20aSAndroid Build Coastguard Workerand few other trusted system services are allowed to access the consumer socket
225*6dbdd20aSAndroid Build Coastguard Worker(see [traced_consumer in SELinux][selinux_consumer]).
226*6dbdd20aSAndroid Build Coastguard Worker
227*6dbdd20aSAndroid Build Coastguard WorkerIn the Perfetto codebase, the [`perfetto`](/docs/reference/perfetto-cli)
228*6dbdd20aSAndroid Build Coastguard Workerbinary (`/system/bin/perfetto` on Android) provides a consumer implementation
229*6dbdd20aSAndroid Build Coastguard Workerand exposes it through a command line interface.
230*6dbdd20aSAndroid Build Coastguard Worker
231*6dbdd20aSAndroid Build Coastguard Worker#### Socket protocol FAQs
232*6dbdd20aSAndroid Build Coastguard Worker
233*6dbdd20aSAndroid Build Coastguard Worker_Why SOCK_STREAM and not DGRAM/SEQPACKET?_
234*6dbdd20aSAndroid Build Coastguard Worker
235*6dbdd20aSAndroid Build Coastguard Worker1. To allow direct passthrough of the consumer socket on Android through
236*6dbdd20aSAndroid Build Coastguard Worker   `adb forward localabstract` and allow host tools to directly talk to the
237*6dbdd20aSAndroid Build Coastguard Worker   on-device tracing service. Today both the Perfetto UI and Android GPU
238*6dbdd20aSAndroid Build Coastguard Worker   Inspector do this.
239*6dbdd20aSAndroid Build Coastguard Worker2. To allow in future to directly control a remote service over TCP or SSH
240*6dbdd20aSAndroid Build Coastguard Worker   tunneling.
241*6dbdd20aSAndroid Build Coastguard Worker3. Because the socket buffer for `SOCK_DGRAM` is extremely limited and
242*6dbdd20aSAndroid Build Coastguard Worker   and `SOCK_SEQPACKET` is not supported on MacOS.
243*6dbdd20aSAndroid Build Coastguard Worker
244*6dbdd20aSAndroid Build Coastguard Worker_Why not gRPC?_
245*6dbdd20aSAndroid Build Coastguard Worker
246*6dbdd20aSAndroid Build Coastguard WorkerThe team evaluated gRPC in late 2017 as an alternative but ruled it out
247*6dbdd20aSAndroid Build Coastguard Workerdue to: (i) binary size and memory footprint; (ii) the complexity and overhead
248*6dbdd20aSAndroid Build Coastguard Workerof running a full HTTP/2 stack over a UNIX socket; (iii) the lack of
249*6dbdd20aSAndroid Build Coastguard Workerfine-grained control on back-pressure.
250*6dbdd20aSAndroid Build Coastguard Worker
251*6dbdd20aSAndroid Build Coastguard Worker_Is the UNIX socket protocol used within Chrome processes?_
252*6dbdd20aSAndroid Build Coastguard Worker
253*6dbdd20aSAndroid Build Coastguard WorkerNo. Within Chrome processes (the browser app, not CrOS) Perfetto doesn't use
254*6dbdd20aSAndroid Build Coastguard Workerany doesn't use any unix socket. Instead it uses the functionally equivalent
255*6dbdd20aSAndroid Build Coastguard WorkerMojo endpoints [`Producer{Client,Host}` and `Consumer{Client,Host}`][mojom].
256*6dbdd20aSAndroid Build Coastguard Worker
257*6dbdd20aSAndroid Build Coastguard Worker### {#shmem-abi} Shared memory
258*6dbdd20aSAndroid Build Coastguard Worker
259*6dbdd20aSAndroid Build Coastguard WorkerThis section describes the binary interface of the memory buffer shared between
260*6dbdd20aSAndroid Build Coastguard Workera producer process and the tracing service (SMB).
261*6dbdd20aSAndroid Build Coastguard Worker
262*6dbdd20aSAndroid Build Coastguard WorkerThe SMB is a staging area to decouple data sources living in the Producer
263*6dbdd20aSAndroid Build Coastguard Workerand allow them to do non-blocking async writes. A SMB is small-ish, typically
264*6dbdd20aSAndroid Build Coastguard Workerhundreds of KB. Its size is configurable by the producer when connecting.
265*6dbdd20aSAndroid Build Coastguard WorkerFor more architectural details about the SMB see also the
266*6dbdd20aSAndroid Build Coastguard Worker[buffers and dataflow doc](/docs/concepts/buffers.md) and the
267*6dbdd20aSAndroid Build Coastguard Worker[shared_memory_abi.h] sources.
268*6dbdd20aSAndroid Build Coastguard Worker
269*6dbdd20aSAndroid Build Coastguard Worker#### Obtaining the SMB
270*6dbdd20aSAndroid Build Coastguard Worker
271*6dbdd20aSAndroid Build Coastguard WorkerThe SMB is obtained by passing a tmpfs file descriptor over the producer socket
272*6dbdd20aSAndroid Build Coastguard Workerand memory-mapping it both from the producer and service.
273*6dbdd20aSAndroid Build Coastguard WorkerThe producer specifies the desired SMB size and memory layout when sending the
274*6dbdd20aSAndroid Build Coastguard Worker[`InitializeConnectionRequest`][producer_port.proto] request to the
275*6dbdd20aSAndroid Build Coastguard Workerservice, which is the very first IPC sent after connection.
276*6dbdd20aSAndroid Build Coastguard WorkerBy default, the service creates the SMB and passes back its file descriptor to
277*6dbdd20aSAndroid Build Coastguard Workerthe producer with the [`InitializeConnectionResponse`][producer_port.proto]
278*6dbdd20aSAndroid Build Coastguard WorkerIPC reply. Recent versions of the service (Android R / 11) allow the FD to be
279*6dbdd20aSAndroid Build Coastguard Workercreated by the producer and passed down to the service in the request. When the
280*6dbdd20aSAndroid Build Coastguard Workerservice supports this, it acks the request setting
281*6dbdd20aSAndroid Build Coastguard Worker`InitializeConnectionResponse.using_shmem_provided_by_producer = true`. At the
282*6dbdd20aSAndroid Build Coastguard Workertime of writing this feature is used only by Chrome for dealing with lazy
283*6dbdd20aSAndroid Build Coastguard WorkerMojo initialization during startup tracing.
284*6dbdd20aSAndroid Build Coastguard Worker
285*6dbdd20aSAndroid Build Coastguard Worker#### SMB memory layout: pages, chunks, fragments and packets
286*6dbdd20aSAndroid Build Coastguard Worker
287*6dbdd20aSAndroid Build Coastguard WorkerThe SMB is partitioned into fixed-size pages. A SMB page must be an integer
288*6dbdd20aSAndroid Build Coastguard Workermultiple of 4KB. The only valid sizes are: 4KB, 8KB, 16KB, 32KB.
289*6dbdd20aSAndroid Build Coastguard Worker
290*6dbdd20aSAndroid Build Coastguard WorkerThe size of a SMB page is determined by each Producer at connection time, via
291*6dbdd20aSAndroid Build Coastguard Workerthe `shared_memory_page_size_hint_bytes` field of `InitializeConnectionRequest`
292*6dbdd20aSAndroid Build Coastguard Workerand cannot be changed afterwards. All pages in the SMB have the same size,
293*6dbdd20aSAndroid Build Coastguard Workerconstant throughout the lifetime of the producer process.
294*6dbdd20aSAndroid Build Coastguard Worker
295*6dbdd20aSAndroid Build Coastguard Worker![Shared Memory ABI Overview](/docs/images/shmem-abi-overview.png)
296*6dbdd20aSAndroid Build Coastguard Worker
297*6dbdd20aSAndroid Build Coastguard Worker**A page** is a fixed-sized partition of the shared memory buffer and is just a
298*6dbdd20aSAndroid Build Coastguard Workercontainer of chunks.
299*6dbdd20aSAndroid Build Coastguard WorkerThe Producer can partition each Page SMB using a limited number of predetermined
300*6dbdd20aSAndroid Build Coastguard Workerlayouts (1 page : 1 chunk; 1 page : 2 chunks and so on).
301*6dbdd20aSAndroid Build Coastguard WorkerThe page layout is stored in a 32-bit atomic word in the page header. The same
302*6dbdd20aSAndroid Build Coastguard Worker32-bit word contains also the state of each chunk (2 bits per chunk).
303*6dbdd20aSAndroid Build Coastguard Worker
304*6dbdd20aSAndroid Build Coastguard WorkerHaving fixed the total SMB size (hence the total memory overhead), the page
305*6dbdd20aSAndroid Build Coastguard Workersize is a triangular trade off between:
306*6dbdd20aSAndroid Build Coastguard Worker
307*6dbdd20aSAndroid Build Coastguard Worker1. IPC traffic: smaller pages -> more IPCs.
308*6dbdd20aSAndroid Build Coastguard Worker2. Producer lock freedom: larger pages -> larger chunks -> data sources can
309*6dbdd20aSAndroid Build Coastguard Worker   write more data without needing to swap chunks and synchronize.
310*6dbdd20aSAndroid Build Coastguard Worker3. Risk of write-starving the SMB: larger pages -> higher chance that the
311*6dbdd20aSAndroid Build Coastguard Worker   Service won't manage to drain them and the SMB remains full.
312*6dbdd20aSAndroid Build Coastguard Worker
313*6dbdd20aSAndroid Build Coastguard WorkerThe page size, on the other side, has no implications on memory wasted due to
314*6dbdd20aSAndroid Build Coastguard Workerfragmentation (see Chunk below).
315*6dbdd20aSAndroid Build Coastguard Worker
316*6dbdd20aSAndroid Build Coastguard Worker**A chunk** A chunk is a portion of a Page and contains a linear sequence of
317*6dbdd20aSAndroid Build Coastguard Worker[`TracePacket(s)`][trace-packet-ref] (the root trace proto).
318*6dbdd20aSAndroid Build Coastguard Worker
319*6dbdd20aSAndroid Build Coastguard WorkerA Chunk defines the granularity of the interaction between the Producer and
320*6dbdd20aSAndroid Build Coastguard Workertracing Service. When a producer fills a chunk it sends `CommitData` IPC to the
321*6dbdd20aSAndroid Build Coastguard Workerservice, asking it to copy its contents into the central non-shared buffers.
322*6dbdd20aSAndroid Build Coastguard Worker
323*6dbdd20aSAndroid Build Coastguard WorkerA a chunk can be in one of the following four states:
324*6dbdd20aSAndroid Build Coastguard Worker
325*6dbdd20aSAndroid Build Coastguard Worker* `Free` : The Chunk is free. The Service shall never touch it, the Producer
326*6dbdd20aSAndroid Build Coastguard Worker   can acquire it when writing and transition it into the `BeingWritten` state.
327*6dbdd20aSAndroid Build Coastguard Worker
328*6dbdd20aSAndroid Build Coastguard Worker* `BeingWritten`: The Chunk is being written by the Producer and is not
329*6dbdd20aSAndroid Build Coastguard Worker    complete yet (i.e. there is still room to write other trace packets).
330*6dbdd20aSAndroid Build Coastguard Worker    The Service never alter the state of chunks in the `BeingWritten` state
331*6dbdd20aSAndroid Build Coastguard Worker    (but will still read them when flushing even if incomplete).
332*6dbdd20aSAndroid Build Coastguard Worker
333*6dbdd20aSAndroid Build Coastguard Worker* `Complete`: The Producer is done writing the chunk and won't touch it
334*6dbdd20aSAndroid Build Coastguard Worker  again. The Service can move it to its non-shared ring buffer and mark the
335*6dbdd20aSAndroid Build Coastguard Worker  chunk as `BeingRead` -> `Free` when done.
336*6dbdd20aSAndroid Build Coastguard Worker
337*6dbdd20aSAndroid Build Coastguard Worker* `BeingRead`: The Service is moving the page into its non-shared ring
338*6dbdd20aSAndroid Build Coastguard Worker  buffer. Producers never touch chunks in this state.
339*6dbdd20aSAndroid Build Coastguard Worker  _Note: this state ended up being never used as the service directly
340*6dbdd20aSAndroid Build Coastguard Worker   transitions chunks from `Complete` back to `Free`_.
341*6dbdd20aSAndroid Build Coastguard Worker
342*6dbdd20aSAndroid Build Coastguard WorkerA chunk is owned exclusively by one thread of one data source of the producer.
343*6dbdd20aSAndroid Build Coastguard Worker
344*6dbdd20aSAndroid Build Coastguard WorkerChunks are essentially single-writer single-thread lock-free arenas. Locking
345*6dbdd20aSAndroid Build Coastguard Workerhappens only when a Chunk is full and a new one needs to be acquired.
346*6dbdd20aSAndroid Build Coastguard Worker
347*6dbdd20aSAndroid Build Coastguard WorkerLocking happens only within the scope of a Producer process.
348*6dbdd20aSAndroid Build Coastguard WorkerInter-process locking is not generally allowed. The Producer cannot lock the
349*6dbdd20aSAndroid Build Coastguard WorkerService and vice versa. In the worst case, any of the two can starve the SMB, by
350*6dbdd20aSAndroid Build Coastguard Workermarking all chunks as either being read or written. But that has the only side
351*6dbdd20aSAndroid Build Coastguard Workereffect of losing the trace data.
352*6dbdd20aSAndroid Build Coastguard WorkerThe only case when stalling on the writer-side (the Producer) can occur is when
353*6dbdd20aSAndroid Build Coastguard Workera data source in a producer opts in into using the
354*6dbdd20aSAndroid Build Coastguard Worker[`BufferExhaustedPolicy.kStall`](/docs/concepts/buffers.md) policy and the SMB
355*6dbdd20aSAndroid Build Coastguard Workeris full.
356*6dbdd20aSAndroid Build Coastguard Worker
357*6dbdd20aSAndroid Build Coastguard Worker**[TracePacket][trace-packet-ref]** is the atom of tracing. Putting aside
358*6dbdd20aSAndroid Build Coastguard Workerpages and chunks a trace is conceptually just a concatenation of TracePacket(s).
359*6dbdd20aSAndroid Build Coastguard WorkerA TracePacket can be big (up to 64 MB) and can span across several chunks, hence
360*6dbdd20aSAndroid Build Coastguard Workeracross several pages.
361*6dbdd20aSAndroid Build Coastguard WorkerA TracePacket can therefore be >> chunk size, >> page size and even >> SMB size.
362*6dbdd20aSAndroid Build Coastguard WorkerThe Chunk header carries metadata to deal with the TracePacket splitting.
363*6dbdd20aSAndroid Build Coastguard Worker
364*6dbdd20aSAndroid Build Coastguard WorkerOverview of the Page, Chunk, Fragment and Packet concepts:<br>
365*6dbdd20aSAndroid Build Coastguard Worker![Shared Memory ABI concepts](/docs/images/shmem-abi-concepts.png)
366*6dbdd20aSAndroid Build Coastguard Worker
367*6dbdd20aSAndroid Build Coastguard WorkerMemory layout of a Page:<br>
368*6dbdd20aSAndroid Build Coastguard Worker![SMB Page layout](/docs/images/shmem-abi-page.png)
369*6dbdd20aSAndroid Build Coastguard Worker
370*6dbdd20aSAndroid Build Coastguard WorkerBecause a packet can be larger than a page, the first and the last packets in
371*6dbdd20aSAndroid Build Coastguard Workera chunk can be fragments.
372*6dbdd20aSAndroid Build Coastguard Worker
373*6dbdd20aSAndroid Build Coastguard Worker![TracePacket spanning across SMB chunks](/docs/images/shmem-abi-spans.png)
374*6dbdd20aSAndroid Build Coastguard Worker
375*6dbdd20aSAndroid Build Coastguard Worker#### Post-facto patching through IPC
376*6dbdd20aSAndroid Build Coastguard Worker
377*6dbdd20aSAndroid Build Coastguard WorkerIf a TracePacket is particularly large, it is very likely that the chunk that
378*6dbdd20aSAndroid Build Coastguard Workercontains its initial fragments is committed into the central buffers and removed
379*6dbdd20aSAndroid Build Coastguard Workerfrom the SMB by the time the last fragments of the same packets is written.
380*6dbdd20aSAndroid Build Coastguard Worker
381*6dbdd20aSAndroid Build Coastguard WorkerNested messages in protobuf are prefixed by their length. In a zero-copy
382*6dbdd20aSAndroid Build Coastguard Workerdirect-serialization scenario like tracing, the length is known only when the
383*6dbdd20aSAndroid Build Coastguard Workerlast field of a submessage is written and cannot be known upfront.
384*6dbdd20aSAndroid Build Coastguard Worker
385*6dbdd20aSAndroid Build Coastguard WorkerBecause of this, it is possible that when the last fragment of a packet is
386*6dbdd20aSAndroid Build Coastguard Workerwritten, the writer needs to backfill the size prefix in an earlier fragment,
387*6dbdd20aSAndroid Build Coastguard Workerwhich now might have disappeared from the SMB.
388*6dbdd20aSAndroid Build Coastguard Worker
389*6dbdd20aSAndroid Build Coastguard WorkerIn order to do this, the tracing protocol allows to patch the contents of a
390*6dbdd20aSAndroid Build Coastguard Workerchunk through the `CommitData` IPC (see
391*6dbdd20aSAndroid Build Coastguard Worker[`CommitDataRequest.ChunkToPatch`][commit_data_request.proto]) after the tracing
392*6dbdd20aSAndroid Build Coastguard Workerservice copied it into the central buffer. There is no guarantee that the
393*6dbdd20aSAndroid Build Coastguard Workerfragment will be still there (e.g., it can be over-written in ring-buffer mode).
394*6dbdd20aSAndroid Build Coastguard WorkerThe service will patch the chunk only if it's still in the buffer and only if
395*6dbdd20aSAndroid Build Coastguard Workerthe producer ID that wrote it matches the Producer ID of the patch request over
396*6dbdd20aSAndroid Build Coastguard WorkerIPC (the Producer ID is not spoofable and is tied to the IPC socket file
397*6dbdd20aSAndroid Build Coastguard Workerdescriptor).
398*6dbdd20aSAndroid Build Coastguard Worker
399*6dbdd20aSAndroid Build Coastguard Worker### {#protos} Proto definitions
400*6dbdd20aSAndroid Build Coastguard Worker
401*6dbdd20aSAndroid Build Coastguard WorkerThe following protobuf messages are part of the overall trace protocol ABI and
402*6dbdd20aSAndroid Build Coastguard Workerare updated maintaining backward-compatibility, unless marked as experimental
403*6dbdd20aSAndroid Build Coastguard Workerin the comments.
404*6dbdd20aSAndroid Build Coastguard Worker
405*6dbdd20aSAndroid Build Coastguard WorkerTIP: See also the _Updating A Message Type_ section of the
406*6dbdd20aSAndroid Build Coastguard Worker    [Protobuf Language Guide][proto-updating] for valid ABI-compatible changes
407*6dbdd20aSAndroid Build Coastguard Worker    when updating the schema of a protobuf message.
408*6dbdd20aSAndroid Build Coastguard Worker
409*6dbdd20aSAndroid Build Coastguard Worker#### DataSourceDescriptor
410*6dbdd20aSAndroid Build Coastguard Worker
411*6dbdd20aSAndroid Build Coastguard WorkerDefined in [data_source_descriptor.proto]. This message is sent
412*6dbdd20aSAndroid Build Coastguard WorkerProducer -> Service through IPC on the Producer socket during the Producer
413*6dbdd20aSAndroid Build Coastguard Workerinitialization, before any tracing session is started. This message is used
414*6dbdd20aSAndroid Build Coastguard Workerto register advertise a data source and its capabilities (e.g., which GPU HW
415*6dbdd20aSAndroid Build Coastguard Workercounters are supported, their possible sampling rates).
416*6dbdd20aSAndroid Build Coastguard Worker
417*6dbdd20aSAndroid Build Coastguard Worker#### DataSourceConfig
418*6dbdd20aSAndroid Build Coastguard Worker
419*6dbdd20aSAndroid Build Coastguard WorkerDefined in [data_source_config.proto]. This message is sent:
420*6dbdd20aSAndroid Build Coastguard Worker
421*6dbdd20aSAndroid Build Coastguard Worker* Consumer -> Service through IPC on the Consumer socket, as part of the
422*6dbdd20aSAndroid Build Coastguard Worker  [TraceConfig](/docs/concepts/config.md) when a Consumer starts a new tracing
423*6dbdd20aSAndroid Build Coastguard Worker  session.
424*6dbdd20aSAndroid Build Coastguard Worker
425*6dbdd20aSAndroid Build Coastguard Worker* Service -> Producer through IPC on the Producer socket, as a reaction to the
426*6dbdd20aSAndroid Build Coastguard Worker  above. The service passes through each `DataSourceConfig` section defined in
427*6dbdd20aSAndroid Build Coastguard Worker  the `TraceConfig` to the corresponding Producer(s) that advertise that data
428*6dbdd20aSAndroid Build Coastguard Worker  source.
429*6dbdd20aSAndroid Build Coastguard Worker
430*6dbdd20aSAndroid Build Coastguard Worker#### TracePacket
431*6dbdd20aSAndroid Build Coastguard Worker
432*6dbdd20aSAndroid Build Coastguard WorkerDefined in [trace_packet.proto]. This is the root object written by any data
433*6dbdd20aSAndroid Build Coastguard Workersource into the SMB when producing any form of trace event.
434*6dbdd20aSAndroid Build Coastguard WorkerSee the [TracePacket reference][trace-packet-ref] for the full details.
435*6dbdd20aSAndroid Build Coastguard Worker
436*6dbdd20aSAndroid Build Coastguard Worker## {#abi-stability} ABI Stability
437*6dbdd20aSAndroid Build Coastguard Worker
438*6dbdd20aSAndroid Build Coastguard WorkerAll the layers of the tracing protocol ABI are long-term stable and can only
439*6dbdd20aSAndroid Build Coastguard Workerbe changed maintaining backwards compatibility.
440*6dbdd20aSAndroid Build Coastguard Worker
441*6dbdd20aSAndroid Build Coastguard WorkerThis is due to the fact that on every Android release the `traced` service
442*6dbdd20aSAndroid Build Coastguard Workergets frozen in the system image while unbundled apps (e.g. Chrome) and host
443*6dbdd20aSAndroid Build Coastguard Workertools (e.g. Perfetto UI) can be updated at a more frequently cadence.
444*6dbdd20aSAndroid Build Coastguard Worker
445*6dbdd20aSAndroid Build Coastguard WorkerBoth the following scenarios are possible:
446*6dbdd20aSAndroid Build Coastguard Worker
447*6dbdd20aSAndroid Build Coastguard Worker#### Producer/Consumer client older than tracing service
448*6dbdd20aSAndroid Build Coastguard Worker
449*6dbdd20aSAndroid Build Coastguard WorkerThis happens typically during Android development. At some point some newer code
450*6dbdd20aSAndroid Build Coastguard Workeris dropped in the Android platform and shipped to users, while client software
451*6dbdd20aSAndroid Build Coastguard Workerand host tools will lag behind (or simply the user has not updated their app /
452*6dbdd20aSAndroid Build Coastguard Workertools).
453*6dbdd20aSAndroid Build Coastguard Worker
454*6dbdd20aSAndroid Build Coastguard WorkerThe tracing service needs to support clients talking and older version of the
455*6dbdd20aSAndroid Build Coastguard WorkerProducer or Consumer tracing protocol.
456*6dbdd20aSAndroid Build Coastguard Worker
457*6dbdd20aSAndroid Build Coastguard Worker* Don't remove IPC methods from the service.
458*6dbdd20aSAndroid Build Coastguard Worker* Assume that fields added later to existing methods might be absent.
459*6dbdd20aSAndroid Build Coastguard Worker* For newer Producer/Consumer behaviors, advertise those behaviors through
460*6dbdd20aSAndroid Build Coastguard Worker  feature flags when connecting to the service. Good examples of this are the
461*6dbdd20aSAndroid Build Coastguard Worker  `will_notify_on_stop` or `handles_incremental_state_clear` flags in
462*6dbdd20aSAndroid Build Coastguard Worker  [data_source_descriptor.proto]
463*6dbdd20aSAndroid Build Coastguard Worker
464*6dbdd20aSAndroid Build Coastguard Worker#### Producer/Consumer client newer than tracing service
465*6dbdd20aSAndroid Build Coastguard Worker
466*6dbdd20aSAndroid Build Coastguard WorkerThis is the most likely scenario. At some point in 2022 a large number of phones
467*6dbdd20aSAndroid Build Coastguard Workerwill still run Android P or Q, hence running a snapshot of the tracing service
468*6dbdd20aSAndroid Build Coastguard Workerfrom ~2018-2020, but will run a recent version Google Chrome.
469*6dbdd20aSAndroid Build Coastguard WorkerChrome, when configured in system-tracing mode (i.e. system-wide + in-app
470*6dbdd20aSAndroid Build Coastguard Workertracing), connects to the Android's `traced` producer socket and talks the
471*6dbdd20aSAndroid Build Coastguard Workerlatest version of the tracing protocol.
472*6dbdd20aSAndroid Build Coastguard Worker
473*6dbdd20aSAndroid Build Coastguard WorkerThe producer/consumer client code needs to be able to talk with an older version of the
474*6dbdd20aSAndroid Build Coastguard Workerservice, which might not support some newer features.
475*6dbdd20aSAndroid Build Coastguard Worker
476*6dbdd20aSAndroid Build Coastguard Worker* Newer IPC methods defined in [producer_port.proto] won't exist in the older
477*6dbdd20aSAndroid Build Coastguard Worker  service. When connecting on the socket the service lists its RPC methods
478*6dbdd20aSAndroid Build Coastguard Worker  and the client is able to detect if a method is available or not.
479*6dbdd20aSAndroid Build Coastguard Worker  At the C++ IPC layer, invoking a method that doesn't exist on the service
480*6dbdd20aSAndroid Build Coastguard Worker  causes the `Deferred<>` promise to be rejected.
481*6dbdd20aSAndroid Build Coastguard Worker
482*6dbdd20aSAndroid Build Coastguard Worker* Newer fields in existing IPC methods will just be ignored by the older version
483*6dbdd20aSAndroid Build Coastguard Worker  of the service.
484*6dbdd20aSAndroid Build Coastguard Worker
485*6dbdd20aSAndroid Build Coastguard Worker* If the producer/consumer client depends on a new behavior of the service, and
486*6dbdd20aSAndroid Build Coastguard Worker  that behavior cannot be inferred by the presence of a method, a new feature
487*6dbdd20aSAndroid Build Coastguard Worker  flag  must be exposed through the `QueryCapabilities` method.
488*6dbdd20aSAndroid Build Coastguard Worker
489*6dbdd20aSAndroid Build Coastguard Worker## Static linking vs shared library
490*6dbdd20aSAndroid Build Coastguard Worker
491*6dbdd20aSAndroid Build Coastguard WorkerThe Perfetto C++ Client Library is only available in the form of a static
492*6dbdd20aSAndroid Build Coastguard Workerlibrary and a single-source amalgamated SDK (which is effectively a static
493*6dbdd20aSAndroid Build Coastguard Workerlibrary). The library implements the Tracing Protocol ABI so, once statically
494*6dbdd20aSAndroid Build Coastguard Workerlinked, depends only on the socket and shared memory protocol ABI, which are
495*6dbdd20aSAndroid Build Coastguard Workerguaranteed to be stable.
496*6dbdd20aSAndroid Build Coastguard Worker
497*6dbdd20aSAndroid Build Coastguard WorkerNo shared library distributions for the C++ are available. We strongly
498*6dbdd20aSAndroid Build Coastguard Workerdiscourage teams from attempting to build the C++ tracing library as shared
499*6dbdd20aSAndroid Build Coastguard Workerlibrary and use it from a different linker unit. It is fine to link AND use the
500*6dbdd20aSAndroid Build Coastguard Workerclient library within the same shared library, as long as none of the perfetto
501*6dbdd20aSAndroid Build Coastguard WorkerC++ API is exported.
502*6dbdd20aSAndroid Build Coastguard Worker
503*6dbdd20aSAndroid Build Coastguard WorkerThe `PERFETTO_EXPORT_COMPONENT` annotations are only used when building the
504*6dbdd20aSAndroid Build Coastguard Workerthird tier of the client library in chromium component builds and cannot be
505*6dbdd20aSAndroid Build Coastguard Workereasily repurposed for delineating shared library boundaries for the other two
506*6dbdd20aSAndroid Build Coastguard WorkerAPI tiers.
507*6dbdd20aSAndroid Build Coastguard Worker
508*6dbdd20aSAndroid Build Coastguard WorkerThis is because the C++ the first two tiers of the Client Library C++ API make
509*6dbdd20aSAndroid Build Coastguard Workerextensive use of inline headers and C++ templates, in order to allow the
510*6dbdd20aSAndroid Build Coastguard Workercompiler to see through most of the layers of abstraction.
511*6dbdd20aSAndroid Build Coastguard Worker
512*6dbdd20aSAndroid Build Coastguard WorkerMaintaining the C++ ABI across hundreds of inlined functions and a shared
513*6dbdd20aSAndroid Build Coastguard Workerlibrary is prohibitively expensive and too prone to break in extremely subtle
514*6dbdd20aSAndroid Build Coastguard Workerways. For this reason the team has ruled out shared library distributions for
515*6dbdd20aSAndroid Build Coastguard Workerthe time being.
516*6dbdd20aSAndroid Build Coastguard Worker
517*6dbdd20aSAndroid Build Coastguard WorkerA new C Client library API/ABI is in the works, but it's not stable yet.
518*6dbdd20aSAndroid Build Coastguard Worker
519*6dbdd20aSAndroid Build Coastguard Worker[cli_lib]: /docs/instrumentation/tracing-sdk.md
520*6dbdd20aSAndroid Build Coastguard Worker[selinux_producer]: https://cs.android.com/search?q=perfetto_producer%20f:sepolicy.*%5C.te&sq=
521*6dbdd20aSAndroid Build Coastguard Worker[selinux_consumer]:https://cs.android.com/search?q=f:sepolicy%2F.*%5C.te%20traced_consumer&sq=
522*6dbdd20aSAndroid Build Coastguard Worker[mojom]: https://source.chromium.org/chromium/chromium/src/+/master:services/tracing/public/mojom/perfetto_service.mojom?q=producer%20f:%5C.mojom$%20perfetto&ss=chromium&originalUrl=https:%2F%2Fcs.chromium.org%2F
523*6dbdd20aSAndroid Build Coastguard Worker[proto_rpc]: https://developers.google.com/protocol-buffers/docs/proto#services
524*6dbdd20aSAndroid Build Coastguard Worker[producer_port.proto]: /protos/perfetto/ipc/producer_port.proto
525*6dbdd20aSAndroid Build Coastguard Worker[consumer_port.proto]: /protos/perfetto/ipc/consumer_port.proto
526*6dbdd20aSAndroid Build Coastguard Worker[trace_packet.proto]: /protos/perfetto/trace/trace_packet.proto
527*6dbdd20aSAndroid Build Coastguard Worker[data_source_descriptor.proto]: /protos/perfetto/common/data_source_descriptor.proto
528*6dbdd20aSAndroid Build Coastguard Worker[data_source_config.proto]: /protos/perfetto/config/data_source_config.proto
529*6dbdd20aSAndroid Build Coastguard Worker[trace-packet-ref]: /docs/reference/trace-packet-proto.autogen
530*6dbdd20aSAndroid Build Coastguard Worker[shared_memory_abi.h]: /include/perfetto/ext/tracing/core/shared_memory_abi.h
531*6dbdd20aSAndroid Build Coastguard Worker[commit_data_request.proto]: /protos/perfetto/common/commit_data_request.proto
532*6dbdd20aSAndroid Build Coastguard Worker[proto-updating]: https://developers.google.com/protocol-buffers/docs/proto#updating
533