ftrace: fix pointer stability of events_ vector

This fixes an extremely subtle bug which causes traced_probes to
crash when tracing on some specific devices.
The root cause of the bug is the fact that in rare cirumstances
the events_ vector can be resized after construction, after some
Event* poitners have been handed out, hence invalidating them.
The rare circumstance is:
- The trace config ends up hitting a "generic event" path, i.e.
  the ftrace event is not known at compile time but exists on the
  target device (note this is not that unlikely because the expansion
  of some atrace categories in ftrace_config_muxer.cc can end up
  adding events like sde/sde_cmd_release_bw which are not in the
  compile-time list.
- The ftrace event ID of the generic event above is > than the
  max(ID of events known at compile time)
- The vector resize() ends up hitting the unhappy realloc() path
  which changes the data() pointer and mem-copies everything,
  invalidating all pointers.

Fix: use std::deque, which guarantees pointer stability.

Bug: 159998308
Change-Id: Id21fabf0c940fd0e5302518c0170686d61aaf847
Merged-In: Id21fabf0c940fd0e5302518c0170686d61aaf847
(cherry picked from commit bd3e8ecca937a76318c68ec8e8da72cb5c0239ba)
(cherry picked from commit 5cceb8adf772f3638577dea0d255b8bef3a743e5)
2 files changed
tree: d9ecb9020b67dd91f7e83f6149a047e5b2a015fe
  1. bazel/
  2. build_overrides/
  3. buildtools/
  4. debian/
  5. docs/
  6. examples/
  7. gn/
  8. include/
  9. infra/
  10. protos/
  11. src/
  12. test/
  13. tools/
  14. ui/
  15. .clang-format
  16. .gitignore
  17. .gn
  18. .style.yapf
  19. Android.bp
  20. Android.bp.extras
  21. BUILD
  22. BUILD.extras
  23. BUILD.gn
  24. codereview.settings
  25. heapprofd.rc
  26. LICENSE
  27. METADATA
  28. MODULE_LICENSE_APACHE2
  29. OWNERS
  30. perfetto.rc
  31. PRESUBMIT.py
  32. README.chromium
  33. README.md
  34. TEST_MAPPING
  35. traced_perf.rc
  36. 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://docs.perfetto.dev or the /docs/ directory for documentation.