Re: [PATCH] gdb: print size of downloaded debuginfod binary

Tom de Vries
2020-12-11T17:54:48Z

[-- Attachment #1: Type: text/plain, Size: 996 bytes --]

On 12/11/20 6:51 PM, Tom de Vries wrote:
> On 12/10/20 8:21 PM, Tom Tromey wrote:
>> Tom> This updated patch fixes both problems, the latter by printing the %
>> Tom> progress on its own line (which is cleared by a final '\r' after
>> Tom> reaching 100%, in order not to waste lines on this).
>>
>> A long time ago I had patches to show a progress bar when reading DWARF.
>>
>> https://sourceware.org/pipermail/gdb-patches/2017-April/139882.html
>>
>> Maybe this could be resurrected.
>> I've occasionally thought of adding this to the TUI as well, say briefly
>> overwriting the status bar with a progress meter.
>
> I've taken a look, and think that this code is more in line with gdb cli
> setup, so I've reimplemented on top of this.
>
> Here is the first patch, adding the progress meter infrastructure
> factored out from your patch.

And here's the reimplemented patch.

I've test-driven it a bit on tumbleweed, and behaviour looks ok.

Currently testing on x86_64-linux.

Thanks,
- Tom

[-- Attachment #2: 0002-gdb-Print-progress-for-debuginfod.patch --]
[-- Type: text/x-patch, Size: 2386 bytes --]

[gdb] Print progress for debuginfod

Prints progress like:

Downloading 4.89 MB separate debug info for /usr/lib64/libgcrypt.so.20.
Downloading 1.10 MB separate debug info for /usr/lib64/liblzma.so.5.
Downloading 1.31 MB separate debug info for /usr/lib64/liblz4.so.1.
Downloading 0.96 MB separate debug info for /usr/lib64/libsmime3.so.
[### ]

Tested on x86_64-linux.

ChangeLog:

2020-12-10 Martin Liska <mliska@suse.cz>
Tom de Vries <tdevries@suse.de>

* gdb/debuginfod-support.c (struct user_data): Remove has_printed
field. Add meter field.
(progressfn): Print progress using meter.

---
gdb/debuginfod-support.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 86630576e3..a17cb7c5a8 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -21,6 +21,8 @@
#include "cli/cli-style.h"
#include "gdbsupport/scoped_fd.h"
#include "debuginfod-support.h"
+#include "gdbsupport/gdb_optional.h"
+#include <iomanip>

#ifndef HAVE_LIBDEBUGINFOD
scoped_fd
@@ -48,12 +50,12 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
struct user_data
{
user_data (const char *desc, const char *fname)
- : desc (desc), fname (fname), has_printed (false)
+ : desc (desc), fname (fname)
{ }

const char * const desc;
const char * const fname;
- bool has_printed;
+ gdb::optional<ui_out::progress_meter> meter;
};

/* Deleter for a debuginfod_client. */
@@ -82,15 +84,21 @@ progressfn (debuginfod_client *c, long cur, long total)
return 1;
}

- if (!data->has_printed && total != 0)
+ if (total == 0)
+ return 0;
+
+ if (!data->meter.has_value ())
{
- /* Print this message only once. */
- data->has_printed = true;
- printf_filtered ("Downloading %s %ps...\n",
- data->desc,
- styled_string (file_name_style.style (), data->fname));
+ float size_in_mb = 1.0f * total / (1024 * 1024);
+ std::stringstream message;
+ message.precision (2);
+ message << "Downloading " << size_in_mb << " MB " << data->desc
+ << " " << data->fname;
+ data->meter.emplace (current_uiout, message.str (), 1);
}

+ current_uiout->progress ((double)cur / (double)total);
+
return 0;
}