diff mbox series

[FFmpeg-devel,v4,2/2] fftools: Add option to log timing

Message ID MN2PR04MB598112607A82DE2306D8A77EBAF69@MN2PR04MB5981.namprd04.prod.outlook.com
State Superseded, archived
Headers show
Series [FFmpeg-devel,v4,1/2] libavutil/log: Add capability to prefix loglines with current time or current date+time | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Soft Works Aug. 9, 2021, 2:16 a.m. UTC
This commit adds two logging flags: 'timing' and 'datetiming'.

Usage:

ffmpeg -loglevel +timing

or

ffmpeg -loglevel +datetiming

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/fftools-common-opts.texi |  4 ++++
 fftools/cmdutils.c           | 14 ++++++++++++++
 fftools/ffmpeg.c             |  6 +++++-
 3 files changed, 23 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 7643dd8396..483a50d8e9 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -198,6 +198,10 @@  and the "Last message repeated n times" line will be omitted.
 Indicates that log output should add a @code{[level]} prefix to each message
 line. This can be used as an alternative to log coloring, e.g. when dumping the
 log to file.
+@item timing
+Prefixes each log line with the current time.
+@item datetiming
+Same as timing but also prints the current date in each line.
 @end table
 Flags can also be used alone by adding a '+'/'-' prefix to set/reset a single
 flag without affecting other @var{flags} or changing @var{loglevel}. When
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index f5e39f616f..72fc67fc3e 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -919,6 +919,20 @@  int opt_loglevel(void *optctx, const char *opt, const char *arg)
                 flags |= AV_LOG_PRINT_LEVEL;
             }
             arg = token + 5;
+        } else if (av_strstart(token, "timing", NULL)) {
+            if (cmd == '-') {
+                flags &= ~AV_LOG_PRINT_TIME;
+            } else {
+                flags |= AV_LOG_PRINT_TIME;
+            }
+            arg = token + 6;
+        } else if (av_strstart(token, "datetiming", NULL)) {
+            if (cmd == '-') {
+                flags &= ~AV_LOG_PRINT_DATETIME;
+            } else {
+                flags |= AV_LOG_PRINT_DATETIME;
+            }
+            arg = token + 10;
         } else {
             break;
         }
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b0ce7c7c32..b0b105be1c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4983,7 +4983,7 @@  static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
 
 int main(int argc, char **argv)
 {
-    int i, ret;
+    int i, ret, log_flags;
     BenchmarkTimeStamps ti;
 
     init_dynload();
@@ -5049,6 +5049,10 @@  int main(int argc, char **argv)
     if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
         exit_program(69);
 
+    log_flags = av_log_get_flags();
+    if (log_flags & AV_LOG_PRINT_TIME || log_flags & AV_LOG_PRINT_DATETIME)
+        av_log(NULL, AV_LOG_INFO, "\n"); /* end with line break to avoid mixing up with shell prompt */
+
     exit_program(received_nb_signals ? 255 : main_return_code);
     return main_return_code;
 }