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).
This commit is contained in:
Dudemanguy 2023-09-29 18:20:30 -05:00
parent 0ba6ca6f76
commit 84fa7ea411
2 changed files with 4 additions and 4 deletions

View File

@ -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);

View File

@ -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)