X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=eb3e7a0f6ba58faa9b0b105fe46edcf9d3edcf1f;hb=2ad9cd3aeb8b97f1cb869dd70f26abd0f7468a81;hp=41b68190559a73a7eae920ee3e1a472000197120;hpb=db0cf963a41d958dc11ee1d3cfb2b1f88cba7f76;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 41b68190..eb3e7a0f 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -2805,10 +2805,46 @@ void NotifyUserAboutErrorFile() #if DEBUG -#define DEBUG_NUM_TIMESTAMPS 3 +#define DEBUG_NUM_TIMESTAMPS 3 +#define DEBUG_TIME_IN_MICROSECONDS 0 + +#if DEBUG_TIME_IN_MICROSECONDS +static double Counter_Microseconds() +{ + static struct timeval base_time = { 0, 0 }; + struct timeval current_time; + double counter; + + gettimeofday(¤t_time, NULL); + + /* reset base time in case of wrap-around */ + if (current_time.tv_sec < base_time.tv_sec) + base_time = current_time; + + counter = + ((double)(current_time.tv_sec - base_time.tv_sec)) * 1000000 + + ((double)(current_time.tv_usec - base_time.tv_usec)); + + return counter; /* return microseconds since last init */ +} +#endif void debug_print_timestamp(int counter_nr, char *message) { +#if DEBUG_TIME_IN_MICROSECONDS + static double counter[DEBUG_NUM_TIMESTAMPS][2]; + + if (counter_nr >= DEBUG_NUM_TIMESTAMPS) + Error(ERR_EXIT, "debugging: increase DEBUG_NUM_TIMESTAMPS in misc.c"); + + counter[counter_nr][0] = Counter_Microseconds(); + + if (message) + printf("%s %.3f ms\n", message, + (counter[counter_nr][0] - counter[counter_nr][1]) / 1000); + + counter[counter_nr][1] = counter[counter_nr][0]; +#else static long counter[DEBUG_NUM_TIMESTAMPS][2]; if (counter_nr >= DEBUG_NUM_TIMESTAMPS) @@ -2817,10 +2853,11 @@ void debug_print_timestamp(int counter_nr, char *message) counter[counter_nr][0] = Counter(); if (message) - printf("%s %.3f seconds\n", message, + printf("%s %.3f s\n", message, (float)(counter[counter_nr][0] - counter[counter_nr][1]) / 1000); counter[counter_nr][1] = counter[counter_nr][0]; +#endif } void debug_print_parent_only(char *format, ...)