*/
void
-cli_ui_out::do_progress_notify (const std::string &msg, double howmuch)
+cli_ui_out::do_progress_notify (const std::string &msg,
+ const std::string &size,
+ double cur, double total)
{
struct ui_file *stream = m_streams.back ();
cli_progress_info &info (m_progress_info.back ());
if (info.state == progress_update::START)
{
- if (!stream->isatty ())
+ if (stream->isatty ())
{
- gdb_printf (stream, "%s...\n", msg.c_str ());
- info.state = progress_update::WORKING;
+ gdb_printf (stream, "%s", msg.c_str ());
+ info.state = progress_update::BAR;
}
else
{
- gdb_printf (stream, "%s\n", msg.c_str ());
- info.state = progress_update::BAR;
+ gdb_printf (stream, "%s...\n", msg.c_str ());
+ info.state = progress_update::WORKING;
}
}
|| !stream->isatty ())
return;
- if (howmuch >= 0)
+ double howmuch = cur / total;
+ if (howmuch >= 0 && howmuch <= 1.0)
{
- int width = chars_per_line - 3;
+ std::string progress = string_printf (" %.02f %s / %.02f %s",
+ cur, size.c_str (),
+ total, size.c_str ());
+ int width = chars_per_line - progress.size () - 3;
int max = width * howmuch;
- gdb_printf (stream, "\r[");
+ std::string display = "\r[";
+
for (int i = 0; i < width; ++i)
- gdb_printf (stream, i < max ? "#" : " ");
- gdb_printf (stream, "]");
+ if (i < max)
+ display += "#";
+ else
+ display += " ";
+
+ display += "]" + progress;
+ gdb_printf (stream, "%s", display.c_str ());
gdb_flush (stream);
}
else
virtual void do_redirect (struct ui_file *outstream) override;
virtual void do_progress_start () override;
- virtual void do_progress_notify (const std::string &, double) override;
+ virtual void do_progress_notify (const std::string &, const std::string &,
+ double, double) override;
virtual void do_progress_end () override;
bool suppress_output ()
using debuginfod_client_up
= std::unique_ptr<debuginfod_client, debuginfod_client_deleter>;
+
/* Convert SIZE into a unit suitable for use with progress updates.
- SIZE should in given in bytes and will be converted into KB or MB.
- UNIT will be set to "KB" or "MB" accordingly. */
+ SIZE should in given in bytes and will be converted into KB, MB, GB
+ or remain unchanged. UNIT will be set to "B", "KB", "MB" or "GB"
+ accordingly. */
static void
-get_size_and_unit (double *size, const char **unit)
+get_size_and_unit (double &size, std::string &unit)
{
- *size /= 1024;
+ if (size < 10.24)
+ {
+ /* If size is less than 0.01 KB then set unit to B. */
+ unit = "B";
+ return;
+ }
- /* If size is greater than 0.01 MB then set unit to MB. */
- if (*size > 10.24)
+ size /= 1024;
+ if (size < 10.24)
{
- *size /= 1024;
- *unit = "MB";
+ /* If size is less than 0.01 MB then set unit to KB. */
+ unit = "KB";
+ return;
}
- else
- *unit = "KB";
+
+ size /= 1024;
+ if (size < 10.24)
+ {
+ /* If size is less than 0.01 GB then set unit to MB. */
+ unit = "MB";
+ return;
+ }
+
+ size /= 1024;
+ 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
if (check_quit_flag ())
{
- current_uiout->do_progress_end (); ///?
-
- gdb_printf ("Cancelling download of %s %ps...\n",
+ //current_uiout->do_progress_end (); ///?
+ gdb_printf ("Cancelling download of %s %s...\n",
data->desc, styled_fname.c_str ());
return 1;
}
if (howmuch >= 0.0 && howmuch <= 1.0)
{
- double size = (double) total;
- const char *unit = "";
+ double d_total = (double) total;
+ double d_cur = (double) cur;
+ std::string unit = "";
- get_size_and_unit (&size, &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",
- size, unit, data->desc,
+ d_total, unit.c_str (), data->desc,
styled_fname.c_str ());
- current_uiout->update_progress (msg, howmuch);
+ data->progress.update_progress (msg, unit, d_cur, d_total);
return 0;
}
}
std::string msg = string_printf ("Downloading %s %s\n",
data->desc, styled_fname.c_str ());
- current_uiout->update_progress (msg, -1);
+ data->progress.update_progress (msg);
return 0;
}
if (fstat (fd, &s) == 0)
{
double size = (double)s.st_size;
- const char *unit = "";
+ std::string unit = "";
- get_size_and_unit (&size, &unit);
- gdb_printf (_("Retrieved %.02f %s %s %s\n"), size, 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
scoped_fd fd (debuginfod_find_executable (c, build_id, build_id_len, &dname));
debuginfod_set_user_data (c, nullptr);
-
- if (fd.get () < 0 && fd.get () != -ENOENT)
- gdb_printf (_("Download failed: %s. " \
- "Continuing without executable for %ps.\n"),
- safe_strerror (-fd.get ()),
- styled_string (file_name_style.style (), filename));
+ print_outcome (data, fd.get ());
if (fd.get () >= 0)
destname->reset (dname);
/* Indicate that a task described by NAME is in progress. */
void
-mi_ui_out::do_progress_notify (const std::string &msg, double howmuch)
+mi_ui_out::do_progress_notify (const std::string &msg, const std::string &unit,
+ double cur, double total)
{
mi_progress_info &info (m_progress_info.back ());
{ return true; }
virtual void do_progress_start () override;
- virtual void do_progress_notify (const std::string &, double) override;
+ virtual void do_progress_notify (const std::string &, const std::string &,
+ double, double) override;
virtual void do_progress_end () override
{
progress_update (const progress_update &) = delete;
progress_update &operator= (const progress_update &) = delete;
- /* Emit some progress for this progress meter. HOWMUCH may range
- from 0.0 to 1.0. */
- void progress (const std::string& msg, double howmuch)
+ /* Emit some progress for this progress meter. Includes current
+ amount of progress made and total amount in the display. */
+ void update_progress (const std::string& msg, std::string& unit,
+ double cur, double total)
{
- m_uiout->do_progress_notify (msg, howmuch);
+ m_uiout->do_progress_notify (msg, unit, cur, total);
}
+ /* Emit some progress for this progress meter. */
+ void update_progress (const std::string& msg)
+ {
+ m_uiout->do_progress_notify (msg, "", -1, -1);
+ }
private:
struct ui_out *m_uiout;
};
- /* Emit some progress corresponding to the most recently created
- progress_update object. */
- void update_progress (std::string &msg, double howmuch)
- {
- do_progress_notify (msg, howmuch);
- }
-
virtual void do_progress_end () = 0;
protected:
virtual void do_redirect (struct ui_file *outstream) = 0;
virtual void do_progress_start () = 0;
- virtual void do_progress_notify (const std::string &, double) = 0;
+ virtual void do_progress_notify (const std::string &, const std::string &,
+ double, double) = 0;
/* Set as not MI-like by default. It is overridden in subclasses if
necessary. */