Add perfetto tracing to host tooling#2502
Open
jmacnak wants to merge 1 commit into
Open
Conversation
e958a29 to
8330f27
Compare
19542bf to
6e9eaf0
Compare
d663657 to
1d90f66
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example cvd create trace:
https://ui.perfetto.dev/#!/?s=315a987bda469405966eb46797201e11b12d247c
Example cvd fetch trace:
https://ui.perfetto.dev/#!/?s=8e6e182ffab8e92f0f0a690b205c73313ec71f17