diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h index 3646d050..dc7d74dc 100644 --- a/contrib/epee/include/math_helper.h +++ b/contrib/epee/include/math_helper.h @@ -51,6 +51,7 @@ namespace math_helper average() { m_base = default_base; + m_count = 0; } bool set_base() @@ -71,6 +72,7 @@ namespace math_helper CRITICAL_REGION_LOCAL(m_lock); //#ifndef DEBUG_STUB + m_count++; m_list.push_back(vl); if(m_list.size() > m_base ) m_list.pop_front(); @@ -106,9 +108,20 @@ namespace math_helper return 0; } + uint64_t& get_count() + { + return m_count; + } + + void reset() + { + m_count = 0; + m_list.clear(); + } private: - unsigned int m_base; + unsigned int m_base; + uint64_t m_count; std::list m_list; mutable critical_section m_lock; }; diff --git a/src/common/db_abstract_accessor.h b/src/common/db_abstract_accessor.h index 413bd93d..61126293 100644 --- a/src/common/db_abstract_accessor.h +++ b/src/common/db_abstract_accessor.h @@ -75,15 +75,18 @@ namespace tools std::map > m_transactions_stack; std::atomic m_is_open; epee::shared_recursive_mutex& m_rwlock; - public: struct performance_data { epee::math_helper::average backend_set_pod_time; epee::math_helper::average backend_set_t_time; epee::math_helper::average set_serialize_t_time; + epee::math_helper::average backend_get_pod_time; + epee::math_helper::average backend_get_t_time; + epee::math_helper::average get_serialize_t_time; }; private: + mutable performance_data m_gperformance_data; mutable std::unordered_map m_performance_data_map; public: basic_db_accessor(std::shared_ptr backend, epee::shared_recursive_mutex& rwlock) :m_backend(backend), m_rwlock(rwlock), m_is_open(false) @@ -93,7 +96,8 @@ namespace tools close(); } - const performance_data& get_performance_data_for_handle(container_handle h) const { return m_performance_data_map[h]; } + performance_data& get_performance_data_for_handle(container_handle h) const { return m_performance_data_map[h]; } + performance_data& get_performance_data_global() const { return m_gperformance_data; } bool bind_parent_container(i_db_parent_to_container_callabck* pcontainer) @@ -270,15 +274,23 @@ namespace tools template bool get_t_object(container_handle h, const t_pod_key& k, t_object& obj) const { + performance_data& m_performance_data = m_gperformance_data; //TRY_ENTRY(); std::string res_buff; size_t sk = 0; const char* pk = key_to_ptr(k, sk); + TIME_MEASURE_START_PD(backend_get_t_time); if (!m_backend->get(h, pk, sk, res_buff)) return false; + TIME_MEASURE_FINISH_PD(backend_get_t_time); - return t_unserializable_object_from_blob(obj, res_buff); + + TIME_MEASURE_START_PD(get_serialize_t_time); + bool res = t_unserializable_object_from_blob(obj, res_buff); + TIME_MEASURE_FINISH_PD(get_serialize_t_time); + + return res; //CATCH_ENTRY_L0("get_t_object_from_db", false); } @@ -310,15 +322,18 @@ namespace tools bool get_pod_object(container_handle h, const t_pod_key& k, t_pod_object& obj) const { static_assert(std::is_pod::value, "t_pod_object must be a POD type."); - + performance_data& m_performance_data = m_gperformance_data; //TRY_ENTRY(); std::string res_buff; size_t sk = 0; const char* pk = key_to_ptr(k, sk); + TIME_MEASURE_START_PD(backend_get_pod_time); if (!m_backend->get(h, pk, sk, res_buff)) return false; + TIME_MEASURE_FINISH_PD(backend_get_pod_time); + CHECK_AND_ASSERT_MES(sizeof(t_pod_object) == res_buff.size(), false, "sizes missmath at get_pod_object_from_db(). returned size = " << res_buff.size() << "expected: " << sizeof(t_pod_object)); @@ -784,14 +799,19 @@ namespace tools m_cache.erase(k); } - const performance_data& get_performance_data() const + performance_data& get_performance_data() const { return m_performance_data; } - const typename basic_db_accessor::performance_data& get_performance_data_native() const + typename basic_db_accessor::performance_data& get_performance_data_native() const { return base_class::bdb.get_performance_data_for_handle(base_class::m_h); } + typename basic_db_accessor::performance_data& get_performance_data_global() const + { + return base_class::bdb.get_performance_data_global(); + } + private: mutable performance_data m_performance_data; }; diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index ad5ee65b..32bad122 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -895,6 +895,26 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con //skip genesis timestamp uint64_t stop_ind = 0; uint64_t blocks_size = m_db_blocks.size(); + TIME_MEASURE_START_PD(target_calculating_enum_blocks); + + //@#@ +// #define PRINT_PERFORMANCE_DATA_NATIVE(var_name) << #var_name": " << m_db_blocks.get_performance_data_native().var_name.get_avg() << "(" << m_db_blocks.get_performance_data_native().var_name.get_count()<< ")" << ENDL +// #define PRINT_PERFORMANCE_DATA_GLOBAL(var_name) << #var_name": " << m_db_blocks.get_performance_data_global().var_name.get_avg() << "(" << m_db_blocks.get_performance_data_global().var_name.get_count()<< ")" << ENDL +// #define PRINT_PERFORMANCE_DATA(var_name) << #var_name": " << m_db_blocks.get_performance_data().var_name.get_avg() << "(" << m_db_blocks.get_performance_data().var_name.get_count()<< ")" << ENDL +// +// #define RESET_PERFORMANCE_DATA_NATIVE(var_name) m_db_blocks.get_performance_data_native().var_name.reset(); +// #define RESET_PERFORMANCE_DATA_GLOBAL(var_name) m_db_blocks.get_performance_data_global().var_name.reset(); +// #define RESET_PERFORMANCE_DATA(var_name) m_db_blocks.get_performance_data().var_name.reset(); +// +// +// RESET_PERFORMANCE_DATA_GLOBAL(backend_get_pod_time); +// RESET_PERFORMANCE_DATA_GLOBAL(backend_get_t_time); +// RESET_PERFORMANCE_DATA_GLOBAL(get_serialize_t_time); +// RESET_PERFORMANCE_DATA(hit_percent); +// RESET_PERFORMANCE_DATA(read_cache_microsec); +// RESET_PERFORMANCE_DATA(read_db_microsec); +// RESET_PERFORMANCE_DATA(update_cache_microsec); +// RESET_PERFORMANCE_DATA(write_to_cache_microsec); for (uint64_t cur_ind = blocks_size - 1; cur_ind != stop_ind && count < DIFFICULTY_WINDOW; cur_ind--) { auto beiptr = m_db_blocks[cur_ind]; @@ -906,8 +926,32 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con commulative_difficulties.push_back(beiptr->cumulative_diff_precise); ++count; } + //@#@ + + + +// LOG_PRINT_MAGENTA("[GET_NEXT_DIFF_CONDITIONAL][DB STAT]: count: " << count << ENDL +// PRINT_PERFORMANCE_DATA_NATIVE(backend_set_pod_time) +// PRINT_PERFORMANCE_DATA_NATIVE(backend_set_t_time) +// PRINT_PERFORMANCE_DATA_NATIVE(set_serialize_t_time) +// PRINT_PERFORMANCE_DATA_GLOBAL(backend_get_pod_time) +// PRINT_PERFORMANCE_DATA_GLOBAL(backend_get_t_time) +// PRINT_PERFORMANCE_DATA_GLOBAL(get_serialize_t_time) +// PRINT_PERFORMANCE_DATA(hit_percent) +// PRINT_PERFORMANCE_DATA(read_cache_microsec) +// PRINT_PERFORMANCE_DATA(read_db_microsec) +// PRINT_PERFORMANCE_DATA(update_cache_microsec) +// PRINT_PERFORMANCE_DATA(write_to_cache_microsec) +// //PRINT_PERFORMANCE_DATA(write_to_db_microsec) +// , LOG_LEVEL_0); + //!@#@ + wide_difficulty_type& dif = pos ? m_cached_next_pos_difficulty : m_cached_next_pow_difficulty; - return dif = next_difficulty(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); + TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks); + TIME_MEASURE_START_PD(target_calculating_calc); + dif = next_difficulty(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); + TIME_MEASURE_FINISH_PD(target_calculating_calc); + return dif; } //------------------------------------------------------------------ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, const alt_chain_type& alt_chain, uint64_t split_height) const @@ -932,13 +976,8 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co return false; return true; }; - TIME_MEASURE_START_PD(target_calculating_enum_blocks); enum_blockchain(cb, alt_chain, split_height); - TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks); - TIME_MEASURE_START_PD(target_calculating_calc); - wide_difficulty_type res = next_difficulty(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); - TIME_MEASURE_FINISH_PD(target_calculating_calc); - return res; + return next_difficulty(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); } //------------------------------------------------------------------ wide_difficulty_type blockchain_storage::get_cached_next_difficulty(bool pos) const @@ -4547,14 +4586,14 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt << ENDL << "HEIGHT " << bei.height << ", difficulty: " << current_diffic << ", cumul_diff_precise: " << bei.cumulative_diff_precise << ", cumul_diff_adj: " << bei.cumulative_diff_adjusted << " (+" << cumulative_diff_delta << ")" << ENDL << "block reward: " << print_money_brief(base_reward + fee_summary) << " (" << print_money_brief(base_reward) << " + " << print_money_brief(fee_summary) << ")" << ", coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", tx_count: " << bei.bl.tx_hashes.size() - << ", " << block_processing_time_0_ms - << "(" << block_processing_time_1 - << "/" << target_calculating_time_2 + << ", timing: " << block_processing_time_0_ms << "ms" + << "(micrsec:" << block_processing_time_1 + << "(" << target_calculating_time_2 << "(" << m_performance_data.target_calculating_enum_blocks.get_last_val() << "/" << m_performance_data.target_calculating_calc.get_last_val() << ")" << "/" << longhash_calculating_time_3 << "/" << insert_time_4 << "/" << all_txs_insert_time_5 << "/" << etc_stuff_6 - << ")micrs"); + << "))"); on_block_added(bei, id);