diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index bffd585d5c..18e3350310 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -280,23 +280,22 @@ struct block_time_tracker { last_time_point = now; } - void report(uint32_t block_num, account_name producer, producer_plugin::speculative_block_metrics& metrics) { - auto now = fc::time_point::now(); - report(block_num, producer, now); - metrics.block_producer = producer; - metrics.block_num = block_num; - metrics.block_total_time_us = (now - clear_time_point).count(); - metrics.block_idle_us = block_idle_time.count(); - metrics.num_success_trx = trx_success_num; - metrics.success_trx_time_us = trx_success_time.count(); - metrics.num_fail_trx = trx_fail_num; - metrics.fail_trx_time_us = trx_fail_time.count(); - metrics.num_transient_trx = transient_trx_num; + void populate_speculative_block_metrics(uint32_t block_num, account_name producer, const fc::time_point& now, + producer_plugin::speculative_block_metrics& metrics) { + metrics.block_producer = producer; + metrics.block_num = block_num; + metrics.block_total_time_us = (now - clear_time_point).count(); + metrics.block_idle_us = block_idle_time.count(); + metrics.num_success_trx = trx_success_num; + metrics.success_trx_time_us = trx_success_time.count(); + metrics.num_fail_trx = trx_fail_num; + metrics.fail_trx_time_us = trx_fail_time.count(); + metrics.num_transient_trx = transient_trx_num; metrics.transient_trx_time_us = transient_trx_time.count(); - metrics.block_other_time_us = other_time.count(); + metrics.block_other_time_us = other_time.count(); } - void report(uint32_t block_num, account_name producer, const fc::time_point& now = fc::time_point::now()) { + void report(uint32_t block_num, account_name producer, const fc::time_point& now) { using namespace std::string_literals; assert(!paused); if( _log.is_enabled( fc::log_level::debug ) ) { @@ -882,10 +881,13 @@ class producer_plugin_impl : public std::enable_shared_from_this().size(); - metrics.trxs_produced_total = new_b->transactions.size(); - metrics.cpu_usage_us = br.total_cpu_usage_us; + metrics.scheduled_trxs_total = chain.db().get_index().size(); + metrics.trxs_produced_total = new_b->transactions.size(); + metrics.cpu_usage_us = br.total_cpu_usage_us; metrics.total_elapsed_time_us = br.total_elapsed_time.count(); - metrics.total_time_us = (fc::time_point::now() - br.start_time).count(); - metrics.net_usage_us = br.total_net_usage; - metrics.last_irreversible = chain.last_irreversible_block_num(); - metrics.head_block_num = chain.head().block_num(); - _update_produced_block_metrics(metrics); + metrics.total_time_us = (now - br.start_time).count(); + metrics.net_usage_us = br.total_net_usage; + metrics.last_irreversible = chain.last_irreversible_block_num(); + metrics.head_block_num = chain.head().block_num(); - _time_tracker.add_other_time(); - _time_tracker.report(new_b->block_num(), new_b->producer, metrics); - } else { - _time_tracker.add_other_time(); - _time_tracker.report(new_b->block_num(), new_b->producer); + _time_tracker.populate_speculative_block_metrics(new_b->block_num(), new_b->producer, now, metrics); + _update_produced_block_metrics(metrics); } + + fc::time_point now = fc::time_point::now(); + _time_tracker.add_other_time(now); + _time_tracker.report(new_b->block_num(), new_b->producer, now); _time_tracker.clear(); }