From 327806b838449bd1316948ea06d0cb1a2b11d5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:21:27 +0100 Subject: [PATCH] Add `election_scheduler` stats --- nano/lib/stats_enums.hpp | 7 +++++++ nano/node/election_scheduler.cpp | 21 ++++++++++++++++----- nano/node/election_scheduler.hpp | 3 ++- nano/node/node.cpp | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index c638688e1f..d061e9c784 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -41,6 +41,7 @@ enum class type : uint8_t active_timeout, backlog, unchecked, + election_scheduler, _last // Must be the last enum }; @@ -262,6 +263,12 @@ enum class detail : uint8_t satisfied, trigger, + // election scheduler + insert_manual, + insert_priority, + insert_priority_success, + erase_oldest, + _last // Must be the last enum }; diff --git a/nano/node/election_scheduler.cpp b/nano/node/election_scheduler.cpp index a68773eddd..00ac280343 100644 --- a/nano/node/election_scheduler.cpp +++ b/nano/node/election_scheduler.cpp @@ -1,8 +1,9 @@ #include #include -nano::election_scheduler::election_scheduler (nano::node & node) : - node{ node } +nano::election_scheduler::election_scheduler (nano::node & node_a, nano::stats & stats_a) : + node{ node_a }, + stats{ stats_a } { } @@ -55,6 +56,7 @@ bool nano::election_scheduler::activate (nano::account const & account_a, nano:: debug_assert (block != nullptr); if (node.ledger.dependents_confirmed (transaction, *block)) { + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); auto balance = node.ledger.balance (transaction, hash); auto previous_balance = node.ledger.balance (transaction, conf_info.frontier); nano::lock_guard lock{ mutex }; @@ -133,9 +135,12 @@ void nano::election_scheduler::run () debug_assert ((std::this_thread::yield (), true)); // Introduce some random delay in debug builds if (!stopped) { + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::loop); + if (overfill_predicate ()) { lock.unlock (); + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::erase_oldest); node.active.erase_oldest (); } else if (manual_queue_predicate ()) @@ -143,6 +148,7 @@ void nano::election_scheduler::run () auto const [block, previous_balance, election_behavior] = manual_queue.front (); manual_queue.pop_front (); lock.unlock (); + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual); nano::unique_lock lock2 (node.active.mutex); node.active.insert_impl (lock2, block, election_behavior); } @@ -152,11 +158,16 @@ void nano::election_scheduler::run () priority.pop (); lock.unlock (); std::shared_ptr election; + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority); nano::unique_lock lock2 (node.active.mutex); - election = node.active.insert_impl (lock2, block).election; - if (election != nullptr) + auto result = node.active.insert_impl (lock2, block); + if (result.inserted) + { + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success); + } + if (result.election != nullptr) { - election->transition_active (); + result.election->transition_active (); } } else diff --git a/nano/node/election_scheduler.hpp b/nano/node/election_scheduler.hpp index a8ce5cd71f..54ddc6ba8f 100644 --- a/nano/node/election_scheduler.hpp +++ b/nano/node/election_scheduler.hpp @@ -19,7 +19,7 @@ class node; class election_scheduler final { public: - election_scheduler (nano::node &); + election_scheduler (nano::node &, nano::stats &); ~election_scheduler (); void start (); @@ -43,6 +43,7 @@ class election_scheduler final private: // Dependencies nano::node & node; + nano::stats & stats; private: void run (); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 7b96066c5e..2f21b2a4b3 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -195,7 +195,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co generator{ config, ledger, wallets, vote_processor, history, network, stats, /* non-final */ false }, final_generator{ config, ledger, wallets, vote_processor, history, network, stats, /* final */ true }, active (*this, confirmation_height_processor), - scheduler{ *this }, + scheduler{ *this, stats }, hinting{ nano::nodeconfig_to_hinted_scheduler_config (config), *this, inactive_vote_cache, active, online_reps, stats }, aggregator (config, stats, generator, final_generator, history, ledger, wallets, active), wallets (wallets_store.init_error (), *this),