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.
This commit is contained in:
parent
6fc9483887
commit
5aea9db3f2
|
|
@ -266,7 +266,8 @@ stage_libarchive_entry_to_mtree (OstreeRepo *self,
|
||||||
goto out;
|
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;
|
goto out;
|
||||||
|
|
||||||
g_free (tmp_checksum);
|
g_free (tmp_checksum);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ struct OstreeRepo {
|
||||||
GFile *config_file;
|
GFile *config_file;
|
||||||
|
|
||||||
GFile *transaction_lock_path;
|
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;
|
GMutex cache_lock;
|
||||||
GPtrArray *cached_meta_indexes;
|
GPtrArray *cached_meta_indexes;
|
||||||
|
|
|
||||||
|
|
@ -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_meta_indexes, (GDestroyNotify) g_ptr_array_unref);
|
||||||
g_clear_pointer (&self->cached_content_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->cache_lock);
|
||||||
|
g_mutex_clear (&self->txn_stats_lock);
|
||||||
|
|
||||||
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
|
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
@ -177,6 +178,7 @@ static void
|
||||||
ostree_repo_init (OstreeRepo *self)
|
ostree_repo_init (OstreeRepo *self)
|
||||||
{
|
{
|
||||||
g_mutex_init (&self->cache_lock);
|
g_mutex_init (&self->cache_lock);
|
||||||
|
g_mutex_init (&self->txn_stats_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
OstreeRepo*
|
OstreeRepo*
|
||||||
|
|
@ -736,6 +738,25 @@ stage_object (OstreeRepo *self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
if (checksum)
|
||||||
ret_csum = ot_csum_from_gchecksum (checksum);
|
ret_csum = ot_csum_from_gchecksum (checksum);
|
||||||
|
|
||||||
|
|
@ -988,6 +1009,12 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
else
|
else
|
||||||
ret_transaction_resume = FALSE;
|
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;
|
self->in_transaction = TRUE;
|
||||||
if (ret_transaction_resume)
|
if (ret_transaction_resume)
|
||||||
{
|
{
|
||||||
|
|
@ -1016,7 +1043,12 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_commit_transaction (OstreeRepo *self,
|
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,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
|
@ -1031,11 +1063,25 @@ ostree_repo_commit_transaction (OstreeRepo *self,
|
||||||
g_hash_table_remove_all (self->loose_object_devino_hash);
|
g_hash_table_remove_all (self->loose_object_devino_hash);
|
||||||
|
|
||||||
self->in_transaction = FALSE;
|
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;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
return ret;
|
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
|
gboolean
|
||||||
ostree_repo_abort_transaction (OstreeRepo *self,
|
ostree_repo_abort_transaction (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -1366,6 +1412,15 @@ ostree_repo_stage_content_async (OstreeRepo *self,
|
||||||
g_object_unref (asyncdata->result);
|
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
|
gboolean
|
||||||
ostree_repo_stage_content_finish (OstreeRepo *self,
|
ostree_repo_stage_content_finish (OstreeRepo *self,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
|
|
@ -1381,9 +1436,7 @@ ostree_repo_stage_content_finish (OstreeRepo *self,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||||
/* Transfer ownership */
|
ot_transfer_out_value (out_csum, &data->result_csum);
|
||||||
*out_csum = data->result_csum;
|
|
||||||
data->result_csum = NULL;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1661,7 +1714,8 @@ stage_directory_to_mtree_internal (OstreeRepo *self,
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!stage_directory_to_mtree_internal (self, child, child_mtree,
|
if (!stage_directory_to_mtree_internal (self, child, child_mtree,
|
||||||
modifier, path, cancellable, error))
|
modifier, path,
|
||||||
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else if (repo_dir)
|
else if (repo_dir)
|
||||||
|
|
@ -1735,6 +1789,18 @@ stage_directory_to_mtree_internal (OstreeRepo *self,
|
||||||
return ret;
|
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
|
gboolean
|
||||||
ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
|
ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
|
||||||
GFile *dir,
|
GFile *dir,
|
||||||
|
|
@ -1747,7 +1813,8 @@ ostree_repo_stage_directory_to_mtree (OstreeRepo *self,
|
||||||
GPtrArray *path = NULL;
|
GPtrArray *path = NULL;
|
||||||
|
|
||||||
path = g_ptr_array_new ();
|
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;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,15 @@ gboolean ostree_repo_commit_transaction (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
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,
|
gboolean ostree_repo_abort_transaction (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ static gboolean opt_no_xattrs;
|
||||||
static char **opt_trees;
|
static char **opt_trees;
|
||||||
static gint opt_owner_uid = -1;
|
static gint opt_owner_uid = -1;
|
||||||
static gint opt_owner_gid = -1;
|
static gint opt_owner_gid = -1;
|
||||||
|
static gboolean opt_table_output;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "subject" },
|
{ "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 },
|
{ "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 },
|
{ "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" },
|
{ "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 }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -138,6 +140,11 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gboolean skip_commit = FALSE;
|
gboolean skip_commit = FALSE;
|
||||||
gboolean in_transaction = 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 OstreeRepo *repo = NULL;
|
||||||
gs_unref_object GFile *arg = NULL;
|
gs_unref_object GFile *arg = NULL;
|
||||||
gs_free char *parent = 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))
|
&commit_checksum, cancellable, error))
|
||||||
goto out;
|
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;
|
goto out;
|
||||||
|
|
||||||
in_transaction = FALSE;
|
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))
|
if (!ostree_repo_write_ref (repo, NULL, opt_branch, commit_checksum, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_print ("%s\n", commit_checksum);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -340,7 +352,21 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
|
||||||
|
|
||||||
in_transaction = FALSE;
|
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;
|
ret = TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue