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
2 files changed
tree: 0ab0599b64a0dcdfd157327a60f00b4e21087fc7
  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://perfetto.dev/docs or the /docs/ directory for documentation.