Skip to content

Commit

Permalink
Use 64bit counters for world/system statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 10, 2022
1 parent f9f0c48 commit 7837410
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 46 deletions.
10 changes: 7 additions & 3 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15650,10 +15650,10 @@ typedef struct ecs_system_t {
bool multi_threaded;
bool no_staging;

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

void *ctx; /* Userdata for system */
void *binding_ctx; /* Optional language binding context */
Expand Down Expand Up @@ -15991,7 +15991,7 @@ bool ecs_worker_sync(

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

/* If there are no threads, merge in place */
if (stage_count == 1) {
Expand Down Expand Up @@ -29481,6 +29481,10 @@ ecs_float_t flecs_counter_record(
int32_t tp = t_prev(t);
ecs_float_t prev = m->counter.value[tp];
m->counter.value[t] = value;
ecs_float_t gauge_value = value - prev;
if (gauge_value < 0) {
gauge_value = 0; /* Counters are monotonically increasing */
}
flecs_gauge_record(m, t, value - prev);
return value - prev;
}
Expand Down
40 changes: 20 additions & 20 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4116,16 +4116,16 @@ typedef struct ecs_world_info_t {
ecs_ftime_t world_time_total; /* Time elapsed in simulation */
ecs_ftime_t world_time_total_raw; /* Time elapsed in simulation (no scaling) */

int32_t frame_count_total; /* Total number of frames */
int32_t merge_count_total; /* Total number of merges */
int64_t frame_count_total; /* Total number of frames */
int64_t merge_count_total; /* Total number of merges */

int32_t id_create_total; /* Total number of times a new id was created */
int32_t id_delete_total; /* Total number of times an id was deleted */
int32_t table_create_total; /* Total number of times a table was created */
int32_t table_delete_total; /* Total number of times a table was deleted */
int32_t pipeline_build_count_total; /* Total number of pipeline builds */
int32_t systems_ran_frame; /* Total number of systems ran in last frame */
int32_t observers_ran_frame; /* Total number of times observer was invoked */
int64_t id_create_total; /* Total number of times a new id was created */
int64_t id_delete_total; /* Total number of times an id was deleted */
int64_t table_create_total; /* Total number of times a table was created */
int64_t table_delete_total; /* Total number of times a table was deleted */
int64_t pipeline_build_count_total; /* Total number of pipeline builds */
int64_t systems_ran_frame; /* Total number of systems ran in last frame */
int64_t observers_ran_frame; /* Total number of times observer was invoked */

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

/* -- Command counts -- */
struct {
int32_t add_count; /* add commands processed */
int32_t remove_count; /* remove commands processed */
int32_t delete_count; /* delete commands processed */
int32_t clear_count; /* clear commands processed */
int32_t set_count; /* set commands processed */
int32_t get_mut_count; /* get_mut/emplace commands processed */
int32_t modified_count; /* modified commands processed */
int32_t other_count; /* other commands processed */
int32_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
int32_t batched_entity_count; /* entities for which commands were batched */
int32_t batched_command_count; /* commands batched */
int64_t add_count; /* add commands processed */
int64_t remove_count; /* remove commands processed */
int64_t delete_count; /* delete commands processed */
int64_t clear_count; /* clear commands processed */
int64_t set_count; /* set commands processed */
int64_t get_mut_count; /* get_mut/emplace commands processed */
int64_t modified_count; /* modified commands processed */
int64_t other_count; /* other commands processed */
int64_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
int64_t batched_entity_count; /* entities for which commands were batched */
int64_t batched_command_count; /* commands batched */
} cmd;

const char *name_prefix; /* Value set by ecs_set_name_prefix. Used
Expand Down
40 changes: 20 additions & 20 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,16 @@ typedef struct ecs_world_info_t {
ecs_ftime_t world_time_total; /* Time elapsed in simulation */
ecs_ftime_t world_time_total_raw; /* Time elapsed in simulation (no scaling) */

int32_t frame_count_total; /* Total number of frames */
int32_t merge_count_total; /* Total number of merges */
int64_t frame_count_total; /* Total number of frames */
int64_t merge_count_total; /* Total number of merges */

int32_t id_create_total; /* Total number of times a new id was created */
int32_t id_delete_total; /* Total number of times an id was deleted */
int32_t table_create_total; /* Total number of times a table was created */
int32_t table_delete_total; /* Total number of times a table was deleted */
int32_t pipeline_build_count_total; /* Total number of pipeline builds */
int32_t systems_ran_frame; /* Total number of systems ran in last frame */
int32_t observers_ran_frame; /* Total number of times observer was invoked */
int64_t id_create_total; /* Total number of times a new id was created */
int64_t id_delete_total; /* Total number of times an id was deleted */
int64_t table_create_total; /* Total number of times a table was created */
int64_t table_delete_total; /* Total number of times a table was deleted */
int64_t pipeline_build_count_total; /* Total number of pipeline builds */
int64_t systems_ran_frame; /* Total number of systems ran in last frame */
int64_t observers_ran_frame; /* Total number of times observer was invoked */

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

/* -- Command counts -- */
struct {
int32_t add_count; /* add commands processed */
int32_t remove_count; /* remove commands processed */
int32_t delete_count; /* delete commands processed */
int32_t clear_count; /* clear commands processed */
int32_t set_count; /* set commands processed */
int32_t get_mut_count; /* get_mut/emplace commands processed */
int32_t modified_count; /* modified commands processed */
int32_t other_count; /* other commands processed */
int32_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
int32_t batched_entity_count; /* entities for which commands were batched */
int32_t batched_command_count; /* commands batched */
int64_t add_count; /* add commands processed */
int64_t remove_count; /* remove commands processed */
int64_t delete_count; /* delete commands processed */
int64_t clear_count; /* clear commands processed */
int64_t set_count; /* set commands processed */
int64_t get_mut_count; /* get_mut/emplace commands processed */
int64_t modified_count; /* modified commands processed */
int64_t other_count; /* other commands processed */
int64_t discard_count; /* commands discarded, happens when entity is no longer alive when running the command */
int64_t batched_entity_count; /* entities for which commands were batched */
int64_t batched_command_count; /* commands batched */
} cmd;

const char *name_prefix; /* Value set by ecs_set_name_prefix. Used
Expand Down
2 changes: 1 addition & 1 deletion src/addons/pipeline/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ bool ecs_worker_sync(

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

/* If there are no threads, merge in place */
if (stage_count == 1) {
Expand Down
4 changes: 4 additions & 0 deletions src/addons/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ ecs_float_t flecs_counter_record(
int32_t tp = t_prev(t);
ecs_float_t prev = m->counter.value[tp];
m->counter.value[t] = value;
ecs_float_t gauge_value = value - prev;
if (gauge_value < 0) {
gauge_value = 0; /* Counters are monotonically increasing */
}
flecs_gauge_record(m, t, value - prev);
return value - prev;
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/system/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ typedef struct ecs_system_t {
bool multi_threaded;
bool no_staging;

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

void *ctx; /* Userdata for system */
void *binding_ctx; /* Optional language binding context */
Expand Down

0 comments on commit 7837410

Please sign in to comment.