SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
Other
6.46k stars 454 forks source link

Multi-threaded stats #872

Open randy408 opened 1 year ago

randy408 commented 1 year ago

Describe the problem you are trying to solve. The stats addon and explorer is not MT aware, the values stop making sense with multiple threads.

Describe the solution you'd like Add support for per-thread stats, thread-specific stats (could indicate how well work is distributed, etc), and proper sums for time spent in systems (wall clock vs cpu time). And then support for it in explorer, of course.

ZeroErrors commented 1 year ago

To add a little more detail to this issue.

Currently the system_time_total is calculated only on the main thread: https://github.com/SanderMertens/flecs/blob/b5241cc76e50cba8cefe423c4478bf6fadb28462/src/addons/pipeline/pipeline.c#L632-L641

This means that the stats only knows about the amount of time the operation took to execute the main thread portion of the work, however, systems may have unbalanced work. Meaning a worker thread could have more to do than the main thread. If this happens it will cause the time interval on the main thread will not be equivalent to the amount of time the system actually took to execute.