Add FDs to the IPC layer and expose shmem to tracing layer

IPC layer
---------
Adds the plumbing to pass a file descriptor to IPC host->client
messages through ipc::AsyncResult. The passed FD is deliberately not
owned (the IPC transport cannot know if the caller wants to retain
the original FD or is fine destroying it).
The API to access the passed file descriptors is current extremely
simplistic: the caller (e.g. the tracing/ code in our case) is
supposed to know when a FD is expected. A nicer API would have been
tying the FD to the proto messages decoded from the incoming buffer
and adding an annotation to the special protobuf messages that can
receive a FD. However that requires too much eng work to get right,
given the SOCK_STREAM nature of the IPC socket, with marginal benefit.
Also adds tests coverage to both the client and host ipc_unittests.

Tracing library
---------------
Adds the plumbing that exposes the shared_memory() to both Producer
and Service . It also gives the possibility for a Producer to hint
the size of the shared memory buffer to the Service.
After this CL the shared memory buffer is just exposed but not used
yet by the tracing library. The only use right now is in the toy
multiprocess end-to-end example (out/xxx/tracing_test).

Test: ipc_unittests --gtest_filter=ClientImplTest.ReceiveFileDescriptor
Test: ipc_unittests --gtest_filter=HostImplTest.SendFileDescriptor
Test: ipc_unittests --gtest_filter=DeferredTest.*
Test: tracing_test
Bug: 68854111

Change-Id: Ie7e72a4edbe9db8fa2f8b00cfa120a45272c6d8b
20 files changed
tree: f9a8bb41a99c6868bea9f30f512b7df17e71f7ba
  1. base/
  2. build/
  3. buildtools/
  4. ftrace_reader/
  5. infra/
  6. ipc/
  7. protos/
  8. protozero/
  9. tools/
  10. tracing/
  11. .clang-format
  12. .gitignore
  13. .gn
  14. .travis.yml
  15. BUILD.gn
  16. codereview.settings
  17. MODULE_LICENSE_APACHE2
  18. NOTICE
  19. OWNERS
  20. PRESUBMIT.py
  21. README.md
README.md

Perfetto - Performance instrumentation and logging for POSIX platforms

This project is meant to be built both as part of the Android tree and from a standalone checkout

For internal docs see this page

Supported platforms

Android is the platform targeted in the first milestones. Right now Linux desktop and OSX are maintained best-effort.

Get the code

Prerequisites

All dependent libraries are self-hosted and pulled by the build/install-build-deps script.
The only requirements on the host are python, git and a compiler (preferably clang, gcc is maintained best-effort):
$ sudo apt-get update && sudo apt-get install git clang python

Then:
$ git clone https://android.googlesource.com/platform/external/perfetto.git

Contributing

This project uses Android AOSP Gerrit for code reviews and uses the Google C++ style. Currently targets -std=c++11.

You can use both git cl upload from Chromium depot tools or Android repo to upload patches.

git cl is quite convenient as it supports code auto-formatting via git cl format.

See https://source.android.com/source/contributing for more details about external contributions and CLA signing.

Build instructions

Build from a standalone checkout

If you are a chromium developer and have depot_tools installed you can avoid the build/ prefix below and just use gn/ninja from depot_tools.

$ build/install-build-deps to install third-party build deps (NDK etc)

$ build/gn args out/android to generate build files and enter in the editor:

target_os = "android"          # Leave empty for local testing
target_cpu = "arm" or "arm64"  # Only when building for Android

(See the Build Configurations section below for more)

$ build/ninja -C out/android all

Build from the Android tree

TODO. The plan is to autogenerate the Android.bp build files from the master GN build files (or temporarily maintain both until we can autogenerate them).

Run tests

On the host (Linux / OSX)

$ build/ninja -C out/default (tracing_unittests | tracing_benchmarks)
$ out/default/tracing_unittests --gtest_help

On Android

Either connect a device in ADB mode or use the bundled emulator.

To start the emulator:
$ build/run_android_emulator (arm | arm64) &

To run the tests (either on the emulator or physical device):
$ build/run_android_test out/default tracing_unittests

Build configurations

The following GN args are supported:

target_os = "android" | "linux" | "mac":
Defaults to the current host, set "android" to build for Android.

target_cpu = "arm" | "arm64" | "x86" | "x64":
Defaults to "arm" when target_os == "android", "x64" when targeting the host. 32-bit host builds are not supported.

is_debug = true | false:
Toggles Debug (default) / Release mode.

is_clang = true | false:
Use Clang (default) / GCC. It requires clang 3.5+ to be installed on the host. Clang is the default compiler on Mac (% having installed Xcode). On Linux: sudo apt-get update && sudo apt-get install clang

cc = "gcc" / cxx = "g++":
Uses a different compiler binary (default: autodetected depending on is_clang).

is_asan = true:
Enables Address Sanitizer

is_lsan = true:
Enables Leak Sanitizer
(Linux/Mac only)

is_msan = true:
Enables Memory Sanitizer
(Linux only)

is_tsan = true:
Enables Thread Sanitizer
(Linux/Mac only)

is_ubsan = true:
Enables Undefined Behavior Sanitizer