tracy icon indicating copy to clipboard operation
tracy copied to clipboard

TRACY_MANUAL_LIFETIME and delayed or optional startup

Open YaLTeR opened this issue 8 months ago • 1 comments

I am using Tracy to profile Mutter and GNOME Shell. I would also like to instrument some libraries like GLib or GJS.

These libraries are loaded into many different processes. However, only the particular process I'm interested in (GNOME Shell) should do any profiling, or start any Tracy threads—otherwise there's a lot of unnecessary overhead and spam in the connection list.

TRACY_MANUAL_LIFETIME is perfect for this, except there's a problem: calling most Tracy functions will crash with an assertion before the profiler is started. What I want instead is for them to do nothing before the profiler is started, kind of like TRACY_ON_DEMAND. I will call ___tracy_startup_profiler() in the one binary that I need, making the instrumentation live, and instrumentation in GLib loaded into all other processes should do nothing.

Right now in my Tracy fork I added a workaround function and check it manually in GLib before calling other Tracy functions.

TRACY_API int ___tracy_is_profiler_started( void )
{
    return tracy::s_profilerData != nullptr;
}

I think it would be nicer if it worked more like TRACY_ON_DEMAND, as in if it also added the check automatically into the relevant Tracy functions. It could be a new define, or it could just do it when TRACY_MANUAL_LIFETIME is set.

Is this something that would be accepted upstream, and if so, how exactly should I go about this?

YaLTeR avatar Oct 15 '23 07:10 YaLTeR