Provide a way to signal that Perfetto will not be initialized
- Dominant language
- C++
- Stars
- 6.5k
- Forks
- 868
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 218
Description
There is currently no way to signal that Perfetto will not be initialized in a given process.
This means that all calls to Perfetto must be guarded by `Tracing::IsInitialized()` or cause crashes if Perfetto is uninitialized.
In particular, any calls to [`Track::FromPointer`](https://github.com/google/perfetto/blob/main/include/perfetto/tracing/track.h#L120) must be guarded by this check.
I am currently working on an experiment to conditionally not initialize Perfetto in WebView, but this is blocked by the numerous call sites to `Track::FromPointer` (and other API methods) which are currently not guarded by `IsInitialized()`.
I propose to add a `Tracing::WillNotInitialize()` function to signal that Perfetto will not be initialized. With this, it would be safe to create otherwise invalid `Track` objects. Calls to `Tracing::Initialize()` should naturally be prohibited if `WillNotInitialize()` has previously been called.
Such a method will allow most call sites to Perfetto to avoid having to explicitly check for initialization.
Contributor guide
Research direction
Start with include/perfetto/tracing/track.h, especially Track::FromPointer, and trace the existing Tracing::IsInitialized() and Tracing::Initialize() APIs. Define how a new Tracing::WillNotInitialize() state affects invalid Track creation and later initialization, then verify the affected call sites and API behavior with the relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100