Open kkpattern opened 1 year ago
The original code (written back in 2018) makes little sense to me now. There even are places where it just can't work (e.g. increase the uint counter, and then check if it's > 0). It should probably be rewritten from scratch.
Hi, thanks for this great tool.
We are writing a tracy python binding. Python has a
PyEval_SetProfile
API to set a profiler function in the interpreter. Every time a function is called or returned, this profiler function will be called. We can usePyEval_SetProfile
to add tracy instruments automatically, which makes tracy a perfect match with python.Since the profiler function is stateless, we can not simply use the tracy C API because there is no easy way to pass the
ctx
variable without hurting the performance. Therefore, we learned from the lua binding to use theLuaZoneState.counter
to correctly match the zone begin and zone end.PyEval_SetProfile
can be called dynamically when the python program is running. This allows us to toggle the tracy profile online, which makes it even better. There is one little problem: when thePyEval_SetProfile
is called and tracy profile is activated, we may already inside some python function. Then we will get morePyTrace_RETURN
thanPyTrace_CALL
, meaning we may get a negativeLuaZoneState.counter
value. So we will hit the assertion. Even if we use the release build, the tracy server will still complain the mismatch zone begin and end.But we can actually recover from a negative counter, as long as we don’t send any data when the counter is negative. So if we change
LuaZoneState.counter
fromuint32_t
toint32_t
, we can solve the problem like this:The above code works perfectly for us. If changing
LuaZoneState.counter
toint32_t
is ok for tracy, we’d like to create a PR for this.Again, thanks so much for this wonderful tool!