mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 15:26:37 +02:00
core: add function util_get_microseconds_string
This commit is contained in:
+10
-10
@@ -736,29 +736,29 @@ debug_display_time_elapsed (struct timeval *time1, struct timeval *time2,
|
||||
const char *message, int display)
|
||||
{
|
||||
struct timeval debug_timeval_end;
|
||||
long long diff, diff_hour, diff_min, diff_sec, diff_usec;
|
||||
char *str_diff;
|
||||
long long diff;
|
||||
|
||||
gettimeofday (&debug_timeval_end, NULL);
|
||||
diff = util_timeval_diff (time1, time2);
|
||||
|
||||
diff_usec = diff % 1000000;
|
||||
diff_sec = (diff / 1000000) % 60;
|
||||
diff_min = ((diff / 1000000) / 60) % 60;
|
||||
diff_hour = (diff / 1000000) / 3600;
|
||||
str_diff = util_get_microseconds_string (diff);
|
||||
|
||||
if (display)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
"debug: time[%s] -> %lld:%02lld:%02lld.%06lld",
|
||||
"debug: time[%s] -> %s",
|
||||
(message) ? message : "?",
|
||||
diff_hour, diff_min, diff_sec, diff_usec);
|
||||
(str_diff) ? str_diff : "?");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_printf ("debug: time[%s] -> %lld:%02lld:%02lld.%06lld",
|
||||
log_printf ("debug: time[%s] -> %s",
|
||||
(message) ? message : "?",
|
||||
diff_hour, diff_min, diff_sec, diff_usec);
|
||||
(str_diff) ? str_diff : "?");
|
||||
}
|
||||
|
||||
if (str_diff)
|
||||
free (str_diff);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -285,6 +285,31 @@ util_timeval_add (struct timeval *tv, long long interval)
|
||||
tv->tv_usec = usec;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts microseconds to a string, using format: "H:MM:SS.mmmmmm"
|
||||
* where: H=hours, MM=minutes, SS=seconds, mmmmmm=microseconds
|
||||
*
|
||||
* Note: result must be freed after use.
|
||||
*/
|
||||
|
||||
char *
|
||||
util_get_microseconds_string (long long microseconds)
|
||||
{
|
||||
long long hour, min, sec, usec;
|
||||
char result[128];
|
||||
|
||||
usec = microseconds % 1000000;
|
||||
sec = (microseconds / 1000000) % 60;
|
||||
min = ((microseconds / 1000000) / 60) % 60;
|
||||
hour = (microseconds / 1000000) / 3600;
|
||||
|
||||
snprintf (result, sizeof (result),
|
||||
"%lld:%02lld:%02lld.%06lld",
|
||||
hour, min, sec, usec);
|
||||
|
||||
return strdup (result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts date to a string, using format of option "weechat.look.time_format"
|
||||
* (can be localized).
|
||||
|
||||
@@ -40,6 +40,7 @@ extern long long util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
extern void util_timeval_add (struct timeval *tv, long long interval);
|
||||
|
||||
/* time */
|
||||
extern char *util_get_microseconds_string (long long diff);
|
||||
extern const char *util_get_time_string (const time_t *date);
|
||||
extern void util_get_time_diff (time_t time1, time_t time2,
|
||||
time_t *total_seconds,
|
||||
|
||||
Reference in New Issue
Block a user