summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-09-29 18:20:30 -0500
committerDudemanguy <random342@airmail.cc>2023-09-29 18:20:30 -0500
commit84fa7ea411e8e99fced66295c973ecdf94ee07b2 (patch)
tree82bce7e6217aba91ab0bc7b401f66d43ba87ca6c
parent0ba6ca6f76a0ed90b8f1bac6406a2b4e92dfe64f (diff)
downloadmpv-84fa7ea411e8e99fced66295c973ecdf94ee07b2.tar.bz2
mpv-84fa7ea411e8e99fced66295c973ecdf94ee07b2.tar.xz
msg: use nanosecond precision
The timestamps when making a log file is actually dependent on MP_START_TIME. This is a 10 microsecond offset that was added to the timer as an offset. With the nanosecond change, this unit needs to be converted as well so the offset is the same as before. After doing that, we need to change the various mp_time_us calls in msg to mp_time_ns and do the right conversion. This fixes the logs timestamps (i.e. so they aren't negative anymore).
-rw-r--r--common/msg.c6
-rw-r--r--osdep/timer.h2
2 files changed, 4 insertions, 4 deletions
diff --git a/common/msg.c b/common/msg.c
index d1128c71bd..2dc4c1e7c2 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -316,7 +316,7 @@ static void print_terminal_line(struct mp_log *log, int lev,
set_msg_color(stream, lev);
if (root->show_time)
- fprintf(stream, "[%10.6f] ", (mp_time_us() - MP_START_TIME) / 1e6);
+ fprintf(stream, "[%10.6f] ", (mp_time_ns() - MP_START_TIME) / 1e9);
const char *prefix = log->prefix;
if ((lev >= MSGL_V) || root->verbose || root->module)
@@ -405,7 +405,7 @@ static void dump_stats(struct mp_log *log, int lev, char *text)
{
struct mp_log_root *root = log->root;
if (lev == MSGL_STATS && root->stats_file)
- fprintf(root->stats_file, "%"PRId64" %s\n", mp_time_us(), text);
+ fprintf(root->stats_file, "%"PRId64" %s\n", mp_time_ns(), text);
}
void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va)
@@ -551,7 +551,7 @@ static void *log_file_thread(void *p)
if (e) {
pthread_mutex_unlock(&root->log_file_lock);
fprintf(root->log_file, "[%8.3f][%c][%s] %s",
- (mp_time_us() - MP_START_TIME) / 1e6,
+ (mp_time_ns() - MP_START_TIME) / 1e9,
mp_log_levels[e->level][0], e->prefix, e->text);
fflush(root->log_file);
pthread_mutex_lock(&root->log_file_lock);
diff --git a/osdep/timer.h b/osdep/timer.h
index 546d8fab41..d76ad16129 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -48,7 +48,7 @@ int mp_start_hires_timers(int wait_ms);
void mp_end_hires_timers(int resolution_ms);
#endif /* _WIN32 */
-#define MP_START_TIME 10000000
+#define MP_START_TIME 10 * INT64_C(1000000000)
// Duration of a second in mpv time.
#define MP_SECOND_US (1000 * 1000)