ftrace: add drain_buffer_percent option for poll-based ftrace ring buffer reads

Firstly, explaining net changes to existing configs that utilise only
periodic reads:
* removed per-tick-period quotas of number of pages that the reader
  extracts from the kernel buffers before it starts shedding load. There
  are situations where this is beneficial, but we're changing our
  approach here to instead scale with the underlying ftrace bandwidth,
  even if it increases the cpu% utilisation. Either way, I'm unconvinced
  these quotas were ever being hit in typical tracing configurations.
* small: for read tick period calculations, we now consider only the
  active data sources (as opposed to all setup ones).
* niche: for configs using non-boot ftrace clocks, moved the clock
  snapshotting closer to the beginning of a read pass.

The poll-based reads are enabled in addition to the periodic ReadTick if
the config requests them. If all concurrent configs are using poll and
none set an explicit drain_period_ms, we'll relax the ReadTick period to
1 second. The tick is still beneficial as it spreads out work more
evenly, helps procfs scrape freshness, and is a general fallback in case
polling doesn't work as expected. The polling is scoped to individual
ftrace instances (highly niche feature for now), but the tick is still
global.

Code-wise:
* config_muxer manages the tracefs/buffer_percent file, picking the
  smallest value out of active configs.
* ftrace_controller manages the polling and callbacks on the per-cpu
  ring buffer fds.

For now the feature is nop'd out on kernels below v6.1 (prior to which
the polls returned as soon as a buffer was non-empty), but I'm looking
into relaxing it on Android GKI builds that are known to have the fix
backported.

(Most of the testing has been manual, the mock-based unittests are too
brittle for me to want to pile on more at the moment.)

Change-Id: Icba56768ded03bb4d725fbb596e965c86195c33c
17 files changed
tree: ce6c07d62c979f2016232de239484c2509de7da4
  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. WATCHLISTS
  47. 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.