From 7c5db2a9943eaf779d659baa2f5ea343bad845d8 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Thu, 9 May 2024 13:00:30 +0200 Subject: [PATCH] feat(metadata): add perfmon support --- include/dwarfs/metadata_v2.h | 5 ++++- src/dwarfs/filesystem_v2.cpp | 9 +++++---- src/dwarfs/metadata_v2.cpp | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/include/dwarfs/metadata_v2.h b/include/dwarfs/metadata_v2.h index d328fbe2..1f38a017 100644 --- a/include/dwarfs/metadata_v2.h +++ b/include/dwarfs/metadata_v2.h @@ -46,6 +46,8 @@ struct filesystem_info; struct file_stat; struct vfs_stat; +class performance_monitor; + namespace thrift::metadata { class metadata; } @@ -58,7 +60,8 @@ class metadata_v2 { metadata_v2(logger& lgr, std::span schema, std::span data, metadata_options const& options, - int inode_offset = 0, bool force_consistency_check = false); + int inode_offset = 0, bool force_consistency_check = false, + std::shared_ptr perfmon = nullptr); void check_consistency() const { impl_->check_consistency(); } diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index c10ee84a..5efb5601 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -332,7 +332,8 @@ make_metadata(logger& lgr, std::shared_ptr mm, const metadata_options& options, int inode_offset = 0, bool force_buffers = false, mlock_mode lock_mode = mlock_mode::NONE, - bool force_consistency_check = false) { + bool force_consistency_check = false, + std::shared_ptr perfmon = nullptr) { LOG_PROXY(debug_logger_policy, lgr); auto schema_it = sections.find(section_type::METADATA_V2_SCHEMA); auto meta_it = sections.find(section_type::METADATA_V2); @@ -379,7 +380,7 @@ make_metadata(logger& lgr, std::shared_ptr mm, get_section_data(mm, schema_it->second.front(), schema_buffer, force_buffers), meta_section_range, options, inode_offset, - force_consistency_check); + force_consistency_check, perfmon); } template @@ -529,7 +530,7 @@ template filesystem_::filesystem_( logger& lgr, os_access const& os, std::shared_ptr mm, const filesystem_options& options, - std::shared_ptr perfmon [[maybe_unused]]) + std::shared_ptr perfmon) : LOG_PROXY_INIT(lgr) , os_{os} , mm_{std::move(mm)} @@ -598,7 +599,7 @@ filesystem_::filesystem_( meta_ = make_metadata(lgr, mm_, sections, schema_buffer, meta_buffer_, options.metadata, options.inode_offset, false, - options.lock_mode, !parser.has_checksums()); + options.lock_mode, !parser.has_checksums(), perfmon); LOG_DEBUG << "read " << cache.block_count() << " blocks and " << meta_.size() << " bytes of metadata"; diff --git a/src/dwarfs/metadata_v2.cpp b/src/dwarfs/metadata_v2.cpp index 71d7a9b6..9e25a0fb 100644 --- a/src/dwarfs/metadata_v2.cpp +++ b/src/dwarfs/metadata_v2.cpp @@ -53,6 +53,7 @@ #include "dwarfs/logger.h" #include "dwarfs/metadata_v2.h" #include "dwarfs/options.h" +#include "dwarfs/performance_monitor.h" #include "dwarfs/string_table.h" #include "dwarfs/util.h" #include "dwarfs/vfs_stat.h" @@ -393,7 +394,8 @@ class metadata_ final : public metadata_v2::impl { public: metadata_(logger& lgr, std::span schema, std::span data, metadata_options const& options, - int inode_offset, bool force_consistency_check) + int inode_offset, bool force_consistency_check, + std::shared_ptr perfmon [[maybe_unused]]) : data_(data) , meta_( check_frozen(map_frozen(schema, data_))) @@ -420,7 +422,15 @@ class metadata_ final : public metadata_v2::impl { , options_(options) , symlinks_(meta_.compact_symlinks() ? string_table(lgr, "symlinks", *meta_.compact_symlinks()) - : string_table(meta_.symlinks())) { + : string_table(meta_.symlinks())) + // clang-format off + PERFMON_CLS_PROXY_INIT(perfmon, "metadata_v2") + PERFMON_CLS_TIMER_INIT(find) + PERFMON_CLS_TIMER_INIT(getattr) + PERFMON_CLS_TIMER_INIT(readdir) + PERFMON_CLS_TIMER_INIT(reg_file_size) + PERFMON_CLS_TIMER_INIT(unpack_metadata) // clang-format on + { if (static_cast(meta_.directories().size() - 1) != symlink_inode_offset_) { DWARFS_THROW( @@ -674,6 +684,7 @@ class metadata_ final : public metadata_v2::impl { } size_t reg_file_size(inode_view iv) const { + PERFMON_CLS_SCOPED_SECTION(reg_file_size) auto cr = get_chunk_range(iv.inode_num()); DWARFS_CHECK(cr, "invalid chunk range"); return std::accumulate( @@ -846,6 +857,12 @@ class metadata_ final : public metadata_v2::impl { const int unique_files_; const metadata_options options_; const string_table symlinks_; + PERFMON_CLS_PROXY_DECL + PERFMON_CLS_TIMER_DECL(find) + PERFMON_CLS_TIMER_DECL(getattr) + PERFMON_CLS_TIMER_DECL(readdir) + PERFMON_CLS_TIMER_DECL(reg_file_size) + PERFMON_CLS_TIMER_DECL(unpack_metadata) }; template @@ -1310,6 +1327,8 @@ folly::dynamic metadata_::as_dynamic() const { template thrift::metadata::metadata metadata_::unpack_metadata() const { + PERFMON_CLS_SCOPED_SECTION(unpack_metadata) + auto meta = meta_.thaw(); if (auto opts = meta.options()) { @@ -1460,6 +1479,8 @@ void metadata_::walk_data_order_impl( template std::optional metadata_::find(directory_view dir, std::string_view name) const { + PERFMON_CLS_SCOPED_SECTION(find) + auto range = dir.entry_range(); auto it = std::lower_bound(range.begin(), range.end(), name, @@ -1530,6 +1551,8 @@ metadata_::find(int inode, const char* name) const { template int metadata_::getattr(inode_view iv, file_stat* stbuf) const { + PERFMON_CLS_SCOPED_SECTION(getattr) + ::memset(stbuf, 0, sizeof(*stbuf)); auto mode = iv.mode(); @@ -1590,6 +1613,8 @@ metadata_::opendir(inode_view iv) const { template std::optional> metadata_::readdir(directory_view dir, size_t offset) const { + PERFMON_CLS_SCOPED_SECTION(readdir) + switch (offset) { case 0: return std::pair(make_inode_view(dir.inode()), "."); @@ -1815,9 +1840,11 @@ metadata_v2::freeze(const thrift::metadata::metadata& data) { metadata_v2::metadata_v2(logger& lgr, std::span schema, std::span data, metadata_options const& options, int inode_offset, - bool force_consistency_check) + bool force_consistency_check, + std::shared_ptr perfmon) : impl_(make_unique_logging_object( - lgr, schema, data, options, inode_offset, force_consistency_check)) {} + lgr, schema, data, options, inode_offset, force_consistency_check, + std::move(perfmon))) {} } // namespace dwarfs