public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/debuginfod: Improve progress updates
@ 2022-01-12  2:54 Aaron Merey
  2022-01-12  3:27 ` Patrick Monnerat
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Merey @ 2022-01-12  2:54 UTC (permalink / raw)
  To: gdb-patches

Only print the size of the download if it is known.

If the size is less than 0.01 MB then print the size in KB instead.

If the size is unknown then also print a throbber to indicate that the
download is progressing.
---
 gdb/debuginfod-support.c | 64 ++++++++++++++++++++++++++++++----------
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 56d8e7781c5..3094269f446 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -83,6 +83,7 @@ struct user_data
   const char * const desc;
   const char * const fname;
   gdb::optional<ui_out::progress_meter> meter;
+  bool printed_spin = false;
 };
 
 /* Deleter for a debuginfod_client.  */
@@ -112,24 +113,51 @@ progressfn (debuginfod_client *c, long cur, long total)
       return 1;
     }
 
-  if (total == 0)
-    return 0;
+  string_file styled_filename (current_uiout->can_emit_style_escape ());
+  fprintf_styled (&styled_filename,
+		  file_name_style.style (),
+		  "%s",
+		  data->fname);
 
-  if (!data->meter.has_value ())
+  if (total > 0)
     {
-      float size_in_mb = 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
-	= string_printf ("Downloading %.2f MB %s %s", size_in_mb, data->desc,
-			 styled_filename.c_str());
-      data->meter.emplace (current_uiout, message, 1);
-    }
+      if (!data->meter.has_value ())
+	{
+	  double size = 1.0f * total / 1024;
+	  std::string unit = "KB";
+
+	  /* Switch to MB if size greater than 0.01 MB.  */
+	  if (size > 10.24)
+	    {
+	      size /= 1024;
+	      unit = "MB";
+	    }
+
+	  /* Overwrite an existing progress update line with no download
+	     size information.  */
+	  if (data->printed_spin)
+	    {
+	      current_uiout->message ("\r");
+	      data->printed_spin = false;
+	    }
+
+	  std::string message = string_printf ("Downloading %.2f %s %s %s",
+					       size, unit.c_str (),
+					       data->desc,
+					       styled_filename.c_str ());
+	  data->meter.emplace (current_uiout, message, 1);
+	}
 
-  current_uiout->progress ((double)cur / (double)total);
+      current_uiout->progress ((double)cur / (double)total);
+    }
+  else
+    {
+      static int spin = 0;
+      current_uiout->message (_("\rDownloading %s %s %c"), data->desc,
+			      styled_filename.c_str (), "-/|\\"[spin++ % 4]);
+      current_uiout->flush ();
+      data->printed_spin = true;
+    }
 
   return 0;
 }
@@ -217,6 +245,9 @@ debuginfod_source_query (const unsigned char *build_id,
 					build_id_len,
 					srcpath,
 					nullptr));
+  if (data.printed_spin)
+    current_uiout->message ("\b \n");
+
   debuginfod_set_user_data (c, nullptr);
 
   if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT)
@@ -259,6 +290,9 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
 
   scoped_fd fd (debuginfod_find_debuginfo (c, build_id, build_id_len,
 					   &dname));
+  if (data.printed_spin)
+    current_uiout->message ("\b \n");
+
   debuginfod_set_user_data (c, nullptr);
 
   if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT)
-- 
2.33.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-01-13 23:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12  2:54 [PATCH] gdb/debuginfod: Improve progress updates Aaron Merey
2022-01-12  3:27 ` Patrick Monnerat
2022-01-12 22:20   ` Aaron Merey
2022-01-12 23:35     ` Patrick Monnerat
2022-01-13 18:09       ` Aaron Merey
2022-01-13 19:46         ` Patrick Monnerat
2022-01-13 21:27     ` Tom Tromey
2022-01-13 23:11       ` Patrick Monnerat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).