From 8eac5be030797607715d5a2d973c55edff78a8a2 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 2 Nov 2018 15:39:34 -0400 Subject: [PATCH] lib/commit: Add devino_cache_hits to txn stats I found this useful while hacking on rpm-ostree but I think it might be useful enough to upstream. This stat is really helpful for validating that a pipeline is hitting the devino cache sweet spot. Closes: #1772 Approved by: cgwalters --- src/libostree/ostree-repo-commit.c | 7 +++++++ src/libostree/ostree-repo.h | 3 ++- src/ostree/ot-builtin-commit.c | 1 + tests/test-basic-user.sh | 3 ++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 134024b843..52bc5d29c6 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -3338,6 +3338,9 @@ write_content_to_mtree_internal (OstreeRepo *self, if (!glnx_shutil_rm_rf_at (dfd_iter->fd, name, cancellable, error)) return FALSE; } + g_mutex_lock (&self->txn_lock); + self->txn.stats.devino_cache_hits++; + g_mutex_unlock (&self->txn_lock); return TRUE; /* Early return */ } } @@ -3469,6 +3472,10 @@ write_content_to_mtree_internal (OstreeRepo *self, if (!ostree_mutable_tree_replace_file (mtree, name, loose_checksum, error)) return FALSE; + + g_mutex_lock (&self->txn_lock); + self->txn.stats.devino_cache_hits++; + g_mutex_unlock (&self->txn_lock); } /* Next fast path - we can "adopt" the file */ else if (can_adopt) diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 829164ba92..007cbeddc3 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -291,8 +291,9 @@ struct _OstreeRepoTransactionStats { guint content_objects_total; guint content_objects_written; guint64 content_bytes_written; + guint devino_cache_hits; - guint64 padding1; + guint padding1; guint64 padding2; guint64 padding3; guint64 padding4; diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 535239bece..b7c61a9e20 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -835,6 +835,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio 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 Cache Hits: %u\n", stats.devino_cache_hits); g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written); } else diff --git a/tests/test-basic-user.sh b/tests/test-basic-user.sh index bd95f5ed5e..7bdb6a0ce2 100755 --- a/tests/test-basic-user.sh +++ b/tests/test-basic-user.sh @@ -117,9 +117,10 @@ assert_file_has_content ls.txt "^-006.. ${newuid} ${newgid} .*/baz/cow" # But --devino-canonical should override that $OSTREE commit ${COMMIT_ARGS} --owner-uid ${newuid} --owner-gid ${newgid} \ - -I -b test2-devino-test --tree=dir=test2-checkout + -I -b test2-devino-test --table-output --tree=dir=test2-checkout > out.txt $OSTREE ls test2-devino-test /baz/cow > ls.txt assert_file_has_content ls.txt "^-006.. ${myuid} ${mygid} .*/baz/cow" +assert_file_has_content out.txt "Content Cache Hits: [1-9][0-9]*" $OSTREE refs --delete test2-{linkcheckout,devino}-test echo "ok commit with -I"