From 29a6d0bce47fc4f1f604da4671355d1eb462d4c9 Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Wed, 23 Jan 2019 21:13:26 +0300 Subject: [PATCH] fixed bug in miner, added demangling for callstacks --- contrib/epee/include/misc_os_dependent.h | 7 ++++--- src/currency_core/scratchpad_helper.cpp | 2 +- .../functional_tests/difficulty_analysis.cpp | 20 ++++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h index 4fe89b9f..116826ce 100644 --- a/contrib/epee/include/misc_os_dependent.h +++ b/contrib/epee/include/misc_os_dependent.h @@ -111,6 +111,7 @@ namespace misc_utils #if defined(__GNUC__) #include +#include #endif inline std::string print_trace() { @@ -125,9 +126,9 @@ namespace misc_utils stack_depth = backtrace(stack_addrs, max_depth); stack_strings = backtrace_symbols(stack_addrs, stack_depth); - - for (size_t i = 1; i < stack_depth; i++) { - ss << stack_strings[i] << std::endl; + for (size_t i = 1; i < stack_depth; i++) + { + ss << boost::core::demangle(stack_strings[i]) << std::endl; } free(stack_strings); // malloc()ed by backtrace_symbols #endif diff --git a/src/currency_core/scratchpad_helper.cpp b/src/currency_core/scratchpad_helper.cpp index dd864659..343e5c99 100644 --- a/src/currency_core/scratchpad_helper.cpp +++ b/src/currency_core/scratchpad_helper.cpp @@ -27,13 +27,13 @@ namespace currency } crypto::hash scratchpad_keeper::get_pow_hash(const blobdata& bd, uint64_t height, const crypto::hash& scr_seed) { + CRITICAL_REGION_BEGIN(m_lock); crypto::hash res_hash = null_hash; if (scr_seed != m_seed || get_scratchpad_size_for_height(height) != this->size()) { bool r = generate(scr_seed, height); CHECK_AND_ASSERT_THROW_MES(r, "Unable to generate scratchpad"); } - CRITICAL_REGION_BEGIN(m_lock); CHECK_AND_ASSERT_THROW_MES(get_scratchpad_size_for_height(height) == this->size(), "Fatal error on hash calculation: scratchpad_size=" << m_scratchpad.size() << " at height=" << height << ", scr_seed=" << scr_seed << ", m_seed=" << m_seed); CHECK_AND_ASSERT_THROW_MES(scr_seed == m_seed, "Fatal error on hash calculation: scratchpad_seed missmatch scr_seed=" << scr_seed << ", m_seed=" << m_seed); diff --git a/tests/functional_tests/difficulty_analysis.cpp b/tests/functional_tests/difficulty_analysis.cpp index c089c113..23b09138 100644 --- a/tests/functional_tests/difficulty_analysis.cpp +++ b/tests/functional_tests/difficulty_analysis.cpp @@ -34,10 +34,28 @@ void run_difficulty_analysis(const std::string& path) std::transform(tok.begin(), tok.end(), std::back_inserter(array_num), &boost::lexical_cast); + array_num.push_back(0); //reserve space for hashrate value blocks.push_back(array_num); } LOG_PRINT_L0("Loaded " << blocks.size() << " lines"); - + LOG_PRINT_L0("Calculating hashrate..."); + std::stringstream ss; + uint64_t curren_hashrate = 0; + uint64_t step = 50; + for (size_t i = 1; i != blocks.size(); i++) + { + + if (i % step == 0 ) + { + curren_hashrate = (blocks[i][3] - blocks[i - step][3])/(blocks[i][1] - blocks[i- step][1]); + ss << std::left << std::setw(10) << i << std::left << std::setw(15) << blocks[i][1] << std::left << std::setw(15) << blocks[i][2] << std::left << std::setw(20) << curren_hashrate * 120 << ENDL; + } + //blocks[i][4] = curren_hashrate; + //ss << std::left << std::setw(10) << i << std::left << std::setw(15) << blocks[i][2] << std::left << std::setw(20) << blocks[i][4] << ENDL; + } + std::string res_path = path + "hashrate.txt"; + file_io_utils::save_string_to_file(res_path, ss.str()); + LOG_PRINT_L0("Done, saved to file " << res_path); return; }