mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-10 07:09:46 +00:00
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.