From a0410919628b799b424fda76708418f3baf83d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 24 May 2024 12:33:55 +0200 Subject: [PATCH] Stats --- nano/lib/logging_enums.hpp | 1 + nano/lib/stats_enums.hpp | 20 ++++++- nano/node/active_elections.cpp | 98 +++++++++++++++++++++++++++++----- nano/node/active_elections.hpp | 4 ++ nano/node/confirming_set.cpp | 2 +- nano/node/election_status.hpp | 3 ++ 6 files changed, 112 insertions(+), 16 deletions(-) diff --git a/nano/lib/logging_enums.hpp b/nano/lib/logging_enums.hpp index f78371b79..780d2b01b 100644 --- a/nano/lib/logging_enums.hpp +++ b/nano/lib/logging_enums.hpp @@ -108,6 +108,7 @@ enum class detail // active_elections active_started, active_stopped, + active_cemented, // election election_confirmed, diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 7ae41defd..355f426e6 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -62,9 +62,11 @@ enum class type active, active_elections, active_started, + active_stopped, active_confirmed, active_dropped, active_timeout, + active_cemented, backlog, unchecked, election_scheduler, @@ -378,6 +380,10 @@ enum class detail insert, insert_failed, + // active_elections + started, + stopped, + // unchecked put, satisfied, @@ -447,7 +453,19 @@ enum class detail // confirming_set notify_cemented, - notify_already_confirmed, + notify_already_cemented, + + // election_state + passive, + active, + expired_confirmed, + expired_unconfirmed, + + // election_status_type + ongoing, + active_confirmed_quorum, + active_confirmation_height, + inactive_confirmation_height, _last // Must be the last enum }; diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index ba6ec9548..31927cb73 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -120,7 +120,13 @@ void nano::active_elections::block_cemented_callback (nano::secure::transaction } recently_cemented.put (status); + node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::cemented); + node.stats.inc (nano::stat::type::active_cemented, to_stat_detail (status.type)); + + node.logger.trace (nano::log::type::active_elections, nano::log::detail::active_cemented, nano::log::arg{ "election", election }); + notify_observers (transaction, status, votes); + bool cemented_bootstrap_count_reached = node.ledger.cemented_count () >= node.ledger.bootstrap_weight_max_blocks; bool was_active = status.type == nano::election_status_type::active_confirmed_quorum || status.type == nano::election_status_type::active_confirmation_height; @@ -302,7 +308,10 @@ void nano::active_elections::cleanup_election (nano::unique_lock & roots.get ().erase (roots.get ().find (election->qualified_root)); - node.stats.inc (completion_type (*election), to_stat_detail (election->behavior ())); + node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::stopped); + node.stats.inc (nano::stat::type::active_stopped, to_stat_detail (election->state ())); + node.stats.inc (to_stat_type (election->state ()), to_stat_detail (election->behavior ())); + node.logger.trace (nano::log::type::active_elections, nano::log::detail::active_stopped, nano::log::arg{ "election", election }); node.logger.debug (nano::log::type::active_elections, "Erased election for blocks: {} (behavior: {}, state: {})", @@ -332,19 +341,6 @@ void nano::active_elections::cleanup_election (nano::unique_lock & } } -nano::stat::type nano::active_elections::completion_type (nano::election const & election) const -{ - if (election.confirmed ()) - { - return nano::stat::type::active_confirmed; - } - if (election.failed ()) - { - return nano::stat::type::active_timeout; - } - return nano::stat::type::active_dropped; -} - std::vector> nano::active_elections::list_active (std::size_t max_a) { nano::lock_guard guard{ mutex }; @@ -421,7 +417,9 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< debug_assert (count_by_behavior[result.election->behavior ()] >= 0); count_by_behavior[result.election->behavior ()]++; + node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::started); node.stats.inc (nano::stat::type::active_started, to_stat_detail (election_behavior_a)); + node.logger.trace (nano::log::type::active_elections, nano::log::detail::active_started, nano::log::arg{ "behavior", election_behavior_a }, nano::log::arg{ "election", result.election }); @@ -598,3 +596,75 @@ nano::error nano::active_elections_config::deserialize (nano::tomlconfig & toml) return toml.get_error (); } + +/* + * + */ + +nano::stat::type nano::to_stat_type (nano::election_state state) +{ + switch (state) + { + case election_state::passive: + case election_state::active: + return nano::stat::type::active_dropped; + break; + case election_state::confirmed: + case election_state::expired_confirmed: + return nano::stat::type::active_confirmed; + break; + case election_state::expired_unconfirmed: + return nano::stat::type::active_timeout; + break; + } + debug_assert (false); + return {}; +} + +nano::stat::detail nano::to_stat_detail (nano::election_state state) +{ + switch (state) + { + case election_state::passive: + return nano::stat::detail::passive; + break; + case election_state::active: + return nano::stat::detail::active; + break; + case election_state::confirmed: + return nano::stat::detail::confirmed; + break; + case election_state::expired_confirmed: + return nano::stat::detail::expired_confirmed; + break; + case election_state::expired_unconfirmed: + return nano::stat::detail::expired_unconfirmed; + break; + } + debug_assert (false); + return {}; +} + +nano::stat::detail nano::to_stat_detail (nano::election_status_type type) +{ + switch (type) + { + case election_status_type::ongoing: + return nano::stat::detail::ongoing; + break; + case election_status_type::active_confirmed_quorum: + return nano::stat::detail::active_confirmed_quorum; + break; + case election_status_type::active_confirmation_height: + return nano::stat::detail::active_confirmation_height; + break; + case election_status_type::inactive_confirmation_height: + return nano::stat::detail::inactive_confirmation_height; + break; + case election_status_type::stopped: + return nano::stat::detail::stopped; + break; + } + debug_assert (false); + return {}; +} \ No newline at end of file diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index 031174070..ba40bb9d1 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -36,6 +36,7 @@ class confirming_set; class election; class vote; class stats; +enum class election_state; } namespace nano::secure { @@ -197,4 +198,7 @@ public: // Tests }; std::unique_ptr collect_container_info (active_elections & active_elections, std::string const & name); + +nano::stat::type to_stat_type (nano::election_state); +nano::stat::detail to_stat_detail (nano::election_state); } diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index c161ab8f5..b7f675bf8 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -21,7 +21,7 @@ nano::confirming_set::confirming_set (nano::ledger & ledger_a, nano::stats & sta } for (auto const & i : notification.already_cemented) { - stats.inc (nano::stat::type::confirming_set, nano::stat::detail::notify_already_confirmed); + stats.inc (nano::stat::type::confirming_set, nano::stat::detail::notify_already_cemented); block_already_cemented_observers.notify (i); } }); diff --git a/nano/node/election_status.hpp b/nano/node/election_status.hpp index 014a14ad7..548bf8e2b 100644 --- a/nano/node/election_status.hpp +++ b/nano/node/election_status.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -22,6 +23,8 @@ enum class election_status_type : uint8_t stopped = 5 }; +nano::stat::detail to_stat_detail (election_status_type); + /* Holds a summary of an election */ class election_status final {