tracing_service_impl: Move compression from perfetto_cmd.cc

Before this change, trace compression was implemented in
perfetto_cmd.cc. This meant that it wasn't possible to use compression
with `write_into_file`, because the service would be directly writing
the data to a file, without going through perfetto_cmd.

With this commit the code that does the compression is moved into the
tracing service. Note that compression in the tracing service is only
enabled as part of `traced`, it's not enabled in the tracing service in
the client library (the compressor is injected with a function pointer).

Note that this change might have unexpected behavior when using
mismatching versions of perfetto_cmd and tracing_service (both will try
to compress or none will). In practice I'm not aware of any use of
mismatching versions, so I think it this will not be a problem.

The `compress_from_cli` config option can be used to restore the old
behavior (both in perfetto_cmd and tracing_service).

Here's the change in binary size for various files on android before and
after this patch:

```
| Binary                           | Size before | Size after |
| -------------------------------- | ----------- | ---------- |
| /system/bin/surfaceflinger       |     7445056 |    7445072 |
| /system/lib64/libgpumemtracer.so |      801936 |     806088 |
| /system/lib64/libperfetto.so     |     1124896 |    1125184 |
| /system/bin/perfetto             |      545176 |     545152 |
```

surfaceflinger and libgpumemtracer statically link the perfetto client
SDK. libperfetto.so contains the tracing service.

The last point to consider is that this makes the compression ratio a
little bit worse when write_into_file is not used. Before this patch,
perfetto_cmd was compressing as part of the same stream up to 512 Kb of
data. Now, reads from IPC are limited to 32 Kb, so that's how often we
have to reset the compression stream. In tested compressing 26 Mb of a
sample trace in both configurations and this are the results I got:

```
| Single stream size               | Total size | # of compressed packets |
| -------------------------------- | ---------- | ----------------------- |
| 32 Kb (after this patch)         |    9049943 |                     574 |
| 64 Kb                            |    8708512 |                     337 |
| 512 Kb (before this patch)       |    8306867 |                      50 |
```

Bug: 278884624

Change-Id: Ib777ba5c44930a53b3e95994e768a970822e70a3
22 files changed
tree: f7c05714a2edf270a54e09be7e42ed85140abbca
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. python/
  13. src/
  14. test/
  15. third_party/
  16. tools/
  17. ui/
  18. .clang-format
  19. .clang-tidy
  20. .git-blame-ignore-revs
  21. .gitattributes
  22. .gitignore
  23. .gn
  24. .style.yapf
  25. Android.bp
  26. Android.bp.extras
  27. BUILD
  28. BUILD.extras
  29. BUILD.gn
  30. CHANGELOG
  31. codereview.settings
  32. DIR_METADATA
  33. heapprofd.rc
  34. LICENSE
  35. meson.build
  36. METADATA
  37. MODULE_LICENSE_APACHE2
  38. OWNERS
  39. perfetto.rc
  40. PerfettoIntegrationTests.xml
  41. PRESUBMIT.py
  42. README.chromium
  43. README.md
  44. TEST_MAPPING
  45. traced_perf.rc
  46. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.