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
189
191typedef struct ecs_system_stats_t {
192 int64_t first_;
195 int64_t last_;
196
197 bool task;
199 ecs_query_stats_t query;
201
203typedef struct ecs_sync_stats_t {
204 int64_t first_;
205 ecs_metric_t time_spent;
206 ecs_metric_t commands_enqueued;
207 int64_t last_;
208
209 int32_t system_count;
210 bool multi_threaded;
211 bool no_readonly;
213
215typedef struct ecs_pipeline_stats_t {
216 /* Allow for initializing struct with {0} */
217 int8_t canary_;
218
221 ecs_vec_t systems;
222
224 ecs_vec_t sync_points;
225
228 ecs_map_t system_stats;
229
231 int32_t t;
232
233 int32_t system_count;
237
243FLECS_API
245 const ecs_world_t *world,
246 ecs_world_stats_t *stats);
247
249FLECS_API
252 const ecs_world_stats_t *src);
253
255FLECS_API
257 ecs_world_stats_t *stats,
258 const ecs_world_stats_t *old,
259 int32_t count);
260
262FLECS_API
264 ecs_world_stats_t *stats);
265
267FLECS_API
270 const ecs_world_stats_t *src);
271
272FLECS_API
273void ecs_world_stats_log(
274 const ecs_world_t *world,
275 const ecs_world_stats_t *stats);
276
284FLECS_API
286 const ecs_world_t *world,
287 const ecs_query_t *query,
288 ecs_query_stats_t *stats);
289
291FLECS_API
294 const ecs_query_stats_t *src);
295
297FLECS_API
299 ecs_query_stats_t *stats,
300 const ecs_query_stats_t *old,
301 int32_t count);
302
304FLECS_API
306 ecs_query_stats_t *stats);
307
309FLECS_API
312 const ecs_query_stats_t *src);
313
314#ifdef FLECS_SYSTEM
323FLECS_API
325 const ecs_world_t *world,
327 ecs_system_stats_t *stats);
328
330FLECS_API
333 const ecs_system_stats_t *src);
334
336FLECS_API
338 ecs_system_stats_t *stats,
339 const ecs_system_stats_t *old,
340 int32_t count);
341
343FLECS_API
345 ecs_system_stats_t *stats);
346
348FLECS_API
351 const ecs_system_stats_t *src);
352#endif
353
354#ifdef FLECS_PIPELINE
363FLECS_API
365 ecs_world_t *world,
367 ecs_pipeline_stats_t *stats);
368
373FLECS_API
375 ecs_pipeline_stats_t *stats);
376
378FLECS_API
381 const ecs_pipeline_stats_t *src);
382
384FLECS_API
387 const ecs_pipeline_stats_t *old,
388 int32_t count);
389
391FLECS_API
393 ecs_pipeline_stats_t *stats);
394
402FLECS_API
405 const ecs_pipeline_stats_t *src);
406
407#endif
408
410FLECS_API
412 ecs_metric_t *dst,
413 const ecs_metric_t *src,
414 int32_t t_dst,
415 int32_t t_src);
416
418FLECS_API
420 ecs_metric_t *m,
421 int32_t t,
422 int32_t count);
423
425FLECS_API
427 ecs_metric_t *m,
428 int32_t dst,
429 int32_t src);
430
431#ifdef __cplusplus
432}
433#endif
434
435#endif
436
439#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:288
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:332
struct ecs_query_t ecs_query_t
A query that caches its results.
Definition flecs.h:364
#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:215
ecs_map_t system_stats
Map with system statistics.
Definition stats.h:228
int32_t rebuild_count
Number of times pipeline has rebuilt.
Definition stats.h:235
int32_t system_count
Number of systems in pipeline.
Definition stats.h:233
ecs_vec_t systems
Vector with system ids of all systems in the pipeline.
Definition stats.h:221
int32_t active_system_count
Number of active systems in pipeline.
Definition stats.h:234
ecs_vec_t sync_points
Vector with sync point stats.
Definition stats.h:224
int32_t t
Current position in ringbuffer.
Definition stats.h:231
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 sync point.
Definition stats.h:203
Statistics for a single system (use ecs_system_stats_get)
Definition stats.h:191
ecs_metric_t invoke_count
Number of times system is invoked.
Definition stats.h:194
bool task
Is system a task.
Definition stats.h:197
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