Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1
9#ifdef FLECS_STATS
10
19#ifndef FLECS_STATS_H
20#define FLECS_STATS_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define ECS_STAT_WINDOW (60)
27
29typedef struct ecs_gauge_t {
30 ecs_float_t avg[ECS_STAT_WINDOW];
31 ecs_float_t min[ECS_STAT_WINDOW];
32 ecs_float_t max[ECS_STAT_WINDOW];
34
36typedef struct ecs_counter_t {
38 double value[ECS_STAT_WINDOW];
40
42typedef union ecs_metric_t {
43 ecs_gauge_t gauge;
44 ecs_counter_t counter;
46
47typedef struct ecs_world_stats_t {
48 int64_t first_;
49
50 /* Entities */
51 struct {
54 } entities;
55
56 /* Component ids */
57 struct {
64 } components;
65
66 /* Tables */
67 struct {
72 } tables;
73
74 /* Queries & events */
75 struct {
79 } queries;
80
81 /* Commands */
82 struct {
83 ecs_metric_t add_count;
84 ecs_metric_t remove_count;
86 ecs_metric_t clear_count;
87 ecs_metric_t set_count;
88 ecs_metric_t get_mut_count;
89 ecs_metric_t modified_count;
90 ecs_metric_t other_count;
91 ecs_metric_t discard_count;
92 ecs_metric_t batched_entity_count;
93 ecs_metric_t batched_count;
94 } commands;
95
96 /* Frame data */
97 struct {
105 } frame;
106
107 /* Timing */
108 struct {
118 } performance;
119
120 struct {
121 /* Memory allocation data */
127 /* Memory allocator data */
134 } memory;
135
136 /* HTTP statistics */
137 struct {
138 ecs_metric_t request_received_count;
139 ecs_metric_t request_invalid_count;
140 ecs_metric_t request_handled_ok_count;
141 ecs_metric_t request_handled_error_count;
142 ecs_metric_t request_not_handled_count;
143 ecs_metric_t request_preflight_count;
144 ecs_metric_t send_ok_count;
145 ecs_metric_t send_error_count;
146 ecs_metric_t busy_count;
147 } http;
148
149 int64_t last_;
150
152 int32_t t;
154
166
168typedef struct ecs_system_stats_t {
169 int64_t first_;
172 int64_t last_;
173
174 bool task;
176 ecs_query_stats_t query;
178
180typedef struct ecs_sync_stats_t {
181 int64_t first_;
182 ecs_metric_t time_spent;
183 ecs_metric_t commands_enqueued;
184 int64_t last_;
185
186 int32_t system_count;
187 bool multi_threaded;
188 bool no_readonly;
190
192typedef struct ecs_pipeline_stats_t {
193 /* Allow for initializing struct with {0} */
194 int8_t canary_;
195
198 ecs_vec_t systems;
199
201 ecs_vec_t sync_points;
202
205 ecs_map_t system_stats;
206
208 int32_t t;
209
210 int32_t system_count;
214
220FLECS_API
222 const ecs_world_t *world,
223 ecs_world_stats_t *stats);
224
226FLECS_API
229 const ecs_world_stats_t *src);
230
232FLECS_API
234 ecs_world_stats_t *stats,
235 const ecs_world_stats_t *old,
236 int32_t count);
237
239FLECS_API
241 ecs_world_stats_t *stats);
242
244FLECS_API
247 const ecs_world_stats_t *src);
248
249FLECS_API
250void ecs_world_stats_log(
251 const ecs_world_t *world,
252 const ecs_world_stats_t *stats);
253
261FLECS_API
263 const ecs_world_t *world,
264 const ecs_query_t *query,
265 ecs_query_stats_t *stats);
266
268FLECS_API
271 const ecs_query_stats_t *src);
272
274FLECS_API
276 ecs_query_stats_t *stats,
277 const ecs_query_stats_t *old,
278 int32_t count);
279
281FLECS_API
283 ecs_query_stats_t *stats);
284
286FLECS_API
289 const ecs_query_stats_t *src);
290
291#ifdef FLECS_SYSTEM
300FLECS_API
302 const ecs_world_t *world,
303 ecs_entity_t system,
304 ecs_system_stats_t *stats);
305
307FLECS_API
310 const ecs_system_stats_t *src);
311
313FLECS_API
315 ecs_system_stats_t *stats,
316 const ecs_system_stats_t *old,
317 int32_t count);
318
320FLECS_API
322 ecs_system_stats_t *stats);
323
325FLECS_API
328 const ecs_system_stats_t *src);
329#endif
330
331#ifdef FLECS_PIPELINE
340FLECS_API
342 ecs_world_t *world,
343 ecs_entity_t pipeline,
344 ecs_pipeline_stats_t *stats);
345
350FLECS_API
352 ecs_pipeline_stats_t *stats);
353
355FLECS_API
358 const ecs_pipeline_stats_t *src);
359
361FLECS_API
364 const ecs_pipeline_stats_t *old,
365 int32_t count);
366
368FLECS_API
370 ecs_pipeline_stats_t *stats);
371
379FLECS_API
382 const ecs_pipeline_stats_t *src);
383
384#endif
385
387FLECS_API
389 ecs_metric_t *dst,
390 const ecs_metric_t *src,
391 int32_t t_dst,
392 int32_t t_src);
393
395FLECS_API
397 ecs_metric_t *m,
398 int32_t t,
399 int32_t count);
400
402FLECS_API
404 ecs_metric_t *m,
405 int32_t dst,
406 int32_t src);
407
408#ifdef __cplusplus
409}
410#endif
411
412#endif
413
416#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_stats_repeat_last(ecs_query_stats_t *stats)
Repeat last measurement.
FLECS_API void ecs_world_stats_get(const ecs_world_t *world, ecs_world_stats_t *stats)
Get world statistics.
struct ecs_pipeline_stats_t ecs_pipeline_stats_t
Statistics for all systems in a pipeline.
FLECS_API void ecs_query_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_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_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_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_stats_get())
FLECS_API void ecs_metric_copy(ecs_metric_t *m, int32_t dst, int32_t src)
Copy measurement.
FLECS_API void ecs_query_stats_copy_last(ecs_query_stats_t *dst, const ecs_query_stats_t *src)
Copy last measurement from source to destination.
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 bool ecs_pipeline_stats_get(ecs_world_t *world, ecs_entity_t pipeline, ecs_pipeline_stats_t *stats)
Get pipeline statistics.
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.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:305
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:349
struct ecs_query_t ecs_query_t
A query that caches its results.
Definition flecs.h:381
#define ecs_float_t
Customizable precision for floating point operations.
Definition flecs.h:36
Monotonically increasing counter.
Definition stats.h:36
ecs_gauge_t rate
Keep track of deltas too.
Definition stats.h:37
Simple value that indicates current state.
Definition stats.h:29
Statistics for all systems in a pipeline.
Definition stats.h:192
ecs_map_t system_stats
Map with system statistics.
Definition stats.h:205
int32_t rebuild_count
Number of times pipeline has rebuilt.
Definition stats.h:212
int32_t system_count
Number of systems in pipeline.
Definition stats.h:210
ecs_vec_t systems
Vector with system ids of all systems in the pipeline.
Definition stats.h:198
int32_t active_system_count
Number of active systems in pipeline.
Definition stats.h:211
ecs_vec_t sync_points
Vector with sync point stats.
Definition stats.h:201
int32_t t
Current position in ring buffer.
Definition stats.h:208
Statistics for a single query (use ecs_query_stats_get())
Definition stats.h:156
int32_t t
Current position in ring buffer.
Definition stats.h:164
ecs_metric_t matched_table_count
Matched non-empty tables.
Definition stats.h:158
ecs_metric_t matched_entity_count
Number of matched entities.
Definition stats.h:160
ecs_metric_t matched_empty_table_count
Matched empty tables.
Definition stats.h:159
Statistics for sync point.
Definition stats.h:180
Statistics for a single system (use ecs_system_stats_get())
Definition stats.h:168
ecs_metric_t invoke_count
Number of times system is invoked.
Definition stats.h:171
bool task
Is system a task.
Definition stats.h:174
ecs_metric_t time_spent
Time spent processing a system.
Definition stats.h:170
ecs_metric_t alloc_count
Allocs per frame.
Definition stats.h:122
ecs_metric_t block_free_count
Block frees per frame.
Definition stats.h:129
ecs_metric_t system_time
Time spent on running systems.
Definition stats.h:112
ecs_metric_t world_time_raw
Actual time passed since simulation start (first time progress() is called)
Definition stats.h:109
ecs_metric_t delete_count
Number of times id has been deleted.
Definition stats.h:63
ecs_metric_t rematch_count
Number of query rematches.
Definition stats.h:100
ecs_metric_t frame_time
Time spent processing a frame.
Definition stats.h:111
ecs_metric_t tag_count
Number of tag ids (ids without data)
Definition stats.h:58
ecs_metric_t component_count
Number of components ids (ids with data)
Definition stats.h:59
ecs_metric_t system_count
Number of systems.
Definition stats.h:78
ecs_metric_t merge_count
Number of merges executed.
Definition stats.h:99
ecs_metric_t free_count
Frees per frame.
Definition stats.h:124
ecs_metric_t query_count
Number of queries.
Definition stats.h:76
ecs_metric_t world_time
Simulation time passed since simulation start.
Definition stats.h:110
ecs_metric_t realloc_count
Reallocs per frame.
Definition stats.h:123
ecs_metric_t merge_time
Time spent on merging commands.
Definition stats.h:114
ecs_metric_t outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:125
ecs_metric_t observers_ran
Number of times an observer was invoked.
Definition stats.h:103
ecs_metric_t frame_count
Number of frames processed.
Definition stats.h:98
ecs_metric_t event_emit_count
Number of events emitted.
Definition stats.h:104
ecs_metric_t empty_count
Number of empty tables.
Definition stats.h:69
ecs_metric_t block_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:130
int32_t t
Current position in ring buffer.
Definition stats.h:152
ecs_metric_t stack_free_count
Page frees per frame.
Definition stats.h:132
ecs_metric_t rematch_time
Time spent on rematching.
Definition stats.h:115
ecs_metric_t fps
Frames per second.
Definition stats.h:116
ecs_metric_t systems_ran
Number of systems ran.
Definition stats.h:102
ecs_metric_t type_count
Number of registered types.
Definition stats.h:61
ecs_metric_t count
Number of entities.
Definition stats.h:52
ecs_metric_t emit_time
Time spent on notifying observers.
Definition stats.h:113
ecs_metric_t create_count
Number of times id has been created.
Definition stats.h:62
ecs_metric_t not_alive_count
Number of not alive (recyclable) entity ids.
Definition stats.h:53
ecs_metric_t stack_alloc_count
Page allocations per frame.
Definition stats.h:131
ecs_metric_t observer_count
Number of observers.
Definition stats.h:77
ecs_metric_t pipeline_build_count
Number of system pipeline rebuilds (occurs when an inactive system becomes active).
Definition stats.h:101
ecs_metric_t stack_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:133
ecs_metric_t block_alloc_count
Block allocations per frame.
Definition stats.h:128
ecs_metric_t delta_time
Delta_time.
Definition stats.h:117
ecs_metric_t pair_count
Number of pair ids.
Definition stats.h:60
Make all metrics the same size, so we can iterate over fields.
Definition stats.h:42