startup trace: Fix abort and restart

Before this change, AbortAndRestart was not working for startup tracing.

The reason being: In the newly started session, we were not able to
recognize the abortion of previous startup trace properly. As a result
trace macros/lambdas remains associated with old trace writers, because
TLS state was not updated properly. Since old trace writer was bound to
`kInvalidTraceBuffer` when we called AbortStartupTracing, newly written
traces were also getting dumped into trash instead of new buffer.

It remained bound to `kInvalidTraceBuffer` even after main tracing
session was started, because main tracing session also adopts existing
data sources (which were instantiated for the startup trace).

Note that: After restarting startup tracing, if we had trace macros in
some different thread (different from where we used trace macros before
aborting), then it was working fine.

In the abortion of start up trace, we were already doing
`TracingMuxer::generation_++` to trigger the validation of thread local
trace-writter in the fast path. However that validation was incorrect
because it was not taking `DataSource.target_buffer_reservation_id`
into account. It was only taking `DataSource.target_buffer_id` into
account. Since the `target_buffer_id` remains zero if the data source
was started for the startup tracing, misreporting of
trace-writer-validity was causing fast-path to not create a new
trace-writter from global muxer.

Fix : Take `target_buffer_reservation_id` into account for checking
if the static-state of a DataSource changed significantly to require a
new trace-writter by fast path.

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