Add election_scheduler stats (#4151)

This commit is contained in:
Piotr Wójcik 2023-02-23 14:20:14 +01:00 committed by GitHub
commit b0d9ca8a46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 7 deletions

View file

@ -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
};

View file

@ -1,8 +1,9 @@
#include <nano/node/election_scheduler.hpp>
#include <nano/node/node.hpp>
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<nano::mutex> 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<nano::election> 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

View file

@ -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 ();

View file

@ -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),