twn_util_c.h: profile_list_stats() for average summary, without spam in console
This commit is contained in:
parent
26a2bf293f
commit
2f94e17852
@ -788,6 +788,8 @@ int enter_loop(int argc, char **argv) {
|
||||
main_loop();
|
||||
}
|
||||
|
||||
profile_list_stats();
|
||||
|
||||
/* loop is over */
|
||||
game_object_unload();
|
||||
|
||||
|
@ -12,7 +12,9 @@
|
||||
static struct ProfileItem {
|
||||
char const *key;
|
||||
struct Profile {
|
||||
uint64_t tick;
|
||||
uint64_t tick_start;
|
||||
uint64_t tick_accum;
|
||||
uint64_t sample_count;
|
||||
} value;
|
||||
} *profiles;
|
||||
|
||||
@ -298,7 +300,19 @@ char *expand_asterisk(const char *mask, const char *to) {
|
||||
|
||||
|
||||
void profile_start(char profile[const static 1]) {
|
||||
shput(profiles, profile, (struct Profile){ .tick = SDL_GetPerformanceCounter() });
|
||||
uint64_t tick_accum = 0, sample_count = 0;
|
||||
|
||||
struct ProfileItem const *p = shgetp_null(profiles, profile);
|
||||
if (p) {
|
||||
tick_accum = p->value.tick_accum;
|
||||
sample_count = p->value.sample_count;
|
||||
}
|
||||
|
||||
shput(profiles, profile, ((struct Profile) {
|
||||
.tick_start = SDL_GetPerformanceCounter(),
|
||||
.tick_accum = tick_accum,
|
||||
.sample_count = sample_count,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@ -308,6 +322,18 @@ void profile_end(char profile[const static 1]) {
|
||||
log_warn("profile %s wasn't started!", profile);
|
||||
return;
|
||||
}
|
||||
log_info("profile '%s' took: %fsec", profile, (double)(SDL_GetPerformanceCounter() - p->value.tick) / (double)(SDL_GetPerformanceFrequency()));
|
||||
shdel(profiles, profile);
|
||||
|
||||
p->value.sample_count++;
|
||||
p->value.tick_accum += SDL_GetPerformanceCounter() - p->value.tick_start;
|
||||
}
|
||||
|
||||
|
||||
void profile_list_stats(void) {
|
||||
for (size_t i = 0; i < shlenu(profiles); ++i) {
|
||||
log_info("profile '%s' on average took: %f seconds",
|
||||
profiles[i].key,
|
||||
(double)profiles[i].value.tick_accum /
|
||||
(double)profiles[i].value.sample_count /
|
||||
(double)(SDL_GetPerformanceFrequency()));
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ char *expand_asterisk(const char *mask, const char *to);
|
||||
|
||||
void profile_start(char profile[const static 1]);
|
||||
void profile_end(char profile[const static 1]);
|
||||
void profile_list_stats(void);
|
||||
|
||||
/* http://www.azillionmonkeys.com/qed/sqroot.html */
|
||||
static inline float fast_sqrt(float x)
|
||||
|
Loading…
Reference in New Issue
Block a user