Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1
15#ifdef FLECS_STATS
16
25#ifndef FLECS_STATS_H
26#define FLECS_STATS_H
27
28#ifndef FLECS_MODULE
29#define FLECS_MODULE
30#endif
31
32#ifndef FLECS_PIPELINE
33#define FLECS_PIPELINE
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define ECS_STAT_WINDOW (60)
41
43typedef struct ecs_gauge_t {
44 ecs_float_t avg[ECS_STAT_WINDOW];
45 ecs_float_t min[ECS_STAT_WINDOW];
46 ecs_float_t max[ECS_STAT_WINDOW];
48
50typedef struct ecs_counter_t {
52 double value[ECS_STAT_WINDOW];
54
56typedef union ecs_metric_t {
57 ecs_gauge_t gauge;
58 ecs_counter_t counter;
60
61typedef struct ecs_world_stats_t {
62 int64_t first_;
63
64 /* Entities */
65 struct {
68 } entities;
69
70 /* Component ids */
71 struct {
78 } components;
79
80 /* Tables */
81 struct {
86 } tables;
87
88 /* Queries & events */
89 struct {
93 } queries;
94
95 /* Commands */
96 struct {
97 ecs_metric_t add_count;
98 ecs_metric_t remove_count;
100 ecs_metric_t clear_count;
101 ecs_metric_t set_count;
102 ecs_metric_t ensure_count;
103 ecs_metric_t modified_count;
104 ecs_metric_t other_count;
105 ecs_metric_t discard_count;
106 ecs_metric_t batched_entity_count;
107 ecs_metric_t batched_count;
108 } commands;
109
110 /* Frame data */
111 struct {
119 } frame;
120
121 /* Timing */
122 struct {
132 } performance;
133
134 struct {
135 /* Memory allocation data */
141 /* Memory allocator data */
148 } memory;
149
150 /* HTTP statistics */
151 struct {
152 ecs_metric_t request_received_count;
153 ecs_metric_t request_invalid_count;
154 ecs_metric_t request_handled_ok_count;
155 ecs_metric_t request_handled_error_count;
156 ecs_metric_t request_not_handled_count;
157 ecs_metric_t request_preflight_count;
158 ecs_metric_t send_ok_count;
159 ecs_metric_t send_error_count;
160 ecs_metric_t busy_count;
161 } http;
162
163 int64_t last_;
164
166 int32_t t;
168
180
182typedef struct ecs_system_stats_t {
183 int64_t first_;
185 int64_t last_;
186
187 bool task;
189 ecs_query_stats_t query;
191
193typedef struct ecs_sync_stats_t {
194 int64_t first_;
195 ecs_metric_t time_spent;
196 ecs_metric_t commands_enqueued;
197 int64_t last_;
198
199 int32_t system_count;
200 bool multi_threaded;
201 bool immediate;
203
205typedef struct ecs_pipeline_stats_t {
206 /* Allow for initializing struct with {0} */
207 int8_t canary_;
208
211 ecs_vec_t systems;
212
214 ecs_vec_t sync_points;
215
217 int32_t t;
218
219 int32_t system_count;
223
229FLECS_API
231 const ecs_world_t *world,
232 ecs_world_stats_t *stats);
233
235FLECS_API
238 const ecs_world_stats_t *src);
239
241FLECS_API
243 ecs_world_stats_t *stats,
244 const ecs_world_stats_t *old,
245 int32_t count);
246
248FLECS_API
250 ecs_world_stats_t *stats);
251
253FLECS_API
256 const ecs_world_stats_t *src);
257
258FLECS_API
259void ecs_world_stats_log(
260 const ecs_world_t *world,
261 const ecs_world_stats_t *stats);
262
270FLECS_API
272 const ecs_world_t *world,
273 const ecs_query_t *query,
274 ecs_query_stats_t *stats);
275
277FLECS_API
280 const ecs_query_stats_t *src);
281
283FLECS_API
285 ecs_query_stats_t *stats,
286 const ecs_query_stats_t *old,
287 int32_t count);
288
290FLECS_API
292 ecs_query_stats_t *stats);
293
295FLECS_API
298 const ecs_query_stats_t *src);
299
308FLECS_API
310 const ecs_world_t *world,
311 ecs_entity_t system,
312 ecs_system_stats_t *stats);
313
315FLECS_API
318 const ecs_system_stats_t *src);
319
321FLECS_API
323 ecs_system_stats_t *stats,
324 const ecs_system_stats_t *old,
325 int32_t count);
326
328FLECS_API
330 ecs_system_stats_t *stats);
331
333FLECS_API
336 const ecs_system_stats_t *src);
337
346FLECS_API
348 ecs_world_t *world,
349 ecs_entity_t pipeline,
350 ecs_pipeline_stats_t *stats);
351
356FLECS_API
358 ecs_pipeline_stats_t *stats);
359
361FLECS_API
364 const ecs_pipeline_stats_t *src);
365
367FLECS_API
370 const ecs_pipeline_stats_t *old,
371 int32_t count);
372
374FLECS_API
376 ecs_pipeline_stats_t *stats);
377
385FLECS_API
388 const ecs_pipeline_stats_t *src);
389
391FLECS_API
393 ecs_metric_t *dst,
394 const ecs_metric_t *src,
395 int32_t t_dst,
396 int32_t t_src);
397
399FLECS_API
401 ecs_metric_t *m,
402 int32_t t,
403 int32_t count);
404
406FLECS_API
408 ecs_metric_t *m,
409 int32_t dst,
410 int32_t src);
411
412FLECS_API extern ECS_COMPONENT_DECLARE(FlecsStats);
418FLECS_API extern ecs_entity_t EcsPeriod1s;
419FLECS_API extern ecs_entity_t EcsPeriod1m;
420FLECS_API extern ecs_entity_t EcsPeriod1h;
421FLECS_API extern ecs_entity_t EcsPeriod1d;
422FLECS_API extern ecs_entity_t EcsPeriod1w;
425typedef struct {
426 ecs_ftime_t elapsed;
427 int32_t reduce_count;
429
431typedef struct {
432 EcsStatsHeader hdr;
433 ecs_world_stats_t stats;
435
437typedef struct {
438 EcsStatsHeader hdr;
439 ecs_map_t stats;
441
443typedef struct {
444 EcsStatsHeader hdr;
445 ecs_map_t stats;
447
449typedef struct {
450 /* Time */
451 double target_fps;
452 double time_scale;
454 /* Total time */
459 /* Last frame time */
464 int64_t frame_count;
467 /* Build info */
470
479FLECS_API
481 ecs_world_t *world);
482
483#ifdef __cplusplus
484}
485#endif
486
487#endif
488
491#endif
FLECS_API void ecs_world_stats_reduce(ecs_world_stats_t *dst, const ecs_world_stats_t *src)
Reduce source measurement window into single destination measurement.
union ecs_metric_t ecs_metric_t
Make all metrics the same size, so we can iterate over fields.
FLECS_API void ecs_query_stats_get(const ecs_world_t *world, const ecs_query_t *query, ecs_query_stats_t *stats)
Get query statistics.
FLECS_API void ecs_query_cache_stats_reduce_last(ecs_query_stats_t *stats, const ecs_query_stats_t *old, int32_t count)
Reduce last measurement into previous measurement, restore old value.
FLECS_API void ecs_world_stats_get(const ecs_world_t *world, ecs_world_stats_t *stats)
Get world statistics.
FLECS_API ecs_entity_t EcsPeriod1s
Tag used for metrics collected in last second.
struct ecs_pipeline_stats_t ecs_pipeline_stats_t
Statistics for all systems in a pipeline.
FLECS_API ecs_entity_t EcsPeriod1h
Tag used for metrics collected in last hour.
FLECS_API void ecs_pipeline_stats_reduce_last(ecs_pipeline_stats_t *stats, const ecs_pipeline_stats_t *old, int32_t count)
Reduce last measurement into previous measurement, restore old value.
FLECS_API void ecs_query_cache_stats_repeat_last(ecs_query_stats_t *stats)
Repeat last measurement.
FLECS_API void ecs_metric_reduce_last(ecs_metric_t *m, int32_t t, int32_t count)
Reduce last measurement into previous measurement.
FLECS_API bool ecs_system_stats_get(const ecs_world_t *world, ecs_entity_t system, ecs_system_stats_t *stats)
Get system statistics.
FLECS_API void ecs_world_stats_reduce_last(ecs_world_stats_t *stats, const ecs_world_stats_t *old, int32_t count)
Reduce last measurement into previous measurement, restore old value.
FLECS_API void ecs_query_cache_stats_reduce(ecs_query_stats_t *dst, const ecs_query_stats_t *src)
Reduce source measurement window into single destination measurement.
struct ecs_query_stats_t ecs_query_stats_t
Statistics for a single query (use ecs_query_cache_stats_get)
FLECS_API void FlecsStatsImport(ecs_world_t *world)
Stats module import function.
FLECS_API void ecs_metric_copy(ecs_metric_t *m, int32_t dst, int32_t src)
Copy measurement.
struct ecs_gauge_t ecs_gauge_t
Simple value that indicates current state.
FLECS_API void ecs_pipeline_stats_repeat_last(ecs_pipeline_stats_t *stats)
Repeat last measurement.
FLECS_API void ecs_pipeline_stats_fini(ecs_pipeline_stats_t *stats)
Free pipeline stats.
FLECS_API void ecs_pipeline_stats_copy_last(ecs_pipeline_stats_t *dst, const ecs_pipeline_stats_t *src)
Copy last measurement to destination.
FLECS_API void ecs_system_stats_reduce(ecs_system_stats_t *dst, const ecs_system_stats_t *src)
Reduce source measurement window into single destination measurement.
FLECS_API void ecs_pipeline_stats_reduce(ecs_pipeline_stats_t *dst, const ecs_pipeline_stats_t *src)
Reduce source measurement window into single destination measurement.
FLECS_API void ecs_system_stats_copy_last(ecs_system_stats_t *dst, const ecs_system_stats_t *src)
Copy last measurement from source to destination.
struct ecs_system_stats_t ecs_system_stats_t
Statistics for a single system (use ecs_system_stats_get())
FLECS_API void ecs_system_stats_repeat_last(ecs_system_stats_t *stats)
Repeat last measurement.
FLECS_API void ecs_world_stats_repeat_last(ecs_world_stats_t *stats)
Repeat last measurement.
struct ecs_sync_stats_t ecs_sync_stats_t
Statistics for sync point.
FLECS_API void ecs_world_stats_copy_last(ecs_world_stats_t *dst, const ecs_world_stats_t *src)
Copy last measurement from source to destination.
FLECS_API void ecs_metric_reduce(ecs_metric_t *dst, const ecs_metric_t *src, int32_t t_dst, int32_t t_src)
Reduce all measurements from a window into a single measurement.
FLECS_API ecs_entity_t EcsPeriod1m
Tag used for metrics collected in last minute.
FLECS_API bool ecs_pipeline_stats_get(ecs_world_t *world, ecs_entity_t pipeline, ecs_pipeline_stats_t *stats)
Get pipeline statistics.
FLECS_API ecs_entity_t EcsPeriod1w
Tag used for metrics collected in last week.
struct ecs_counter_t ecs_counter_t
Monotonically increasing counter.
FLECS_API void ecs_system_stats_reduce_last(ecs_system_stats_t *stats, const ecs_system_stats_t *old, int32_t count)
Reduce last measurement into previous measurement, restore old value.
FLECS_API ecs_entity_t EcsPeriod1d
Tag used for metrics collected in last day.
FLECS_API void ecs_query_cache_stats_copy_last(ecs_query_stats_t *dst, const ecs_query_stats_t *src)
Copy last measurement from source to destination.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:339
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:383
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
Definition flecs_c.h:112
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
#define ecs_float_t
Customizable precision for floating point operations.
Definition flecs.h:52
Component that stores pipeline statistics.
Definition stats.h:443
Common data for statistics.
Definition stats.h:425
Component that stores system statistics.
Definition stats.h:437
Component that stores world statistics.
Definition stats.h:431
Component that stores a summary of world statistics.
Definition stats.h:449
double target_fps
Target FPS.
Definition stats.h:451
double merge_time_total
Total time spent in merges.
Definition stats.h:457
double frame_time_last
Time spent processing a frame.
Definition stats.h:460
int64_t frame_count
Number of frames processed.
Definition stats.h:464
double system_time_last
Time spent in systems.
Definition stats.h:461
ecs_build_info_t build_info
Build info.
Definition stats.h:468
double system_time_total
Total time spent in systems.
Definition stats.h:456
double frame_time_total
Total time spent processing a frame.
Definition stats.h:455
double merge_time_last
Time spent in merges.
Definition stats.h:462
double time_scale
Simulation time scale.
Definition stats.h:452
int64_t command_count
Number of commands processed.
Definition stats.h:465
Type with information about the current Flecs build.
Definition flecs.h:1328
Monotonically increasing counter.
Definition stats.h:50
ecs_gauge_t rate
Keep track of deltas too.
Definition stats.h:51
Simple value that indicates current state.
Definition stats.h:43
Statistics for all systems in a pipeline.
Definition stats.h:205
int32_t rebuild_count
Number of times pipeline has rebuilt.
Definition stats.h:221
int32_t system_count
Number of systems in pipeline.
Definition stats.h:219
ecs_vec_t systems
Vector with system ids of all systems in the pipeline.
Definition stats.h:211
int32_t active_system_count
Number of active systems in pipeline.
Definition stats.h:220
ecs_vec_t sync_points
Vector with sync point stats.
Definition stats.h:214
int32_t t
Current position in ring buffer.
Definition stats.h:217
Statistics for a single query (use ecs_query_cache_stats_get)
Definition stats.h:170
ecs_metric_t result_count
Number of query results.
Definition stats.h:172
int32_t t
Current position in ringbuffer.
Definition stats.h:178
ecs_metric_t matched_table_count
Number of matched tables.
Definition stats.h:173
ecs_metric_t matched_entity_count
Number of matched entities.
Definition stats.h:174
Queries are lists of constraints (terms) that match entities.
Definition flecs.h:760
Statistics for sync point.
Definition stats.h:193
Statistics for a single system (use ecs_system_stats_get())
Definition stats.h:182
bool task
Is system a task.
Definition stats.h:187
ecs_metric_t time_spent
Time spent processing a system.
Definition stats.h:184
ecs_metric_t alloc_count
Allocs per frame.
Definition stats.h:136
ecs_metric_t block_free_count
Block frees per frame.
Definition stats.h:143
ecs_metric_t system_time
Time spent on running systems.
Definition stats.h:126
ecs_metric_t world_time_raw
Actual time passed since simulation start (first time progress() is called)
Definition stats.h:123
ecs_metric_t delete_count
Number of times id has been deleted.
Definition stats.h:77
ecs_metric_t rematch_count
Number of query rematches.
Definition stats.h:114
ecs_metric_t frame_time
Time spent processing a frame.
Definition stats.h:125
ecs_metric_t tag_count
Number of tag ids (ids without data)
Definition stats.h:72
ecs_metric_t component_count
Number of components ids (ids with data)
Definition stats.h:73
ecs_metric_t system_count
Number of systems.
Definition stats.h:92
ecs_metric_t merge_count
Number of merges executed.
Definition stats.h:113
ecs_metric_t free_count
Frees per frame.
Definition stats.h:138
ecs_metric_t query_count
Number of queries.
Definition stats.h:90
ecs_metric_t world_time
Simulation time passed since simulation start.
Definition stats.h:124
ecs_metric_t realloc_count
Reallocs per frame.
Definition stats.h:137
ecs_metric_t merge_time
Time spent on merging commands.
Definition stats.h:128
ecs_metric_t outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:139
ecs_metric_t observers_ran
Number of times an observer was invoked.
Definition stats.h:117
ecs_metric_t frame_count
Number of frames processed.
Definition stats.h:112
ecs_metric_t event_emit_count
Number of events emitted.
Definition stats.h:118
ecs_metric_t empty_count
Number of empty tables.
Definition stats.h:83
ecs_metric_t block_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:144
int32_t t
Current position in ring buffer.
Definition stats.h:166
ecs_metric_t stack_free_count
Page frees per frame.
Definition stats.h:146
ecs_metric_t rematch_time
Time spent on rematching.
Definition stats.h:129
ecs_metric_t fps
Frames per second.
Definition stats.h:130
ecs_metric_t systems_ran
Number of systems ran.
Definition stats.h:116
ecs_metric_t type_count
Number of registered types.
Definition stats.h:75
ecs_metric_t count
Number of entities.
Definition stats.h:66
ecs_metric_t emit_time
Time spent on notifying observers.
Definition stats.h:127
ecs_metric_t create_count
Number of times id has been created.
Definition stats.h:76
ecs_metric_t not_alive_count
Number of not alive (recyclable) entity ids.
Definition stats.h:67
ecs_metric_t stack_alloc_count
Page allocations per frame.
Definition stats.h:145
ecs_metric_t observer_count
Number of observers.
Definition stats.h:91
ecs_metric_t pipeline_build_count
Number of system pipeline rebuilds (occurs when an inactive system becomes active).
Definition stats.h:115
ecs_metric_t stack_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:147
ecs_metric_t block_alloc_count
Block allocations per frame.
Definition stats.h:142
ecs_metric_t delta_time
Delta_time.
Definition stats.h:131
ecs_metric_t pair_count
Number of pair ids.
Definition stats.h:74
Make all metrics the same size, so we can iterate over fields.
Definition stats.h:56