From b50b67107fca24becf2762d788a495d4740d15b5 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 27 Oct 2022 14:45:57 +0100 Subject: [PATCH] Add fu_progress_to_string() to make debugging easier --- libfwupdplugin/fu-progress.c | 49 ++++++++++++++++++++++++++++++++++ libfwupdplugin/fu-progress.h | 2 ++ libfwupdplugin/fwupdplugin.map | 1 + 3 files changed, 52 insertions(+) diff --git a/libfwupdplugin/fu-progress.c b/libfwupdplugin/fu-progress.c index 4e1a25677..8cd4c6f9d 100644 --- a/libfwupdplugin/fu-progress.c +++ b/libfwupdplugin/fu-progress.c @@ -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) { diff --git a/libfwupdplugin/fu-progress.h b/libfwupdplugin/fu-progress.h index a893f6f16..294ddb32a 100644 --- a/libfwupdplugin/fu-progress.h +++ b/libfwupdplugin/fu-progress.h @@ -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); diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index a9a49ca0f..f332b4cce 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -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: *;