Add fu_progress_to_string() to make debugging easier

This commit is contained in:
Richard Hughes 2022-10-27 14:45:57 +01:00
parent 93466bd7c4
commit b50b67107f
3 changed files with 52 additions and 0 deletions

View File

@ -1012,6 +1012,55 @@ fu_progress_traceback(FuProgress *self)
return g_string_free(g_steal_pointer(&str), FALSE);
}
static void
fu_progress_to_string_cb(FuProgress *self, guint idt, GString *str)
{
FuProgressPrivate *priv = GET_PRIVATE(self);
/* not interesting */
if (priv->id == NULL && priv->name == NULL)
return;
if (priv->id != NULL)
fu_string_append(str, idt, "Id", priv->id);
if (priv->name != NULL)
fu_string_append(str, idt, "Name", priv->name);
if (priv->percentage != G_MAXUINT)
fu_string_append_ku(str, idt, "Percentage", priv->percentage);
if (priv->status != FWUPD_STATUS_UNKNOWN)
fu_string_append(str, idt, "Status", fwupd_status_to_string(priv->status));
if (priv->duration > 0.0001)
fu_string_append_ku(str, idt, "DurationMs", priv->duration * 1000.f);
if (priv->step_weighting > 0)
fu_string_append_ku(str, idt, "StepWeighting", priv->step_weighting);
if (priv->step_now > 0)
fu_string_append_ku(str, idt, "StepNow", priv->step_now);
for (guint i = 0; i < priv->children->len; i++) {
FuProgress *child = g_ptr_array_index(priv->children, i);
fu_progress_to_string_cb(child, idt + 1, str);
}
}
/**
* fu_progress_to_string:
* @self: A #FuProgress
*
* Prints the progress for debugging.
*
* Return value: (transfer full): string
*
* Since: 1.8.7
**/
gchar *
fu_progress_to_string(FuProgress *self)
{
g_autoptr(GString) str = g_string_new(NULL);
fu_progress_to_string_cb(self, 0, str);
if (str->len == 0)
return NULL;
return g_string_free(g_steal_pointer(&str), FALSE);
}
static void
fu_progress_init(FuProgress *self)
{

View File

@ -134,3 +134,5 @@ void
fu_progress_sleep(FuProgress *self, guint delay_ms);
gchar *
fu_progress_traceback(FuProgress *self);
gchar *
fu_progress_to_string(FuProgress *self);

View File

@ -1139,6 +1139,7 @@ LIBFWUPDPLUGIN_1.8.6 {
LIBFWUPDPLUGIN_1.8.7 {
global:
fu_progress_to_string;
fu_udev_device_find_usb_device;
fu_udev_device_set_device_file;
local: *;