From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2009) id C8098385AC22; Thu, 24 Mar 2022 19:03:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8098385AC22 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Aaron Merey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove download size from debuginfod progress messages if unavailable X-Act-Checkin: binutils-gdb X-Git-Author: Aaron Merey X-Git-Refname: refs/heads/master X-Git-Oldrev: 8bd59ec1bba9a591eb4f2523acafe98c38fd2f46 X-Git-Newrev: b0e0d830d98e98de8c57e8f4bee24b31294ea4e1 Message-Id: <20220324190352.C8098385AC22@sourceware.org> Date: Thu, 24 Mar 2022 19:03:52 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Mar 2022 19:03:52 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db0e0d830d98e= 98de8c57e8f4bee24b31294ea4e1 commit b0e0d830d98e98de8c57e8f4bee24b31294ea4e1 Author: Aaron Merey Date: Tue Mar 22 20:01:54 2022 -0400 Remove download size from debuginfod progress messages if unavailable =20 Currently debuginfod progress update messages include the size of each download: =20 Downloading 7.5 MB separate debug info for /lib/libxyz.so.0 =20 This value originates from the Content-Length HTTP header of the transfer. However this header is not guaranteed to be present for each download. This can happen when debuginfod servers compress files on-the-fly at the time of transfer. In this case gdb wrongly prints "-0.00 MB" as the size. =20 This patch removes download sizes from progress messages when they are not available. It also removes usage of the progress bar until a more thorough reworking of progress updating is implemented. [1] =20 [1] https://sourceware.org/pipermail/gdb-patches/2022-February/185798.h= tml Diff: --- gdb/debuginfod-support.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 3614ff23882..d5d023ff7bb 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -86,12 +86,12 @@ debuginfod_exec_query (const unsigned char *build_id, struct user_data { user_data (const char *desc, const char *fname) - : desc (desc), fname (fname) + : desc (desc), fname (fname), has_printed (false) { } =20 const char * const desc; const char * const fname; - gdb::optional meter; + bool has_printed; }; =20 /* Deleter for a debuginfod_client. */ @@ -121,24 +121,32 @@ progressfn (debuginfod_client *c, long cur, long tota= l) return 1; } =20 - if (total =3D=3D 0) - return 0; - - if (!data->meter.has_value ()) + if (!data->has_printed) { - float size_in_mb =3D 1.0f * total / (1024 * 1024); - string_file styled_filename (current_uiout->can_emit_style_escape ()= ); - fprintf_styled (&styled_filename, - file_name_style.style (), - "%s", - data->fname); - std::string message - =3D string_printf ("Downloading %.2f MB %s %s", size_in_mb, data->desc, - styled_filename.c_str()); - data->meter.emplace (current_uiout, message, 1); - } + /* Include the transfer size, if available. */ + if (total > 0) + { + float size =3D 1.0f * total / 1024; + const char *unit =3D "KB"; + + /* If size is greater than 0.01 MB, set unit to MB. */ + if (size > 10.24) + { + size /=3D 1024; + unit =3D "MB"; + } + + printf_filtered ("Downloading %.2f %s %s %ps...\n", + size, unit, data->desc, + styled_string (file_name_style.style (), + data->fname)); + } + else + printf_filtered ("Downloading %s %ps...\n", data->desc, + styled_string (file_name_style.style (), data->fname)); =20 - data->meter->progress ((double)cur / (double)total); + data->has_printed =3D true; + } =20 return 0; }