From 460a0f045a953e0db041fab5199e358227f36e77 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 22 Nov 2024 15:55:12 +0100 Subject: [PATCH] Only print cache details in state explorer when asked for it. --- .../vespa/searchcore/proton/server/proton.cpp | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index f2efbe6f3e9..7a70baf9eaa 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -964,6 +964,7 @@ const std::string RESOURCE_USAGE = "resourceusage"; const std::string THREAD_POOLS = "threadpools"; const std::string HW_INFO = "hwinfo"; const std::string SESSION = "session"; +const std::string CACHE_NAME = "cache"; struct StateExplorerProxy : vespalib::StateExplorer { @@ -1008,22 +1009,42 @@ void insert_cache_stats(Cursor& object, const vespalib::CacheStats& stats) object.setLong("lookups", stats.lookups()); } -} // namespace proton:: +class CacheExplorer : public vespalib::StateExplorer { + const IPostingListCache& _posting_list_cache; +public: + CacheExplorer(const IPostingListCache& posting_list_cache) noexcept; + ~CacheExplorer() override; + void get_state(const vespalib::slime::Inserter& inserter, bool full) const override; +}; + +CacheExplorer::CacheExplorer(const IPostingListCache& posting_list_cache) noexcept + : _posting_list_cache(posting_list_cache) +{ +} + +CacheExplorer::~CacheExplorer() = default; void -Proton::get_state(const vespalib::slime::Inserter &inserter, bool) const +CacheExplorer::get_state(const vespalib::slime::Inserter& inserter, bool full) const { - if (_posting_list_cache) { - auto& object = inserter.insertObject().setObject("cache"); - insert_cache_stats(object.setObject("postinglist"), _posting_list_cache->get_stats()); - insert_cache_stats(object.setObject("bitvector"), _posting_list_cache->get_stats()); + auto &object = inserter.insertObject(); + if (full) { + insert_cache_stats(object.setObject("postinglist"), _posting_list_cache.get_stats()); + insert_cache_stats(object.setObject("bitvector"), _posting_list_cache.get_bitvector_stats()); } } +} // namespace proton:: + +void +Proton::get_state(const vespalib::slime::Inserter &, bool) const +{ +} + std::vector Proton::get_children_names() const { - return {DOCUMENT_DB, THREAD_POOLS, MATCH_ENGINE, FLUSH_ENGINE, TLS_NAME, HW_INFO, RESOURCE_USAGE, SESSION}; + return {DOCUMENT_DB, THREAD_POOLS, MATCH_ENGINE, FLUSH_ENGINE, TLS_NAME, HW_INFO, RESOURCE_USAGE, SESSION, CACHE_NAME}; } std::unique_ptr @@ -1052,6 +1073,8 @@ Proton::get_child(std::string_view name) const return std::make_unique(_hw_info); } else if (name == SESSION) { return std::make_unique(*_sessionManager); + } else if (name == CACHE_NAME && _posting_list_cache) { + return std::make_unique(*_posting_list_cache); } return {}; }