Skip to content

Add perfetto tracing to host tooling#2502

Open
jmacnak wants to merge 1 commit into
google:mainfrom
jmacnak:perfetto
Open

Add perfetto tracing to host tooling#2502
jmacnak wants to merge 1 commit into
google:mainfrom
jmacnak:perfetto

Conversation

@jmacnak
Copy link
Copy Markdown
Member

@jmacnak jmacnak commented May 1, 2026

@jmacnak jmacnak force-pushed the perfetto branch 7 times, most recently from e958a29 to 8330f27 Compare May 6, 2026 17:15
@jmacnak jmacnak added the kokoro:force-run Trigger a presubmit build unconditionally. label May 6, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label May 6, 2026
@jmacnak jmacnak force-pushed the perfetto branch 4 times, most recently from 19542bf to 6e9eaf0 Compare May 7, 2026 18:24
@jmacnak jmacnak force-pushed the perfetto branch 4 times, most recently from d663657 to 1d90f66 Compare May 15, 2026 20:00
Example cvd create trace:
https://ui.perfetto.dev/#!/?s=315a987bda469405966eb46797201e11b12d247c

Example cvd fetch trace:
https://ui.perfetto.dev/#!/?s=8e6e182ffab8e92f0f0a690b205c73313ec71f17

Perfetto uses a shared memory buffer between producer processes and the
traced consumer daemon. `fork()` is problematic for this as the parent
and child processes would end up clobbering each other when the shared
memory buffer is inherited by the child. To prevent this, we introduce
a perfetto wrapper that uses `pthread_atfork()` to register handlers that
shutdown and restart tracing before and after forking.

Perfetto also depends on global static data and explicitly calls out that
it can not be restarted unless this data is cleared [1]. With this, the
Perfetto wrapper utilizes `dlopen()` and `dlclose()` during init and
shutdown.

Perfetto also uses thread local data which requires extra care around
`dlclose()` to prevent some thread local destructors from running after
`dlclose()` has already unloaded the Perfetto library. To work around
this, the Perfetto wrapper isolates all Perfetto calls into a single
worker thread.

[1] https://github.com/google/perfetto/blob/ab21398d658ce3bccc192b226d2731add6c02890/include/perfetto/tracing/tracing.h#L252

Bug: b/378560215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants