From b0d9ca8a469be6862f5a3db0e6ad32f140b6616c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:20:14 +0100 Subject: [PATCH] Add `election_scheduler` stats (#4151) --- 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 e857624dc..28a099a03 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 }; @@ -264,6 +265,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 cbf59f8f1..bb13de2eb 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); node.active.insert (block, election_behavior); } else if (priority_queue_predicate ()) @@ -151,10 +157,15 @@ void nano::election_scheduler::run () priority.pop (); lock.unlock (); std::shared_ptr election; - election = node.active.insert (block).election; - if (election != nullptr) + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority); + auto result = node.active.insert (block); + if (result.inserted) { - election->transition_active (); + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success); + } + if (result.election != nullptr) + { + result.election->transition_active (); } } else diff --git a/nano/node/election_scheduler.hpp b/nano/node/election_scheduler.hpp index a8ce5cd71..54ddc6ba8 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 @@ public: private: // Dependencies nano::node & node; + nano::stats & stats; private: void run (); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 7b96066c5..2f21b2a4b 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),