]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve cur/total display, remove higher verbosity setting users/amerey/debuginfod-size
authorAaron Merey <amerey@redhat.com>
Tue, 21 Jun 2022 21:55:29 +0000 (17:55 -0400)
committerAaron Merey <amerey@redhat.com>
Tue, 21 Jun 2022 21:55:29 +0000 (17:55 -0400)
gdb/cli-out.c
gdb/debuginfod-support.c
gdb/mi/mi-out.c

index 3e5af160b305f1825e7fb8e14c62c3bde07d746c..7a2720d003f0ff8df6801d0312bb871ac5efb6de 100644 (file)
@@ -295,7 +295,7 @@ cli_ui_out::do_progress_start ()
 void
 cli_ui_out::do_progress_notify (const std::string &msg,
                                const std::string &size,
-                               double cur, double total)
+                               double howmuch, double total)
 {
   struct ui_file *stream = m_streams.back ();
   cli_progress_info &info (m_progress_info.back ());
@@ -323,12 +323,11 @@ cli_ui_out::do_progress_notify (const std::string &msg,
       || !stream->isatty ())
     return;
 
-  double howmuch = cur / total;
-  if (howmuch >= 0 && howmuch <= 1.0)
+  if (total > 0 && howmuch >= 0 && howmuch <= 1.0)
     {
-      std::string progress = string_printf (" %.02f %s / %.02f %s",
-                                           cur, size.c_str (),
-                                           total, size.c_str ());
+      std::string progress = string_printf (" %3.d%% (%.02f %s)",
+                                           (int)(howmuch * 100), total,
+                                           size.c_str ());
       int width = chars_per_line - progress.size () - 3;
       int max = width * howmuch;
 
@@ -357,11 +356,11 @@ cli_ui_out::do_progress_notify (const std::string &msg,
          int width = chars_per_line - 3;
 
          gdb_printf (stream, "\r[");
-          
          for (int i = 0; i < width; ++i)
            {
-             if (i >= info.pos % width
-                 && i < (info.pos + 3) % width)
+             if (i == info.pos % width
+                 || i == (info.pos + 1) % width
+                 || i == (info.pos + 2) % width)
                gdb_printf (stream, "#");
              else
                gdb_printf (stream, " ");
index 77e2839cb8ffade558e5dc8916cd38c440f5f797..0613e4e3d07f0cfb7f7fe3ce6391d0103b427149 100644 (file)
@@ -119,25 +119,25 @@ using debuginfod_client_up
 static void
 get_size_and_unit (double &size, std::string &unit)
 {
-  if (size < 10.24)
+  if (size < 1024)
     {
-      /* If size is less than 0.01 KB then set unit to B.  */
+      /* If size is less than 1 KB then set unit to B.  */
       unit = "B";
       return;
     }
 
   size /= 1024;
-  if (size < 10.24)
+  if (size < 1024)
     {
-      /* If size is less than 0.01 MB then set unit to KB.  */
+      /* If size is less than 1 MB then set unit to KB.  */
       unit = "KB";
       return;
     }
 
   size /= 1024;
-  if (size < 10.24)
+  if (size < 1024)
     {
-      /* If size is less than 0.01 GB then set unit to MB.  */
+      /* If size is less than 1 GB then set unit to MB.  */
       unit = "MB";
       return;
     }
@@ -146,17 +146,6 @@ get_size_and_unit (double &size, std::string &unit)
   unit = "GB";
 }
 
-static void
-convert_to_unit (double &size, const std::string &unit)
-{
-  if (unit == "KB")
-    size /= 1024;
-  else if (unit == "MB")
-    size /= 1024 * 1024;
-  else if (unit == "GB")
-    size /= 1024 * 1024 * 1024;
-}
-
 static int
 progressfn (debuginfod_client *c, long cur, long total)
 {
@@ -169,7 +158,6 @@ progressfn (debuginfod_client *c, long cur, long total)
 
   if (check_quit_flag ())
     {
-      //current_uiout->do_progress_end (); ///?
       gdb_printf ("Cancelling download of %s %s...\n",
                  data->desc, styled_fname.c_str ());
       return 1;
@@ -187,15 +175,13 @@ progressfn (debuginfod_client *c, long cur, long total)
       if (howmuch >= 0.0 && howmuch <= 1.0)
        {
          double d_total = (double) total;
-          double d_cur = (double) cur;
          std::string unit = "";
 
          get_size_and_unit (d_total, unit);
-         convert_to_unit (d_cur, unit);
          std::string msg = string_printf ("Downloading %0.2f %s %s %s\n",
                                           d_total, unit.c_str (), data->desc,
                                           styled_fname.c_str ());
-         data->progress.update_progress (msg, unit, d_cur, d_total);
+         data->progress.update_progress (msg, unit, howmuch, d_total);
          return 0;
        }
     }
@@ -299,29 +285,9 @@ print_outcome (user_data &data, int fd)
   fprintf_styled (&styled_fname, file_name_style.style (), "%s",
                  data.fname);
 
-  if (debuginfod_verbose > 1 && fd >= 0)
-    {
-      struct stat s;
-
-      if (fstat (fd, &s) == 0)
-       {
-         double size = (double)s.st_size;
-         std::string unit = "";
-
-         get_size_and_unit (size, unit);
-         gdb_printf (_("Retrieved %.02f %s %s %s\n"), size, unit.c_str (),
-                     data.desc, styled_fname.c_str ());
-       }
-      else
-       warning (_("Retrieved %s %s but size cannot be read: %s\n"),
-                data.desc, styled_fname.c_str (),
-                safe_strerror (errno));
-    }
-  else if (fd < 0 && fd != -ENOENT)
-    gdb_printf (_("Download failed: %s. " \
-               "Continuing without %s %s.\n"),
-               safe_strerror (-fd), data.desc,
-               styled_fname.c_str ());
+  if (fd < 0 && fd != -ENOENT)
+    gdb_printf (_("Download failed: %s. Continuing without %s %s.\n"),
+               safe_strerror (-fd), data.desc, styled_fname.c_str ());
 }
 
 /* See debuginfod-support.h  */
index ee0f4db5341df4dc81132643e71480b9c12ce064..90a2362e91a930209c4452fad50425538dd2568b 100644 (file)
@@ -278,7 +278,7 @@ mi_ui_out::do_progress_notify (const std::string &msg, const std::string &unit,
   if (info.state == progress_update::START)
     {
       struct ui_file *stream = gdb_stdout;
-      gdb_printf (stream, "%s\n", msg.c_str ());
+      gdb_printf (stream, "%s", msg.c_str ());
       info.state = progress_update::WORKING;
     }
 }