Skip to content

Commit

Permalink
Stats & logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 9, 2024
1 parent 124421b commit 8a968e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ enum class detail : uint8_t
representative_mismatch,
block_position,

// blockprocessor result
// blockprocessor
process_blocking,
process_blocking_timeout,

// block source
live,
bootstrap,
bootstrap_legacy,
Expand Down
16 changes: 16 additions & 0 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ void nano::block_processor::add (std::shared_ptr<nano::block> const & block, blo
node.stats.inc (nano::stat::type::blockprocessor, nano::stat::detail::insufficient_work);
return;
}

node.stats.inc (nano::stat::type::blockprocessor, nano::stat::detail::process);
node.logger.debug (nano::log::type::blockprocessor, "Processing block (async): {} (source: {})", block->hash ().to_string (), to_string (source));

add_impl (block, context{ source });
}

std::optional<nano::process_return> nano::block_processor::add_blocking (std::shared_ptr<nano::block> const & block, block_source const source)
{
node.stats.inc (nano::stat::type::blockprocessor, nano::stat::detail::process_blocking);
node.logger.debug (nano::log::type::blockprocessor, "Processing block (blocking): {} (source: {})", block->hash ().to_string (), to_string (source));

context ctx{ source };
auto future = ctx.get_future ();
add_impl (block, std::move (ctx));

try
{
auto status = future.wait_for (node.config.block_process_timeout);
Expand All @@ -107,7 +115,10 @@ std::optional<nano::process_return> nano::block_processor::add_blocking (std::sh
}
catch (std::future_error const &)
{
node.stats.inc (nano::stat::type::blockprocessor, nano::stat::detail::process_blocking_timeout);
node.logger.error (nano::log::type::blockprocessor, "Timeout processing block: {}", block->hash ().to_string ());
}

return std::nullopt;
}

Expand Down Expand Up @@ -415,6 +426,11 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (bl
return composite;
}

std::string_view nano::to_string (nano::block_source source)
{
return magic_enum::enum_name (source);
}

nano::stat::detail nano::to_stat_detail (nano::block_source type)
{
auto value = magic_enum::enum_cast<nano::stat::detail> (magic_enum::enum_name (type));
Expand Down
1 change: 1 addition & 0 deletions nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class block_source
forced,
};

std::string_view to_string (nano::block_source);
nano::stat::detail to_stat_detail (block_source);

/**
Expand Down

0 comments on commit 8a968e9

Please sign in to comment.