traced_perf: add memory guardrail (stops the DS if daemon above limit)

Normally, when a source is stopped, traced_perf:
* pauses the perf_events stream
* waits for reader to drain the outstanding samples
* waits for the unwinder to unwind them
* cleans up and acks the StopDataSource

Instead, this patch introduces an option for stopping the work abruptly,
immediately erasing the data source state from both the reader and
unwinder stages.

Note: the tracing service (traced) doesn't respect producer stop
notifications unless the service itself started the stop sequence. So we
can't just NotifyDataSourceStopped(), and will keep receiving flush &
stop request IPCs for the DS that we've forgotten about. I believe it's
safe to blindly ack unknown flushes and stops (as the service should be
accutrate about routing the IPCs in the first place). Do tell if I'm
overlooking an important detail though.

An alternative would've been to introduce a new DS status (kTombstoned
or similar), and propagate that knowledge until the StopDataSource IPC.
But I don't think that complexity is worth it.

Note: I went with a separate periodic task per guardrail'd DS. Having
concurrent sources should be rare, so it doesn't feel worth sharing the
mem footprint calculation cost. Also, this will allow us to introduce a
guardrail check period as part of the trace config, should we need that
flexibility.

Change-Id: I6d585e6728991141e1ab8bd0b8f6b2ad6fe6d5fc
8 files changed
tree: 95d6a7712d728c4d875aedb9e5f94623ca082c47
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. src/
  13. test/
  14. tools/
  15. ui/
  16. .clang-format
  17. .clang-tidy
  18. .gitignore
  19. .gn
  20. .style.yapf
  21. Android.bp
  22. Android.bp.extras
  23. BUILD
  24. BUILD.extras
  25. BUILD.gn
  26. CHANGELOG
  27. codereview.settings
  28. heapprofd.rc
  29. LICENSE
  30. METADATA
  31. MODULE_LICENSE_APACHE2
  32. OWNERS
  33. perfetto.rc
  34. PRESUBMIT.py
  35. README.chromium
  36. README.md
  37. TEST_MAPPING
  38. traced_perf.rc
  39. 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.