From 4006907ba3e05ee548dd10bca05ede0948a9891e Mon Sep 17 00:00:00 2001 From: razzeee Date: Tue, 9 Jun 2026 16:43:37 +0200 Subject: [PATCH] transaction: Add flatpak_transaction_progress_get_bytes_per_second() --- common/flatpak-progress-private.h | 1 + common/flatpak-progress.c | 17 ++++++++++++++++- common/flatpak-transaction.c | 16 ++++++++++++++++ common/flatpak-transaction.h | 2 ++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/common/flatpak-progress-private.h b/common/flatpak-progress-private.h index 47ada0c81..3dd8baa57 100644 --- a/common/flatpak-progress-private.h +++ b/common/flatpak-progress-private.h @@ -74,6 +74,7 @@ void flatpak_progress_set_update_interval (FlatpakProgress *self, guint64 flatpak_progress_get_bytes_transferred (FlatpakProgress *self); guint64 flatpak_progress_get_transferred_extra_data_bytes (FlatpakProgress *self); guint64 flatpak_progress_get_start_time (FlatpakProgress *self); +guint64 flatpak_progress_get_bytes_per_second (FlatpakProgress *self); const char *flatpak_progress_get_status (FlatpakProgress *self); int flatpak_progress_get_progress (FlatpakProgress *self); gboolean flatpak_progress_get_estimating (FlatpakProgress *self); diff --git a/common/flatpak-progress.c b/common/flatpak-progress.c index 1ca4b0463..fd685e23a 100644 --- a/common/flatpak-progress.c +++ b/common/flatpak-progress.c @@ -113,6 +113,7 @@ struct _FlatpakProgress /* Self-progress-reporting fields, not from OSTree */ guint progress; guint last_total; + guint64 bytes_per_second; guint32 update_interval; @@ -190,6 +191,7 @@ update_status_progress_and_estimating (FlatpakProgress *self) extra data, so ignore those */ if (self->requested == 0) { + self->bytes_per_second = 0; return; } @@ -209,6 +211,7 @@ update_status_progress_and_estimating (FlatpakProgress *self) { g_string_append (buf, self->ostree_status); new_progress = 100; + self->bytes_per_second = 0; goto out; } @@ -302,9 +305,15 @@ update_status_progress_and_estimating (FlatpakProgress *self) if (elapsed_time > 0) // Ignore first second { - g_autofree gchar *formatted_bytes_sec = g_format_size (total_transferred / elapsed_time); + g_autofree gchar *formatted_bytes_sec = NULL; + self->bytes_per_second = total_transferred / elapsed_time; + formatted_bytes_sec = g_format_size (self->bytes_per_second); g_string_append_printf (buf, " (%s/s)", formatted_bytes_sec); } + else + { + self->bytes_per_second = 0; + } out: if (new_progress < self->progress && self->last_total == total) @@ -482,6 +491,12 @@ flatpak_progress_get_start_time (FlatpakProgress *self) return self->start_time; } +guint64 +flatpak_progress_get_bytes_per_second (FlatpakProgress *self) +{ + return self->bytes_per_second; +} + const char * flatpak_progress_get_status (FlatpakProgress *self) { diff --git a/common/flatpak-transaction.c b/common/flatpak-transaction.c index 5d1460ce6..681f1ab82 100644 --- a/common/flatpak-transaction.c +++ b/common/flatpak-transaction.c @@ -395,6 +395,22 @@ flatpak_transaction_progress_get_start_time (FlatpakTransactionProgress *self) return flatpak_progress_get_start_time (self->progress_obj); } +/** + * flatpak_transaction_progress_get_bytes_per_second: + * @self: a #FlatpakTransactionProgress + * + * Gets the current transfer speed in bytes per second. Returns 0 during + * the first second of a transfer while the rate is being established. + * + * Returns: the current transfer rate in bytes per second + * Since: 1.19.0 + */ +guint64 +flatpak_transaction_progress_get_bytes_per_second (FlatpakTransactionProgress *self) +{ + return flatpak_progress_get_bytes_per_second (self->progress_obj); +} + static void flatpak_transaction_progress_finalize (GObject *object) { diff --git a/common/flatpak-transaction.h b/common/flatpak-transaction.h index ae305c341..21a5b4146 100644 --- a/common/flatpak-transaction.h +++ b/common/flatpak-transaction.h @@ -175,6 +175,8 @@ FLATPAK_EXTERN guint64 flatpak_transaction_progress_get_bytes_transferred (FlatpakTransactionProgress *self); FLATPAK_EXTERN guint64 flatpak_transaction_progress_get_start_time (FlatpakTransactionProgress *self); +FLATPAK_EXTERN +guint64 flatpak_transaction_progress_get_bytes_per_second (FlatpakTransactionProgress *self); FLATPAK_EXTERN