[ostree] Add API to retrieve statistics from transactions, use it in commit
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] Add API to retrieve statistics from transactions, use it in commit
- Date: Thu, 25 Jul 2013 23:25:58 +0000 (UTC)
commit 5aea9db3f21909a82a3dfd056b74267f442d8a60
Author: Colin Walters <walters verbum org>
Date: Thu Jul 25 18:52:06 2013 -0400
Add API to retrieve statistics from transactions, use it in commit
It's just interesting to see =) This is also kind of prototyping out
some more "structured" output.
src/libostree/ostree-repo-libarchive.c | 3 +-
src/libostree/ostree-repo-private.h | 6 ++
src/libostree/ostree-repo.c | 111 +++++++++++++++++++++++++------
src/libostree/ostree-repo.h | 37 +++++++----
src/ostree/ot-builtin-commit.c | 32 ++++++++-
5 files changed, 149 insertions(+), 40 deletions(-)
---
diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c
index bb20475..3c23af0 100644
--- a/src/libostree/ostree-repo-libarchive.c
+++ b/src/libostree/ostree-repo-libarchive.c
@@ -266,7 +266,8 @@ stage_libarchive_entry_to_mtree (OstreeRepo *self,
goto out;
}
- if (!import_libarchive_entry_file (self, a, entry, file_info, &tmp_csum, cancellable, error))
+ if (!import_libarchive_entry_file (self, a, entry, file_info, &tmp_csum,
+ cancellable, error))
goto out;
g_free (tmp_checksum);
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index 78edf74..40793ab 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -38,6 +38,12 @@ struct OstreeRepo {
GFile *config_file;
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;
GMutex cache_lock;
GPtrArray *cached_meta_indexes;
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 4a2b04b..fd7d33f 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -83,6 +83,7 @@ ostree_repo_finalize (GObject *object)
g_clear_pointer (&self->cached_meta_indexes, (GDestroyNotify) g_ptr_array_unref);
g_clear_pointer (&self->cached_content_indexes, (GDestroyNotify) g_ptr_array_unref);
g_mutex_clear (&self->cache_lock);
+ g_mutex_clear (&self->txn_stats_lock);
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
}
@@ -177,6 +178,7 @@ static void
ostree_repo_init (OstreeRepo *self)
{
g_mutex_init (&self->cache_lock);
+ g_mutex_init (&self->txn_stats_lock);
}
OstreeRepo*
@@ -735,6 +737,25 @@ stage_object (OstreeRepo *self,
g_clear_object (&temp_file);
}
}
+
+ g_mutex_lock (&self->txn_stats_lock);
+ if (do_commit)
+ {
+ if (OSTREE_OBJECT_TYPE_IS_META (objtype))
+ {
+ self->txn_metadata_objects_written++;
+ }
+ else
+ {
+ self->txn_content_objects_written++;
+ self->txn_content_bytes_written += file_object_length;
+ }
+ }
+ if (OSTREE_OBJECT_TYPE_IS_META (objtype))
+ self->txn_metadata_objects_total++;
+ else
+ self->txn_content_objects_total++;
+ g_mutex_unlock (&self->txn_stats_lock);
if (checksum)
ret_csum = ot_csum_from_gchecksum (checksum);
@@ -988,6 +1009,12 @@ 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;
+
self->in_transaction = TRUE;
if (ret_transaction_resume)
{
@@ -1015,10 +1042,15 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
return ret;
}
-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 ret = FALSE;
@@ -1031,11 +1063,25 @@ ostree_repo_commit_transaction (OstreeRepo *self,
g_hash_table_remove_all (self->loose_object_devino_hash);
self->in_transaction = FALSE;
+ 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;
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,
@@ -1366,6 +1412,15 @@ ostree_repo_stage_content_async (OstreeRepo *self,
g_object_unref (asyncdata->result);
}
+/**
+ * ostree_repo_stage_content_finish:
+ * @self: a #OstreeRepo
+ * @result: a #GAsyncResult
+ * @out_csum: (out) (transfer full): A binary SHA256 checksum of the content object
+ * @error: a #GError
+ *
+ * Completes an invocation of ostree_repo_stage_content_async().
+ */
gboolean
ostree_repo_stage_content_finish (OstreeRepo *self,
GAsyncResult *result,
@@ -1381,9 +1436,7 @@ ostree_repo_stage_content_finish (OstreeRepo *self,
return FALSE;
data = g_simple_async_result_get_op_res_gpointer (simple);
- /* Transfer ownership */
- *out_csum = data->result_csum;
- data->result_csum = NULL;
+ ot_transfer_out_value (out_csum, &data->result_csum);
return TRUE;
}
@@ -1558,13 +1611,13 @@ apply_commit_filter (OstreeRepo *self,
}
static gboolean
-stage_directory_to_mtree_internal (OstreeRepo *self,
- GFile *dir,
- OstreeMutableTree *mtree,
- OstreeRepoCommitModifier *modifier,
- GPtrArray *path,
- GCancellable *cancellable,
- GError **error)
+stage_directory_to_mtree_internal (OstreeRepo *self,
+ GFile *dir,
+ OstreeMutableTree *mtree,
+ OstreeRepoCommitModifier *modifier,
+ GPtrArray *path,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
gboolean repo_dir_was_empty = FALSE;
@@ -1661,7 +1714,8 @@ stage_directory_to_mtree_internal (OstreeRepo *self,
goto out;
if (!stage_directory_to_mtree_internal (self, child, child_mtree,
- modifier, path, cancellable, error))
+ modifier, path,
+ cancellable, error))
goto out;
}
else if (repo_dir)
@@ -1735,19 +1789,32 @@ stage_directory_to_mtree_internal (OstreeRepo *self,
return ret;
}
+/**
+ * ostree_repo_stage_directory_to_mtree:
+ * @self:
+ * @dir: Path to a directory
+ * @mtree: Overlay directory contents into this tree
+ * @modifier: (allow-none): Optional modifier
+ * @cancellable:
+ * @error:
+ *
+ * Store objects for @dir and all children into the repository @self,
+ * overlaying the resulting filesystem hierarchy into @mtree.
+ */
gboolean
-ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
- GFile *dir,
- OstreeMutableTree *mtree,
- OstreeRepoCommitModifier *modifier,
- GCancellable *cancellable,
- GError **error)
+ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
+ GFile *dir,
+ OstreeMutableTree *mtree,
+ OstreeRepoCommitModifier *modifier,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
GPtrArray *path = NULL;
path = g_ptr_array_new ();
- if (!stage_directory_to_mtree_internal (self, dir, mtree, modifier, path, cancellable, error))
+ if (!stage_directory_to_mtree_internal (self, dir, mtree, modifier, path,
+ cancellable, error))
goto out;
ret = TRUE;
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index bc2ca96..85a02a2 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -85,6 +85,15 @@ 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_abort_transaction (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
@@ -227,20 +236,20 @@ OstreeRepoCommitModifier *ostree_repo_commit_modifier_new (void);
void ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier);
-gboolean ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
- GFile *dir,
- OstreeMutableTree *mtree,
- OstreeRepoCommitModifier *modifier,
- GCancellable *cancellable,
- GError **error);
-
-gboolean ostree_repo_stage_archive_to_mtree (OstreeRepo *self,
- GFile *archive,
- OstreeMutableTree *tree,
- OstreeRepoCommitModifier *modifier,
- gboolean autocreate_parents,
- GCancellable *cancellable,
- GError **error);
+gboolean ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
+ GFile *dir,
+ OstreeMutableTree *mtree,
+ OstreeRepoCommitModifier *modifier,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean ostree_repo_stage_archive_to_mtree (OstreeRepo *self,
+ GFile *archive,
+ OstreeMutableTree *tree,
+ OstreeRepoCommitModifier *modifier,
+ gboolean autocreate_parents,
+ GCancellable *cancellable,
+ GError **error);
gboolean ostree_repo_stage_mtree (OstreeRepo *self,
OstreeMutableTree *tree,
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 83191ad..facdee1 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -36,6 +36,7 @@ static gboolean opt_no_xattrs;
static char **opt_trees;
static gint opt_owner_uid = -1;
static gint opt_owner_gid = -1;
+static gboolean opt_table_output;
static GOptionEntry options[] = {
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "subject" },
@@ -49,6 +50,7 @@ static GOptionEntry options[] = {
{ "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, "When loading tar
archives, automatically create parent directories as needed", NULL },
{ "skip-if-unchanged", 0, 0, G_OPTION_ARG_NONE, &opt_skip_if_unchanged, "If the contents are unchanged
from previous commit, do nothing", NULL },
{ "statoverride", 0, 0, G_OPTION_ARG_FILENAME, &opt_statoverride_file, "File containing list of
modifications to make to permissions", "path" },
+ { "table-output", 0, 0, G_OPTION_ARG_NONE, &opt_table_output, "Output more information in a KEY: VALUE
format", NULL },
{ NULL }
};
@@ -138,6 +140,11 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, 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 OstreeRepo *repo = NULL;
gs_unref_object GFile *arg = NULL;
gs_free char *parent = NULL;
@@ -323,7 +330,13 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
&commit_checksum, cancellable, error))
goto out;
- if (!ostree_repo_commit_transaction (repo, cancellable, error))
+ if (!ostree_repo_commit_transaction_with_stats (repo,
+ &metadata_total,
+ &metadata_written,
+ &content_total,
+ &content_written,
+ &content_bytes_written,
+ cancellable, error))
goto out;
in_transaction = FALSE;
@@ -331,7 +344,6 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
if (!ostree_repo_write_ref (repo, NULL, opt_branch, commit_checksum, error))
goto out;
- g_print ("%s\n", commit_checksum);
}
else
{
@@ -340,7 +352,21 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
in_transaction = FALSE;
- g_print ("%s\n", parent);
+ commit_checksum = g_strdup (parent);
+ }
+
+ 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);
+ }
+ else
+ {
+ g_print ("%s\n", commit_checksum);
}
ret = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]