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 /* Components and ids */
57 struct {
66 } ids;
67
68 /* Tables */
69 struct {
78 } tables;
79
80 /* Queries & events */
81 struct {
85 } queries;
86
87 /* Commands */
88 struct {
89 ecs_metric_t add_count;
90 ecs_metric_t remove_count;
92 ecs_metric_t clear_count;
93 ecs_metric_t set_count;
94 ecs_metric_t get_mut_count;
95 ecs_metric_t modified_count;
96 ecs_metric_t other_count;
97 ecs_metric_t discard_count;
98 ecs_metric_t batched_entity_count;
99 ecs_metric_t batched_count;
100 } commands;
101
102 /* Frame data */
103 struct {
111 } frame;
112
113 /* Timing */
114 struct {
124 } performance;
125
126 struct {
127 /* Memory allocation data */
133 /* Memory allocator data */
140 } memory;
141
142 /* REST statistics */
143 struct {
144 ecs_metric_t request_count;
145 ecs_metric_t entity_count;
146 ecs_metric_t entity_error_count;
148 ecs_metric_t query_error_count;
149 ecs_metric_t query_name_count;
150 ecs_metric_t query_name_error_count;
151 ecs_metric_t query_name_from_cache_count;
152 ecs_metric_t enable_count;
153 ecs_metric_t enable_error_count;
154 ecs_metric_t world_stats_count;
155 ecs_metric_t pipeline_stats_count;
156 ecs_metric_t stats_error_count;
157 } rest;
158
159 /* HTTP statistics */
160 struct {
161 ecs_metric_t request_received_count;
162 ecs_metric_t request_invalid_count;
163 ecs_metric_t request_handled_ok_count;
164 ecs_metric_t request_handled_error_count;
165 ecs_metric_t request_not_handled_count;
166 ecs_metric_t request_preflight_count;
167 ecs_metric_t send_ok_count;
168 ecs_metric_t send_error_count;
169 ecs_metric_t busy_count;
170 } http;
171
172 int64_t last_;
173
175 int32_t t;
177
179typedef struct ecs_query_stats_t {
180 int64_t first_;
184 int64_t last_;
185
187 int32_t t;
189
191typedef struct ecs_system_stats_t {
192 int64_t first_;
197 int64_t last_;
198
199 bool task;
201 ecs_query_stats_t query;
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
215 ecs_map_t system_stats;
216
218 int32_t t;
219
220 int32_t system_count;
224
230FLECS_API
232 const ecs_world_t *world,
233 ecs_world_stats_t *stats);
234
236FLECS_API
239 const ecs_world_stats_t *src);
240
242FLECS_API
244 ecs_world_stats_t *stats,
245 const ecs_world_stats_t *old,
246 int32_t count);
247
249FLECS_API
251 ecs_world_stats_t *stats);
252
254FLECS_API
257 const ecs_world_stats_t *src);
258
259FLECS_API
260void ecs_world_stats_log(
261 const ecs_world_t *world,
262 const ecs_world_stats_t *stats);
263
271FLECS_API
273 const ecs_world_t *world,
274 const ecs_query_t *query,
275 ecs_query_stats_t *stats);
276
278FLECS_API
281 const ecs_query_stats_t *src);
282
284FLECS_API
286 ecs_query_stats_t *stats,
287 const ecs_query_stats_t *old,
288 int32_t count);
289
291FLECS_API
293 ecs_query_stats_t *stats);
294
296FLECS_API
299 const ecs_query_stats_t *src);
300
301#ifdef FLECS_SYSTEM
310FLECS_API
312 const ecs_world_t *world,
314 ecs_system_stats_t *stats);
315
317FLECS_API
320 const ecs_system_stats_t *src);
321
323FLECS_API
325 ecs_system_stats_t *stats,
326 const ecs_system_stats_t *old,
327 int32_t count);
328
330FLECS_API
332 ecs_system_stats_t *stats);
333
335FLECS_API
338 const ecs_system_stats_t *src);
339#endif
340
341#ifdef FLECS_PIPELINE
350FLECS_API
352 ecs_world_t *world,
354 ecs_pipeline_stats_t *stats);
355
360FLECS_API
362 ecs_pipeline_stats_t *stats);
363
365FLECS_API
368 const ecs_pipeline_stats_t *src);
369
371FLECS_API
374 const ecs_pipeline_stats_t *old,
375 int32_t count);
376
378FLECS_API
380 ecs_pipeline_stats_t *stats);
381
389FLECS_API
392 const ecs_pipeline_stats_t *src);
393
394#endif
395
397FLECS_API
399 ecs_metric_t *dst,
400 const ecs_metric_t *src,
401 int32_t t_dst,
402 int32_t t_src);
403
405FLECS_API
407 ecs_metric_t *m,
408 int32_t t,
409 int32_t count);
410
412FLECS_API
414 ecs_metric_t *m,
415 int32_t dst,
416 int32_t src);
417
418#ifdef __cplusplus
419}
420#endif
421
422#endif
423
426#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.
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.
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.
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.
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.
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.
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.
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:282
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:291
struct ecs_query_t ecs_query_t
A query allows for cached iteration over ECS data.
Definition flecs.h:300
#define ecs_float_t
Customizable precision for floating point operations.
Definition flecs.h:35
flecs::pipeline_builder pipeline() const
Create a new pipeline.
flecs::query< Comps... > query(flecs::query_base &parent, Args &&... args) const
Create a subquery.
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:205
ecs_map_t system_stats
Map with system statistics.
Definition stats.h:215
int32_t rebuild_count
Number of times pipeline has rebuilt.
Definition stats.h:222
int32_t system_count
Number of systems in pipeline.
Definition stats.h:220
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:221
int32_t t
Current position in ringbuffer.
Definition stats.h:218
Statistics for a single query (use ecs_query_stats_get)
Definition stats.h:179
int32_t t
Current position in ringbuffer.
Definition stats.h:187
ecs_metric_t matched_table_count
Matched non-empty tables.
Definition stats.h:181
ecs_metric_t matched_entity_count
Number of matched entities.
Definition stats.h:183
ecs_metric_t matched_empty_table_count
Matched empty tables.
Definition stats.h:182
Statistics for a single system (use ecs_system_stats_get)
Definition stats.h:191
ecs_metric_t active
Whether system is active (is matched with >0 entities)
Definition stats.h:195
ecs_metric_t invoke_count
Number of times system is invoked.
Definition stats.h:194
bool task
Is system a task.
Definition stats.h:199
ecs_metric_t enabled
Whether system is enabled.
Definition stats.h:196
ecs_metric_t time_spent
Time spent processing a system.
Definition stats.h:193
ecs_metric_t alloc_count
Allocs per frame.
Definition stats.h:128
ecs_metric_t block_free_count
Block frees per frame.
Definition stats.h:135
ecs_metric_t system_time
Time spent on running systems.
Definition stats.h:118
ecs_metric_t world_time_raw
Actual time passed since simulation start (first time progress() is called)
Definition stats.h:115
ecs_metric_t delete_count
Number of times id has been deleted.
Definition stats.h:65
ecs_metric_t rematch_count
Number of query rematches.
Definition stats.h:106
ecs_metric_t frame_time
Time spent processing a frame.
Definition stats.h:117
ecs_metric_t tag_count
Number of tag ids (ids without data)
Definition stats.h:59
ecs_metric_t component_count
Number of components ids (ids with data)
Definition stats.h:60
ecs_metric_t system_count
Number of systems.
Definition stats.h:84
ecs_metric_t merge_count
Number of merges executed.
Definition stats.h:105
ecs_metric_t free_count
Frees per frame.
Definition stats.h:130
ecs_metric_t tag_only_count
Number of tables with only tags.
Definition stats.h:72
ecs_metric_t query_count
Number of queries.
Definition stats.h:82
ecs_metric_t world_time
Simulation time passed since simulation start.
Definition stats.h:116
ecs_metric_t realloc_count
Reallocs per frame.
Definition stats.h:129
ecs_metric_t merge_time
Time spent on merging commands.
Definition stats.h:120
ecs_metric_t outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:131
ecs_metric_t observers_ran
Number of times an observer was invoked.
Definition stats.h:109
ecs_metric_t frame_count
Number of frames processed.
Definition stats.h:104
ecs_metric_t event_emit_count
Number of events emitted.
Definition stats.h:110
ecs_metric_t empty_count
Number of empty tables.
Definition stats.h:71
ecs_metric_t wildcard_count
Number of wildcard ids.
Definition stats.h:62
ecs_metric_t storage_count
Number of table storages.
Definition stats.h:75
ecs_metric_t block_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:136
int32_t t
Current position in ringbuffer.
Definition stats.h:175
ecs_metric_t stack_free_count
Page frees per frame.
Definition stats.h:138
ecs_metric_t rematch_time
Time spent on rematching.
Definition stats.h:121
ecs_metric_t fps
Frames per second.
Definition stats.h:122
ecs_metric_t systems_ran
Number of systems ran.
Definition stats.h:108
ecs_metric_t type_count
Number of registered types.
Definition stats.h:63
ecs_metric_t count
Number of entities.
Definition stats.h:52
ecs_metric_t emit_time
Time spent on notifying observers.
Definition stats.h:119
ecs_metric_t create_count
Number of times id has been created.
Definition stats.h:64
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:137
ecs_metric_t trivial_only_count
Number of tables with only trivial components.
Definition stats.h:73
ecs_metric_t observer_count
Number of observers.
Definition stats.h:83
ecs_metric_t record_count
Number of table cache records.
Definition stats.h:74
ecs_metric_t pipeline_build_count
Number of system pipeline rebuilds (occurs when an inactive system becomes active).
Definition stats.h:107
ecs_metric_t stack_outstanding_alloc_count
Difference between allocs & frees.
Definition stats.h:139
ecs_metric_t block_alloc_count
Block allocations per frame.
Definition stats.h:134
ecs_metric_t delta_time
Delta_time.
Definition stats.h:123
ecs_metric_t pair_count
Number of pair ids.
Definition stats.h:61
flecs::system_builder< Components... > system(Args &&... args) const
Create a new system.
Make all metrics the same size, so we can iterate over fields.
Definition stats.h:42