From 61db31ff70e8c54694ee19ab2b9d25eb0cc97242 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 27 Apr 2024 15:29:48 +0200 Subject: [PATCH] feat(block_cache): add perfmon support --- include/dwarfs/block_cache.h | 4 +++- src/dwarfs/block_cache.cpp | 39 +++++++++++++++++++++++++++++------- src/dwarfs/filesystem_v2.cpp | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/dwarfs/block_cache.h b/include/dwarfs/block_cache.h index 43549ffd..4a611a41 100644 --- a/include/dwarfs/block_cache.h +++ b/include/dwarfs/block_cache.h @@ -40,11 +40,13 @@ class fs_section; class logger; class mmif; class os_access; +class performance_monitor; class block_cache { public: block_cache(logger& lgr, os_access const& os, std::shared_ptr mm, - const block_cache_options& options); + const block_cache_options& options, + std::shared_ptr perfmon); size_t block_count() const { return impl_->block_count(); } diff --git a/src/dwarfs/block_cache.cpp b/src/dwarfs/block_cache.cpp index 8c095c21..eb5fd0ee 100644 --- a/src/dwarfs/block_cache.cpp +++ b/src/dwarfs/block_cache.cpp @@ -48,6 +48,7 @@ #include "dwarfs/logger.h" #include "dwarfs/mmif.h" #include "dwarfs/options.h" +#include "dwarfs/performance_monitor.h" #include "dwarfs/worker_group.h" namespace dwarfs { @@ -138,10 +139,17 @@ template class block_cache_ final : public block_cache::impl { public: block_cache_(logger& lgr, os_access const& os, std::shared_ptr mm, - block_cache_options const& options) + block_cache_options const& options, + std::shared_ptr perfmon + [[maybe_unused]]) : cache_(0) , mm_(std::move(mm)) , LOG_PROXY_INIT(lgr) + // clang-format off + PERFMON_CLS_PROXY_INIT(perfmon, "block_cache") + PERFMON_CLS_TIMER_INIT(get, "block_no", "offset", "size") + PERFMON_CLS_TIMER_INIT(process, "block_no") + PERFMON_CLS_TIMER_INIT(decompress, "range_end") // clang-format on , os_{os} , options_(options) { if (options.init_workers) { @@ -287,6 +295,9 @@ class block_cache_ final : public block_cache::impl { std::future get(size_t block_no, size_t offset, size_t size) const override { + PERFMON_CLS_SCOPED_SECTION(get) + PERFMON_SET_CONTEXT(block_no, offset, size) + range_requests_.fetch_add(1, std::memory_order_relaxed); std::promise promise; @@ -485,7 +496,10 @@ class block_cache_ final : public block_cache::impl { } void process_job(std::shared_ptr brs) const { + PERFMON_CLS_SCOPED_SECTION(process) + auto block_no = brs->block_no(); + PERFMON_SET_CONTEXT(block_no) LOG_TRACE << "processing block " << block_no; @@ -546,11 +560,17 @@ class block_cache_ final : public block_cache::impl { } } - LOG_TRACE << "decompressing block " << block_no << " until position " - << req.end(); - try { - block->decompress_until(range_end); + if (range_end > block->range_end()) { + PERFMON_CLS_SCOPED_SECTION(decompress) + PERFMON_SET_CONTEXT(range_end) + + LOG_TRACE << "decompressing block " << block_no << " until position " + << req.end(); + + block->decompress_until(range_end); + } + req.fulfill(block); } catch (...) { req.error(std::current_exception()); @@ -652,6 +672,10 @@ class block_cache_ final : public block_cache::impl { std::vector block_; std::shared_ptr mm_; LOG_PROXY_DECL(LoggerPolicy); + PERFMON_CLS_PROXY_DECL + PERFMON_CLS_TIMER_DECL(get) + PERFMON_CLS_TIMER_DECL(process) + PERFMON_CLS_TIMER_DECL(decompress) os_access const& os_; const block_cache_options options_; cache_tidy_config tidy_config_; @@ -659,8 +683,9 @@ class block_cache_ final : public block_cache::impl { block_cache::block_cache(logger& lgr, os_access const& os, std::shared_ptr mm, - const block_cache_options& options) + const block_cache_options& options, + std::shared_ptr perfmon) : impl_(make_unique_logging_object( - lgr, os, std::move(mm), options)) {} + lgr, os, std::move(mm), options, std::move(perfmon))) {} } // namespace dwarfs diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index c3cda493..c10ee84a 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -553,7 +553,7 @@ filesystem_::filesystem_( PERFMON_CLS_TIMER_INIT(readv_iovec) PERFMON_CLS_TIMER_INIT(readv_future) // clang-format on { - block_cache cache(lgr, os_, mm_, options.block_cache); + block_cache cache(lgr, os_, mm_, options.block_cache, perfmon); filesystem_parser parser(mm_, image_offset_); if (parser.has_index()) {