Skip to content

Commit

Permalink
Add new command line argument "-log_ms" which includes milliseconds
Browse files Browse the repository at this point in the history
For debugging of high frequency events (e.g. decklink output), we want
a higher resolution timestamp on log events.  Add a command line
option which can be optionally enabled which includes the higher
precision.
  • Loading branch information
dheitmueller committed Dec 23, 2020
1 parent eab9b0a commit 3c4a546
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions fftools/cmdutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static FILE *report_file;
static int report_file_level = AV_LOG_DEBUG;
int hide_banner = 0;
char *log_filename = NULL;
int log_ms = 0;

enum show_muxdemuxers {
SHOW_DEFAULT,
Expand Down Expand Up @@ -536,6 +537,9 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options)
idx = locate_option(argc, argv, options, "logfile");
if (idx && argv[idx + 1])
log_filename = strdup(argv[idx + 1]);

if (locate_option(argc, argv, options, "log_ms"))
log_ms = 1;
}

static const AVOption *opt_find(void *obj, const char *name, const char *unit,
Expand Down
2 changes: 2 additions & 0 deletions fftools/cmdutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern AVDictionary *swr_opts;
extern AVDictionary *format_opts, *codec_opts, *resample_opts;
extern int hide_banner;
extern char *log_filename;
extern int log_ms;

/**
* Register a program-specific cleanup routine.
Expand Down Expand Up @@ -236,6 +237,7 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags,
{ "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" }, \
{ "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \
{ "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
{ "log_ms", OPT_BOOL | OPT_EXPERT, { &log_ms }, "show millisecond timestamps", "log_ms" }, \
{ "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
{ "report", 0, { (void*)opt_report }, "generate a report" }, \
{ "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
Expand Down
14 changes: 11 additions & 3 deletions fftools/ltndecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4978,9 +4978,17 @@ static void log_callback_ltn(void *ptr, int level, const char *fmt, va_list vl)
ff_mutex_lock(&log_mutex);
time(&now);
timeinfo = localtime(&now);
if (print_prefix == 1)
strftime(line2, sizeof(line2), "%F %T ", timeinfo);
else

if (print_prefix == 1) {
if (log_ms == 1) {
char dt[64];
gettimeofday(&tv,NULL);
strftime(dt, sizeof(dt), "%F %T", timeinfo);
snprintf(line2, sizeof(line2), "%s (%d.%06d) ", dt, tv.tv_sec, tv.tv_usec);
} else {
strftime(line2, sizeof(line2), "%F %T ", timeinfo);
}
} else
line2[0] = '\0';

av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
Expand Down

0 comments on commit 3c4a546

Please sign in to comment.