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/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index 660de59a..1fb48d26 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -567,6 +567,8 @@ bool handle_get_daemon_info(po::variables_map& vm) << "longhash_calculating_time_3: " << res.performance_data.longhash_calculating_time_3 << ENDL << "raise_block_core_event: " << res.performance_data.raise_block_core_event << ENDL << "target_calculating_time_2: " << res.performance_data.target_calculating_time_2 << ENDL + << "target_calculating_enum_blocks: " << res.performance_data.target_calculating_enum_blocks << ENDL + << "target_calculating_calc: " << res.performance_data.target_calculating_calc << ENDL << "all_txs_insert_time_5: " << res.performance_data.all_txs_insert_time_5 << ENDL << "tx_add_one_tx_time: " << res.performance_data.tx_add_one_tx_time << ENDL << "tx_check_inputs_time: " << res.performance_data.tx_check_inputs_time << ENDL diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 51c082bd..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 @@ -4542,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); diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 960b288b..463a754c 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -68,6 +68,9 @@ namespace currency epee::math_helper::average etc_stuff_6; epee::math_helper::average insert_time_4; epee::math_helper::average raise_block_core_event; + //target_calculating_time_2 + epee::math_helper::average target_calculating_enum_blocks; + epee::math_helper::average target_calculating_calc; //tx processing zone epee::math_helper::average tx_check_inputs_time; diff --git a/src/currency_core/difficulty.cpp b/src/currency_core/difficulty.cpp index 21d7d339..b5d90356 100644 --- a/src/currency_core/difficulty.cpp +++ b/src/currency_core/difficulty.cpp @@ -239,6 +239,7 @@ namespace currency { wide_difficulty_type next_difficulty(vector& timestamps, vector& cumulative_difficulties, size_t target_seconds) { + TIME_MEASURE_START_PD(target_calculating_enum_blocks); // timestamps - first is latest, back - is oldest timestamps if (timestamps.size() > DIFFICULTY_WINDOW) { diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 64a38cc2..9a2ab644 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -193,6 +193,8 @@ namespace currency res.performance_data.etc_stuff_6 = pd.etc_stuff_6.get_avg(); res.performance_data.insert_time_4 = pd.insert_time_4.get_avg(); res.performance_data.raise_block_core_event = pd.raise_block_core_event.get_avg(); + res.performance_data.target_calculating_enum_blocks = pd.target_calculating_enum_blocks.get_avg(); + res.performance_data.target_calculating_calc = pd.target_calculating_calc.get_avg(); //tx processing zone res.performance_data.tx_check_inputs_time = pd.tx_check_inputs_time.get_avg(); res.performance_data.tx_add_one_tx_time = pd.tx_add_one_tx_time.get_avg(); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index b27d7ddb..10fec97a 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -459,6 +459,8 @@ namespace currency uint64_t etc_stuff_6; uint64_t insert_time_4; uint64_t raise_block_core_event; + uint64_t target_calculating_enum_blocks; + uint64_t target_calculating_calc; //tx processing zone uint64_t tx_check_inputs_time; @@ -505,7 +507,8 @@ namespace currency KV_SERIALIZE(etc_stuff_6) KV_SERIALIZE(insert_time_4) KV_SERIALIZE(raise_block_core_event) - + KV_SERIALIZE(target_calculating_enum_blocks) + KV_SERIALIZE(target_calculating_calc) //tx processing zone KV_SERIALIZE(tx_check_inputs_time) KV_SERIALIZE(tx_add_one_tx_time) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 99d17fd8..0c37b14d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,8 +34,8 @@ target_link_libraries(difficulty-tests currency_core ${CMAKE_THREAD_LIBS_INIT} e target_link_libraries(functional_tests wallet currency_core crypto common rpc zlibstatic ethash upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(hash-tests crypto ethash) target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(performance_tests currency_core common crypto zlibstatic ethash${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(unit_tests wallet currency_core crypto common gtest_main zlibstatic ethash${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(performance_tests currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(unit_tests wallet currency_core crypto common gtest_main zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_clt currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_srv currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 23bb8885..810c135e 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -28,7 +28,7 @@ std::atomic test_core_time::m_time_shift; #define TESTS_DEFAULT_FEE TX_DEFAULT_FEE -static std::atomic s_generated_money_total(0); +static std::atomic s_generated_money_total(0); // TODO: consiger changing to boost::multiprecision::uint128_t static size_t s_wallets_total_count = 10; // total number of wallet that will be randomly used to generate transactions //static size_t s_althchains_minimum_height = 150; // height at which althchaining is started static size_t s_tx_generation_minimum_height = 100; // height at which tx generation is started @@ -43,7 +43,7 @@ typedef std::vector> cct_wallets_t; static const std::vector empty_extra; static const std::vector empty_attachment; -bool create_block_template_manually(const currency::block& prev_block, uint64_t already_generated_coins, const std::vector& txs, const currency::account_public_address& miner_addr, currency::block& result) +bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector& txs, const currency::account_public_address& miner_addr, currency::block& result) { result.flags = 0; result.major_version = CURRENT_BLOCK_MAJOR_VERSION; @@ -572,7 +572,7 @@ bool core_concurrency_test(boost::program_options::variables_map& vm, size_t wth << replay_time_ms / (events.empty() ? 1 : events.size()) << " ms per event, " << events.size() << " events total", LOG_LEVEL_0); core_state_after_playback.fill(c); - uint64_t already_generated_coins = 0; + boost::multiprecision::uint128_t already_generated_coins = 0; { block_extended_info bei = AUTO_VAL_INIT(bei); c.get_blockchain_storage().get_block_extended_info_by_hash(c.get_blockchain_storage().get_top_block_id(), bei); @@ -583,7 +583,7 @@ bool core_concurrency_test(boost::program_options::variables_map& vm, size_t wth if (rthreads > 0) { s_generated_money_total = s_generated_money_total / rthreads; - LOG_PRINT("Generated coins: " << print_money(already_generated_coins) << ", counted by readers (with fee): " << print_money(s_generated_money_total), LOG_LEVEL_0); + LOG_PRINT("Generated coins: " << print_money(already_generated_coins) << ", counted by readers (with fee): " << print_money(s_generated_money_total.load()), LOG_LEVEL_0); } LOG_PRINT("Writers' stats:", LOG_LEVEL_0); diff --git a/tests/functional_tests/difficulty_analysis.cpp b/tests/functional_tests/difficulty_analysis.cpp index b784a88b..be994253 100644 --- a/tests/functional_tests/difficulty_analysis.cpp +++ b/tests/functional_tests/difficulty_analysis.cpp @@ -12,6 +12,7 @@ using namespace epee; #include "wallet/wallet2.h" #include "currency_core/blockchain_storage.h" +#include "currency_core/basic_pow_helpers.h" using std::size_t; @@ -318,11 +319,29 @@ void run_emulation(const std::string& path) LOG_PRINT_L0("Done"); } +void hash_rate_analysis(const std::string& path); void run_difficulty_analysis(const std::string& path) { - //hash_rate_analysis(path); - run_emulation(path); +// currency::block b = AUTO_VAL_INIT(b); +// std::string s("sdsccasc"); +// b.miner_tx.extra.push_back(s); +// +// crypto::hash mining_hash = currency::null_hash; +// bool r = string_tools::parse_tpod_from_hex_string("7759031ee0f014fe45476724df268f61c890b4a4637df1489a6c94c0135efbd8", mining_hash); +// uint64_t nonce = 13704307308123612296; +// crypto::hash pow_hash = currency::get_block_longhash(6, mining_hash, nonce); +// +// std::cout << mining_hash << ENDL; +// std::cout << pow_hash << ENDL; + + //crypto::hash mining_hash = currency::get_block_header_mining_hash(b); + //crypto::hash id_hash = currency::get_block_hash(b); + + + + hash_rate_analysis(path); + //run_emulation(path); } diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index b256b12c..fe8260a1 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -264,7 +264,7 @@ TEST_F(positive_test_connection_to_levin_protocol_handler_calls, handler_initial TEST_F(positive_test_connection_to_levin_protocol_handler_calls, concurent_handler_initialization_and_destruction_is_correct) { const size_t connection_count = 10000; - auto create_and_destroy_connections = [this]() + auto create_and_destroy_connections = [&]() { std::vector connections(connection_count); for (size_t i = 0; i < connection_count; ++i) diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index 112c97f4..39b40816 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -128,11 +128,11 @@ TEST(validate_parse_amount_case, validate_parse_amount) uint64_t res = 0; bool r = currency::parse_amount(res, "0.0001"); ASSERT_TRUE(r); - ASSERT_EQ(res, 10000); + ASSERT_EQ(res, 100000000); r = currency::parse_amount(res, "100.0001"); ASSERT_TRUE(r); - ASSERT_EQ(res, 10000010000); + ASSERT_EQ(res, 100000100000000); r = currency::parse_amount(res, "000.0000"); ASSERT_TRUE(r); @@ -145,11 +145,11 @@ TEST(validate_parse_amount_case, validate_parse_amount) r = currency::parse_amount(res, " 100.0001 "); ASSERT_TRUE(r); - ASSERT_EQ(res, 10000010000); + ASSERT_EQ(res, 100000100000000); r = currency::parse_amount(res, " 100.0000 "); ASSERT_TRUE(r); - ASSERT_EQ(res, 10000000000); + ASSERT_EQ(res, 100000000000000); r = currency::parse_amount(res, " 100. 0000 "); ASSERT_FALSE(r); diff --git a/utils/increment_build_number.sh b/utils/increment_build_number.sh index 95d0a152..e9f78c08 100644 --- a/utils/increment_build_number.sh +++ b/utils/increment_build_number.sh @@ -3,7 +3,7 @@ curr_path=${BASH_SOURCE%/*} version_file_path=../src/version.h.in pushd $curr_path -git pull +git pull --ff-only if [ $? -ne 0 ]; then echo "Failed to pull" popd