From d89111fb0ed471197f83ef380351c86984fe0529 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 11 Nov 2020 21:28:07 +0100 Subject: [PATCH] debuginfod-find: Be a bit less verbose with -v 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 --- debuginfod/ChangeLog | 5 +++++ debuginfod/debuginfod-find.c | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index a02643e17..d4face2d1 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2020-11-11 Mark Wielaard + + * debuginfod-find.c (progressfn): Use clock_gettime to print Progress + at most 5 times a second. + 2020-11-01 Érico N. Rolim * debuginfod-client.c (debuginfod_init_cache): Use ACCESSPERMS for diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c index 88a460f83..5f9bccc38 100644 --- a/debuginfod/debuginfod-find.c +++ b/debuginfod/debuginfod-find.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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; } -- 2.47.3