• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Perfetto IPC
2
3*** note
4**This doc is WIP**, stay tuned.
5<!-- TODO(primiano): write IPC doc. -->
6***
7
8**TL;DR**
9We needed an IPC for Android and Linux which was small, simple, controllable,
10predictable, C++11 friendly and debuggable.
11Our IPC transport is not mandatory outside of Android, you can wrap your own IPC
12transport (e.g., Perfetto uses Mojo in chromium) or just short circuit the
13Perfetto `{Service,Producer,Consumer}` interfaces for IPC-less full in-process
14use.
15
16Key features:
17- Protobuf over a unix-socket.
18- Allows to send file descriptors over the wire: for setting up shared memory
19  and passing the FD for the output trace from a consumer to the service.
20- Service definition uses same protobuf rpc syntax of [gRPC](https://grpc.io)
21- Extremely simple [wire protocol](/src/ipc/wire_protocol.proto).
22- C++11 friendly, allows to bind `std::function` to each request.
23- Leak (un)friendly: tries hard to guarantee that callbacks are left unresolved,
24  using C++11 move semantics.
25- Shutdown / destruction friendly: tries hard to guarantee that no callbacks are
26  issued after the IPC channel is destroyed.
27- Disconnection-friendly: all outstanding requests (and hence pending callbacks)
28  are nack-ed in case of a disconnection (e.g., if the endpoint crashes).
29- Memory friendly: one virtually contiguous cache-friendly rx buffer,
30  madvise()'d when when not used.
31- Debugging friendly: single-thread only, based on non-blocking socket I/O.
32- Binary size friendly: generates one protobuf per message, doesn't have any
33  external dependency.
34- Hopefully safe:
35  - The rx buffer has guard regions around.
36  - The wire protocol is based on protobuf.
37  - [Fuzzed](/src/ipc/buffered_frame_deserializer_fuzzer.cc)
38- Offers direct control of socket buffers and overrun/stalling policy.
39- ABI stable.
40
41Realistically will never support:
42  - Multithreading / thread pools.
43  - Congestion or flow control.
44  - Non-data object brokering (e.g. sending a remote interface).
45  - Introspection / reflection.
46