From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id X4s2L0nz1F+WEQAAWB0awg (envelope-from ) for ; Sat, 12 Dec 2020 11:43:53 -0500 Received: by simark.ca (Postfix, from userid 112) id B72021F0AA; Sat, 12 Dec 2020 11:43:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 41DF51EF4B for ; Sat, 12 Dec 2020 11:43:53 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAF5D389246A; Sat, 12 Dec 2020 16:43:52 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D1FF8385802A for ; Sat, 12 Dec 2020 16:43:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1FF8385802A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E805EAD8D; Sat, 12 Dec 2020 16:43:49 +0000 (UTC) To: Tom Tromey References: <6ad82f30-0ca3-8b19-2907-d71f0dfecafe@suse.cz> <2c28a403-a169-0dc3-9b64-58484237c8c2@suse.cz> <72061fbb-b480-04ce-ef4a-fe13a7266885@suse.de> <87a6ulmppr.fsf@tromey.com> <5506b198-c504-0046-0559-bcc24538d31c@suse.de> <87ft4cgn94.fsf@tromey.com> From: Tom de Vries Subject: Re: [PATCH] gdb: print size of downloaded debuginfod binary Message-ID: <8fc40ddb-d298-3659-9ff3-fb31d372c58f@suse.de> Date: Sat, 12 Dec 2020 17:43:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <87ft4cgn94.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------44EFEF498AA116437DFEBFB1" Content-Language: en-US X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------44EFEF498AA116437DFEBFB1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 12/11/20 8:23 PM, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> + gdb::optional meter; > > Seems like a bit of a shame to have an optional here, but then > essentially require optional-style behavior in the CLI ui-out as well > (in deferring output until the first update). > Well, the natural place to declare "ui_out::progress_meter meter" given its lifetime is in debuginfod_source_query and debuginfod_debuginfo_query. But the only constructor has the name argument with no means of changing it later, and the name (containing the size) is only known lateron, when progressfn is called. So the optional is used as a means to have lifetime as we want it, while postponing construction until we known all the constructor arguments. > Maybe it could be done in progress_meter itself. Not sure. > > Tom> - /* Print this message only once. */ > Tom> - data->has_printed = true; > Tom> - printf_filtered ("Downloading %s %ps...\n", > Tom> - data->desc, > Tom> - styled_string (file_name_style.style (), data->fname)); > Tom> + float size_in_mb = 1.0f * total / (1024 * 1024); > Tom> + std::stringstream message; > Tom> + message.precision (2); > Tom> + message << "Downloading " << size_in_mb << " MB " << data->desc > Tom> + << " " << data->fname; > > Seems like this could use string_printf. Done. > I suspect there's some way to preserve the styling but offhand I don't > recall what it is. Maybe you have to use string_file to accomplish that. > Done. Thanks, - Tom --------------44EFEF498AA116437DFEBFB1 Content-Type: text/x-patch; charset=UTF-8; name="0011-gdb-Print-progress-for-debuginfod.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="0011-gdb-Print-progress-for-debuginfod.patch" [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 Tom de Vries * gdb/debuginfod-support.c (struct user_data): Remove has_printed field. Add meter field. (progressfn): Print progress using meter. --- gdb/debuginfod-support.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index e21b2f40ca..e9b2dcd5be 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -21,6 +21,7 @@ #include "cli/cli-style.h" #include "gdbsupport/scoped_fd.h" #include "debuginfod-support.h" +#include "gdbsupport/gdb_optional.h" =20 #ifndef HAVE_LIBDEBUGINFOD scoped_fd @@ -46,12 +47,12 @@ debuginfod_debuginfo_query (const unsigned char *buil= d_id, struct user_data { user_data (const char *desc, const char *fname) - : desc (desc), fname (fname), has_printed (false) + : desc (desc), fname (fname) { } =20 const char * const desc; const char * const fname; - bool has_printed; + gdb::optional meter; }; =20 /* Deleter for a debuginfod_client. */ @@ -80,15 +81,25 @@ progressfn (debuginfod_client *c, long cur, long tota= l) return 1; } =20 - if (!data->has_printed && total !=3D 0) + if (total =3D=3D 0) + return 0; + + if (!data->meter.has_value ()) { - /* Print this message only once. */ - data->has_printed =3D true; - printf_filtered ("Downloading %s %ps...\n", - data->desc, - styled_string (file_name_style.style (), data->fname)); + 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); } =20 + current_uiout->progress ((double)cur / (double)total); + return 0; } =20 --------------44EFEF498AA116437DFEBFB1--