traced_perf: implement limiting inflight samples' heap footprint

The samples are enqueued by the main thread, and freed by the unwinding
thread, so the footprint accounting spans the two of them. The approach
is to keep two relaxed atomic counters, where the main thread increments
the allocated total, and the unwinder increments the deallocated total.
The main thread also reads both to look at their difference.

A bit rusty on atomics, but I think fully relaxed is fine here, as there
are only two threads, and the unwinder should never decrement beyond
what was allocated earlier (by the main thread, which is the reader).

Could've also made it a single atomic with fetch_add and fetch_sub,
don't think there's a major difference in practice either way.

See aosp/1660138 for more context.

Change-Id: I4aefb92147a450cd14143aa890faa905b7b6ca35
5 files changed
tree: 925868485dfd3179be26f89993be61fa2e2ed0c9
  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. .gitattributes
  19. .gitignore
  20. .gn
  21. .style.yapf
  22. Android.bp
  23. Android.bp.extras
  24. BUILD
  25. BUILD.extras
  26. BUILD.gn
  27. CHANGELOG
  28. codereview.settings
  29. DIR_METADATA
  30. heapprofd.rc
  31. LICENSE
  32. meson.build
  33. METADATA
  34. MODULE_LICENSE_APACHE2
  35. OWNERS
  36. perfetto.rc
  37. PerfettoIntegrationTests.xml
  38. PRESUBMIT.py
  39. README.chromium
  40. README.md
  41. TEST_MAPPING
  42. traced_perf.rc
  43. 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.