mirror of
https://github.com/wolfpld/tracy.git
synced 2026-06-08 08:33:48 +00:00
Fix and refactor zone running time
Many of the zones would have a negative running time due to a missing `cs->IsEndValid()` check. This could end reporting context switches before the zone start, due to `cs->End()` returning -1. This happened when systrace dropped event, or when using Fibers and `TracyFiberEnter` is called on the new thread once the fiber has been scheduled. (The manual actually does not really hint this is wrong, we should probably fix the manual or the server code.) In both cases, we assume runtime to be 0 for that context switch. Since we have no actual information. Both options (counting full runtime or no runtime) are wrong, and most of the code handling `!cs->IsEndValid()` uses `Start` instead so that's what I did. This is still a net improvement over displaying negative values. If we want to change this handling, we'd need to review the other places that do `it->IsEndValid() ? it->End() : it->Start()` as well. It also seems two different concepts were being mixed: 1. Do we have any context switch data at all ? (`it != ctx->v.end()` ie `count != 0`) 2. Do we have complete data for the last context switch (`eit != ctx->v.end()`) This led to some places of the code not displaying or counting running time at all, notably when hovering a zone. I think most of the time we wanted 1, as it reports correctly and assumes the last context switch is still running, which is a fair assumption if we didn't see one putting the thread to sleep. I also fixed a case where we were overcounting runtime when range start was during a sleep.
This commit is contained in:
@@ -563,6 +563,7 @@ struct ContextSwitchData
|
||||
tracy_force_inline int64_t End() const { return _end.Val(); }
|
||||
tracy_force_inline void SetEnd( int64_t end ) { assert( end < (int64_t)( 1ull << 47 ) ); _end = end; }
|
||||
tracy_force_inline bool IsEndValid() const { return _end.IsNonNegative(); }
|
||||
tracy_force_inline int64_t EndOrStart() const { return _end.IsNonNegative() ? _end.Val() : _start.Val(); }
|
||||
tracy_force_inline uint8_t Cpu() const { return _cpu; }
|
||||
tracy_force_inline void SetCpu( uint8_t cpu ) { _cpu = cpu; }
|
||||
tracy_force_inline uint8_t WakeupCpu() const { return _wakeupcpu; }
|
||||
|
||||
Reference in New Issue
Block a user