]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod-find: Be a bit less verbose with -v
authorMark Wielaard <mark@klomp.org>
Wed, 11 Nov 2020 20:28:07 +0000 (21:28 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 17 Nov 2020 13:36:37 +0000 (14:36 +0100)
debuginfod-find -v enables a progressfn that prints the Progress every
time the callback is called. For slow transfers or big downloads this
can be really verbose (hundreds a times a second). Slow it down a bit,
so it only prints the progress at most 5 times a second.

Signed-off-by: Mark Wielaard <mark@klomp.org>
debuginfod/ChangeLog
debuginfod/debuginfod-find.c

index a02643e17b7d856510045bd54a22d434db68795a..d4face2d1c3fb28a9c5c7215b806c4549c6c122f 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-11  Mark Wielaard  <mark@klomp.org>
+
+       * debuginfod-find.c (progressfn): Use clock_gettime to print Progress
+       at most 5 times a second.
+
 2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
 
        * debuginfod-client.c (debuginfod_init_cache): Use ACCESSPERMS for
index 88a460f83d30bd9d8e58c822e703e3126045dccd..5f9bccc388a7aecbde517a48a5e994168cf1dea1 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <argp.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -64,7 +65,28 @@ static int verbose;
 int progressfn(debuginfod_client *c __attribute__((__unused__)),
               long a, long b)
 {
-  fprintf (stderr, "Progress %ld / %ld\n", a, b);
+  static bool first = true;
+  static struct timespec last;
+  struct timespec now;
+  uint64_t delta;
+  if (!first)
+    {
+      clock_gettime (CLOCK_MONOTONIC, &now);
+      delta = ((now.tv_sec - last.tv_sec) * 1000000
+              + (now.tv_nsec - last.tv_nsec) / 1000);
+    }
+  else
+    {
+      first = false;
+      delta = 250000;
+    }
+
+  /* Show progress the first time and then at most 5 times a second. */
+  if (delta > 200000)
+    {
+      fprintf (stderr, "Progress %ld / %ld\n", a, b);
+      clock_gettime (CLOCK_MONOTONIC, &last);
+    }
   return 0;
 }