Skip to content

Commit 7837410

Browse files
committed
Use 64bit counters for world/system statistics
1 parent f9f0c48 commit 7837410

File tree

6 files changed

+54
-46
lines changed

6 files changed

+54
-46
lines changed

flecs.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -15650,10 +15650,10 @@ typedef struct ecs_system_t {
1565015650
bool multi_threaded;
1565115651
bool no_staging;
1565215652

15653-
int32_t invoke_count; /* Number of times system is invoked */
15653+
int64_t invoke_count; /* Number of times system is invoked */
1565415654
float time_spent; /* Time spent on running system */
1565515655
ecs_ftime_t time_passed; /* Time passed since last invocation */
15656-
int32_t last_frame; /* Last frame for which the system was considered */
15656+
int64_t last_frame; /* Last frame for which the system was considered */
1565715657

1565815658
void *ctx; /* Userdata for system */
1565915659
void *binding_ctx; /* Optional language binding context */
@@ -15991,7 +15991,7 @@ bool ecs_worker_sync(
1599115991

1599215992
int32_t stage_count = ecs_get_stage_count(world);
1599315993
ecs_assert(stage_count != 0, ECS_INTERNAL_ERROR, NULL);
15994-
int32_t build_count = world->info.pipeline_build_count_total;
15994+
int64_t build_count = world->info.pipeline_build_count_total;
1599515995

1599615996
/* If there are no threads, merge in place */
1599715997
if (stage_count == 1) {
@@ -29481,6 +29481,10 @@ ecs_float_t flecs_counter_record(
2948129481
int32_t tp = t_prev(t);
2948229482
ecs_float_t prev = m->counter.value[tp];
2948329483
m->counter.value[t] = value;
29484+
ecs_float_t gauge_value = value - prev;
29485+
if (gauge_value < 0) {
29486+
gauge_value = 0; /* Counters are monotonically increasing */
29487+
}
2948429488
flecs_gauge_record(m, t, value - prev);
2948529489
return value - prev;
2948629490
}

flecs.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -4116,16 +4116,16 @@ typedef struct ecs_world_info_t {
41164116
ecs_ftime_t world_time_total; /* Time elapsed in simulation */
41174117
ecs_ftime_t world_time_total_raw; /* Time elapsed in simulation (no scaling) */
41184118

4119-
int32_t frame_count_total; /* Total number of frames */
4120-
int32_t merge_count_total; /* Total number of merges */
4119+
int64_t frame_count_total; /* Total number of frames */
4120+
int64_t merge_count_total; /* Total number of merges */
41214121

4122-
int32_t id_create_total; /* Total number of times a new id was created */
4123-
int32_t id_delete_total; /* Total number of times an id was deleted */
4124-
int32_t table_create_total; /* Total number of times a table was created */
4125-
int32_t table_delete_total; /* Total number of times a table was deleted */
4126-
int32_t pipeline_build_count_total; /* Total number of pipeline builds */
4127-
int32_t systems_ran_frame; /* Total number of systems ran in last frame */
4128-
int32_t observers_ran_frame; /* Total number of times observer was invoked */
4122+
int64_t id_create_total; /* Total number of times a new id was created */
4123+
int64_t id_delete_total; /* Total number of times an id was deleted */
4124+
int64_t table_create_total; /* Total number of times a table was created */
4125+
int64_t table_delete_total; /* Total number of times a table was deleted */
4126+
int64_t pipeline_build_count_total; /* Total number of pipeline builds */
4127+
int64_t systems_ran_frame; /* Total number of systems ran in last frame */
4128+
int64_t observers_ran_frame; /* Total number of times observer was invoked */
41294129

41304130
int32_t id_count; /* Number of ids in the world (excluding wildcards) */
41314131
int32_t tag_id_count; /* Number of tag (no data) ids in the world */
@@ -4142,17 +4142,17 @@ typedef struct ecs_world_info_t {
41424142

41434143
/* -- Command counts -- */
41444144
struct {
4145-
int32_t add_count; /* add commands processed */
4146-
int32_t remove_count; /* remove commands processed */
4147-
int32_t delete_count; /* delete commands processed */
4148-
int32_t clear_count; /* clear commands processed */
4149-
int32_t set_count; /* set commands processed */
4150-
int32_t get_mut_count; /* get_mut/emplace commands processed */
4151-
int32_t modified_count; /* modified commands processed */
4152-
int32_t other_count; /* other commands processed */
4153-
int32_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
4154-
int32_t batched_entity_count; /* entities for which commands were batched */
4155-
int32_t batched_command_count; /* commands batched */
4145+
int64_t add_count; /* add commands processed */
4146+
int64_t remove_count; /* remove commands processed */
4147+
int64_t delete_count; /* delete commands processed */
4148+
int64_t clear_count; /* clear commands processed */
4149+
int64_t set_count; /* set commands processed */
4150+
int64_t get_mut_count; /* get_mut/emplace commands processed */
4151+
int64_t modified_count; /* modified commands processed */
4152+
int64_t other_count; /* other commands processed */
4153+
int64_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
4154+
int64_t batched_entity_count; /* entities for which commands were batched */
4155+
int64_t batched_command_count; /* commands batched */
41564156
} cmd;
41574157

41584158
const char *name_prefix; /* Value set by ecs_set_name_prefix. Used

include/flecs.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -921,16 +921,16 @@ typedef struct ecs_world_info_t {
921921
ecs_ftime_t world_time_total; /* Time elapsed in simulation */
922922
ecs_ftime_t world_time_total_raw; /* Time elapsed in simulation (no scaling) */
923923

924-
int32_t frame_count_total; /* Total number of frames */
925-
int32_t merge_count_total; /* Total number of merges */
924+
int64_t frame_count_total; /* Total number of frames */
925+
int64_t merge_count_total; /* Total number of merges */
926926

927-
int32_t id_create_total; /* Total number of times a new id was created */
928-
int32_t id_delete_total; /* Total number of times an id was deleted */
929-
int32_t table_create_total; /* Total number of times a table was created */
930-
int32_t table_delete_total; /* Total number of times a table was deleted */
931-
int32_t pipeline_build_count_total; /* Total number of pipeline builds */
932-
int32_t systems_ran_frame; /* Total number of systems ran in last frame */
933-
int32_t observers_ran_frame; /* Total number of times observer was invoked */
927+
int64_t id_create_total; /* Total number of times a new id was created */
928+
int64_t id_delete_total; /* Total number of times an id was deleted */
929+
int64_t table_create_total; /* Total number of times a table was created */
930+
int64_t table_delete_total; /* Total number of times a table was deleted */
931+
int64_t pipeline_build_count_total; /* Total number of pipeline builds */
932+
int64_t systems_ran_frame; /* Total number of systems ran in last frame */
933+
int64_t observers_ran_frame; /* Total number of times observer was invoked */
934934

935935
int32_t id_count; /* Number of ids in the world (excluding wildcards) */
936936
int32_t tag_id_count; /* Number of tag (no data) ids in the world */
@@ -947,17 +947,17 @@ typedef struct ecs_world_info_t {
947947

948948
/* -- Command counts -- */
949949
struct {
950-
int32_t add_count; /* add commands processed */
951-
int32_t remove_count; /* remove commands processed */
952-
int32_t delete_count; /* delete commands processed */
953-
int32_t clear_count; /* clear commands processed */
954-
int32_t set_count; /* set commands processed */
955-
int32_t get_mut_count; /* get_mut/emplace commands processed */
956-
int32_t modified_count; /* modified commands processed */
957-
int32_t other_count; /* other commands processed */
958-
int32_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
959-
int32_t batched_entity_count; /* entities for which commands were batched */
960-
int32_t batched_command_count; /* commands batched */
950+
int64_t add_count; /* add commands processed */
951+
int64_t remove_count; /* remove commands processed */
952+
int64_t delete_count; /* delete commands processed */
953+
int64_t clear_count; /* clear commands processed */
954+
int64_t set_count; /* set commands processed */
955+
int64_t get_mut_count; /* get_mut/emplace commands processed */
956+
int64_t modified_count; /* modified commands processed */
957+
int64_t other_count; /* other commands processed */
958+
int64_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
959+
int64_t batched_entity_count; /* entities for which commands were batched */
960+
int64_t batched_command_count; /* commands batched */
961961
} cmd;
962962

963963
const char *name_prefix; /* Value set by ecs_set_name_prefix. Used

src/addons/pipeline/worker.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool ecs_worker_sync(
215215

216216
int32_t stage_count = ecs_get_stage_count(world);
217217
ecs_assert(stage_count != 0, ECS_INTERNAL_ERROR, NULL);
218-
int32_t build_count = world->info.pipeline_build_count_total;
218+
int64_t build_count = world->info.pipeline_build_count_total;
219219

220220
/* If there are no threads, merge in place */
221221
if (stage_count == 1) {

src/addons/stats.c

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ ecs_float_t flecs_counter_record(
5757
int32_t tp = t_prev(t);
5858
ecs_float_t prev = m->counter.value[tp];
5959
m->counter.value[t] = value;
60+
ecs_float_t gauge_value = value - prev;
61+
if (gauge_value < 0) {
62+
gauge_value = 0; /* Counters are monotonically increasing */
63+
}
6064
flecs_gauge_record(m, t, value - prev);
6165
return value - prev;
6266
}

src/addons/system/system.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ typedef struct ecs_system_t {
2424
bool multi_threaded;
2525
bool no_staging;
2626

27-
int32_t invoke_count; /* Number of times system is invoked */
27+
int64_t invoke_count; /* Number of times system is invoked */
2828
float time_spent; /* Time spent on running system */
2929
ecs_ftime_t time_passed; /* Time passed since last invocation */
30-
int32_t last_frame; /* Last frame for which the system was considered */
30+
int64_t last_frame; /* Last frame for which the system was considered */
3131

3232
void *ctx; /* Userdata for system */
3333
void *binding_ctx; /* Optional language binding context */

0 commit comments

Comments
 (0)