From ef61724269a1bdf54fef0c9ba99e9116806d90f5 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 5 Sep 2013 16:48:40 -0400 Subject: [PATCH] repo: Move the transaction stats to a separate struct This is much easier for callers to handle, and simplifies the API a lot. https://bugzilla.gnome.org/show_bug.cgi?id=707644 --- doc/ostree-sections.txt | 2 +- src/libostree/ostree-repo-commit.c | 60 ++++++++++++++--------------- src/libostree/ostree-repo-private.h | 6 +-- src/libostree/ostree-repo-pull.c | 2 +- src/libostree/ostree-repo.h | 49 +++++++++++++++++------ src/ostree/ot-builtin-commit.c | 24 ++++-------- src/ostree/ot-builtin-pull-local.c | 2 +- 7 files changed, 76 insertions(+), 69 deletions(-) diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt index 34a2faf3..f5abbd57 100644 --- a/doc/ostree-sections.txt +++ b/doc/ostree-sections.txt @@ -63,9 +63,9 @@ ostree_repo_get_config ostree_repo_copy_config ostree_repo_get_parent ostree_repo_write_config +OstreeRepoTransactionStats ostree_repo_prepare_transaction ostree_repo_commit_transaction -ostree_repo_commit_transaction_with_stats ostree_repo_abort_transaction ostree_repo_has_object ostree_repo_write_metadata diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 39b75faf..69b48c8f 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -367,18 +367,18 @@ write_object (OstreeRepo *self, { if (OSTREE_OBJECT_TYPE_IS_META (objtype)) { - self->txn_metadata_objects_written++; + self->txn_stats.metadata_objects_written++; } else { - self->txn_content_objects_written++; - self->txn_content_bytes_written += file_object_length; + self->txn_stats.content_objects_written++; + self->txn_stats.content_bytes_written += file_object_length; } } if (OSTREE_OBJECT_TYPE_IS_META (objtype)) - self->txn_metadata_objects_total++; + self->txn_stats.metadata_objects_total++; else - self->txn_content_objects_total++; + self->txn_stats.content_objects_total++; g_mutex_unlock (&self->txn_stats_lock); if (checksum) @@ -562,11 +562,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self, else ret_transaction_resume = FALSE; - self->txn_metadata_objects_total = - self->txn_metadata_objects_written = - self->txn_content_objects_total = - self->txn_content_objects_written = - self->txn_content_bytes_written = 0; + memset (&self->txn_stats, 0, sizeof (OstreeRepoTransactionStats)); self->in_transaction = TRUE; if (ret_transaction_resume) @@ -631,14 +627,10 @@ cleanup_tmpdir (OstreeRepo *self, } gboolean -ostree_repo_commit_transaction_with_stats (OstreeRepo *self, - guint *out_metadata_objects_total, - guint *out_metadata_objects_written, - guint *out_content_objects_total, - guint *out_content_objects_written, - guint64 *out_content_bytes_written, - GCancellable *cancellable, - GError **error) +ostree_repo_commit_transaction (OstreeRepo *self, + OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; @@ -655,26 +647,14 @@ ostree_repo_commit_transaction_with_stats (OstreeRepo *self, if (!ot_gfile_ensure_unlinked (self->transaction_lock_path, cancellable, error)) goto out; - if (out_metadata_objects_total) *out_metadata_objects_total = self->txn_metadata_objects_total; - if (out_metadata_objects_written) *out_metadata_objects_written = self->txn_metadata_objects_written; - if (out_content_objects_total) *out_content_objects_total = self->txn_content_objects_total; - if (out_content_objects_written) *out_content_objects_written = self->txn_content_objects_written; - if (out_content_bytes_written) *out_content_bytes_written = self->txn_content_bytes_written; + if (out_stats) + *out_stats = self->txn_stats; ret = TRUE; out: return ret; } -gboolean -ostree_repo_commit_transaction (OstreeRepo *self, - GCancellable *cancellable, - GError **error) -{ - return ostree_repo_commit_transaction_with_stats (self, NULL, NULL, NULL, NULL, NULL, - cancellable, error); -} - gboolean ostree_repo_abort_transaction (OstreeRepo *self, GCancellable *cancellable, @@ -1622,3 +1602,19 @@ ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier) G_DEFINE_BOXED_TYPE(OstreeRepoCommitModifier, ostree_repo_commit_modifier, ostree_repo_commit_modifier_ref, ostree_repo_commit_modifier_unref); + +static OstreeRepoTransactionStats * +ostree_repo_transaction_stats_copy (OstreeRepoTransactionStats *stats) +{ + return g_memdup (stats, sizeof (OstreeRepoTransactionStats)); +} + +static void +ostree_repo_transaction_stats_free (OstreeRepoTransactionStats *stats) +{ + return g_free (stats); +} + +G_DEFINE_BOXED_TYPE(OstreeRepoTransactionStats, ostree_repo_transaction_stats, + ostree_repo_transaction_stats_copy, + ostree_repo_transaction_stats_free); diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index ed7daae2..383ea50e 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -40,11 +40,7 @@ struct OstreeRepo { GFile *transaction_lock_path; GMutex txn_stats_lock; - guint txn_metadata_objects_total; - guint txn_metadata_objects_written; - guint txn_content_objects_total; - guint txn_content_objects_written; - guint64 txn_content_bytes_written; + OstreeRepoTransactionStats txn_stats; GMutex cache_lock; GPtrArray *cached_meta_indexes; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index bdb1958f..0a42e3f9 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -1332,7 +1332,7 @@ ostree_repo_pull (OstreeRepo *self, if (!run_mainloop_monitor_fetcher (pull_data)) goto out; - if (!ostree_repo_commit_transaction (pull_data->repo, cancellable, error)) + if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error)) goto out; g_hash_table_iter_init (&hash_iter, updated_refs); diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 186b4804..882e3061 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -79,24 +79,49 @@ gboolean ostree_repo_write_config (OstreeRepo *self, GKeyFile *new_config, GError **error); +/** + * OstreeRepoTransactionStats: + * @metadata_objects_total: The total number of metadata objects + * in the repository after this transaction has completed. + * @metadata_objects_written: The number of metadata objects that + * were written to the repository in this transaction. + * @content_objects_total: The total number of content objects + * in the repository after this transaction has completed. + * @content_objects_written: The number of content objects that + * were written to the repository in this transaction. + * @content_bytes_total: The amount of data added to the repository, + * in bytes, counting only content objects. + * + * A list of statistics for each transaction that may be + * interesting for reporting purposes. + */ +typedef struct _OstreeRepoTransactionStats OstreeRepoTransactionStats; + +struct _OstreeRepoTransactionStats { + guint metadata_objects_total; + guint metadata_objects_written; + guint content_objects_total; + guint content_objects_written; + guint64 content_bytes_written; + + guint64 padding1; + guint64 padding2; + guint64 padding3; + guint64 padding4; +}; + +GType ostree_repo_transaction_stats_get_type (void); + gboolean ostree_repo_prepare_transaction (OstreeRepo *self, gboolean enable_commit_hardlink_scan, gboolean *out_transaction_resume, GCancellable *cancellable, GError **error); -gboolean ostree_repo_commit_transaction (OstreeRepo *self, - GCancellable *cancellable, - GError **error); - -gboolean ostree_repo_commit_transaction_with_stats (OstreeRepo *self, - guint *out_metadata_objects_total, - guint *out_metadata_objects_written, - guint *out_content_objects_total, - guint *out_content_objects_written, - guint64 *out_content_bytes_written, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_commit_transaction (OstreeRepo *self, + OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, + GError **error); gboolean ostree_repo_abort_transaction (OstreeRepo *self, GCancellable *cancellable, diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 7ef20377..22d6d89c 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -225,11 +225,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca gboolean ret = FALSE; gboolean skip_commit = FALSE; gboolean in_transaction = FALSE; - guint metadata_total = 0; - guint metadata_written = 0; - guint content_total = 0; - guint content_written = 0; - guint64 content_bytes_written = 0; gs_unref_object GFile *arg = NULL; gs_free char *parent = NULL; gs_free char *commit_checksum = NULL; @@ -243,6 +238,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca gs_free char *parent_content_checksum = NULL; gs_free char *parent_metadata_checksum = NULL; OstreeRepoCommitModifier *modifier = NULL; + OstreeRepoTransactionStats stats; context = g_option_context_new ("[ARG] - Commit a new revision"); g_option_context_add_main_entries (context, options, NULL); @@ -424,13 +420,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca &commit_checksum, cancellable, error)) goto out; - if (!ostree_repo_commit_transaction_with_stats (repo, - &metadata_total, - &metadata_written, - &content_total, - &content_written, - &content_bytes_written, - cancellable, error)) + if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) goto out; in_transaction = FALSE; @@ -452,11 +442,11 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca if (opt_table_output) { g_print ("Commit: %s\n", commit_checksum); - g_print ("Metadata Total: %u\n", metadata_total); - g_print ("Metadata Written: %u\n", metadata_written); - g_print ("Content Total: %u\n", content_total); - g_print ("Content Written: %u\n", content_written); - g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", content_bytes_written); + g_print ("Metadata Total: %u\n", stats.metadata_objects_total); + g_print ("Metadata Written: %u\n", stats.metadata_objects_written); + g_print ("Content Total: %u\n", stats.content_objects_total); + g_print ("Content Written: %u\n", stats.content_objects_written); + g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written); } else { diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c index b7749e16..98ba6cd2 100644 --- a/src/ostree/ot-builtin-pull-local.c +++ b/src/ostree/ot-builtin-pull-local.c @@ -290,7 +290,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable gs_console_end_status_line (data->console, NULL, NULL); } - if (!ostree_repo_commit_transaction (data->dest_repo, NULL, error)) + if (!ostree_repo_commit_transaction (data->dest_repo, NULL, NULL, error)) goto out; g_print ("Writing %u refs\n", g_hash_table_size (refs_to_clone));