twn_util_c.h: internal profiling api
This commit is contained in:
parent
4b0d584b7e
commit
26a2bf293f
@ -9,6 +9,14 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
static struct ProfileItem {
|
||||
char const *key;
|
||||
struct Profile {
|
||||
uint64_t tick;
|
||||
} value;
|
||||
} *profiles;
|
||||
|
||||
|
||||
void cry_impl(const char *file, const int line, const char *title, const char *text) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"TEARS AT %s:%d: %s ... %s", file, line, title, text);
|
||||
@ -287,3 +295,19 @@ char *expand_asterisk(const char *mask, const char *to) {
|
||||
SDL_memcpy(str + (offset - mask) + to_len, offset + 1, mask_len - (offset - mask));
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
void profile_start(char profile[const static 1]) {
|
||||
shput(profiles, profile, (struct Profile){ .tick = SDL_GetPerformanceCounter() });
|
||||
}
|
||||
|
||||
|
||||
void profile_end(char profile[const static 1]) {
|
||||
struct ProfileItem *p = shgetp_null(profiles, profile);
|
||||
if (!p) {
|
||||
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);
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ _Noreturn void die_abruptly(void);
|
||||
/* note: you must free the returned string */
|
||||
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]);
|
||||
|
||||
/* http://www.azillionmonkeys.com/qed/sqroot.html */
|
||||
static inline float fast_sqrt(float x)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user