diff options
Diffstat (limited to 'src/common')
35 files changed, 115 insertions, 44 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 7ce0229da..66fd8d7ad 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014-2017, The Monero Project +# Copyright (c) 2014-2018, The Monero Project # # All rights reserved. # diff --git a/src/common/apply_permutation.h b/src/common/apply_permutation.h index 8684f14ce..ff346bab1 100644 --- a/src/common/apply_permutation.h +++ b/src/common/apply_permutation.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/base58.cpp b/src/common/base58.cpp index 941373443..75556cad9 100644 --- a/src/common/base58.cpp +++ b/src/common/base58.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/base58.h b/src/common/base58.h index 6dd850c03..02ca96956 100644 --- a/src/common/base58.h +++ b/src/common/base58.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index f8b21c52e..3f5c623f8 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 4b9ca9559..7980b381f 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/command_line.h b/src/common/command_line.h index c2bac9cc8..7b183d86b 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/common_fwd.h b/src/common/common_fwd.h index f33e185b5..2924d9cbe 100644 --- a/src/common/common_fwd.h +++ b/src/common/common_fwd.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index d942ae9d0..06f127c25 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index c0a2dbf2b..d5dc03283 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/download.cpp b/src/common/download.cpp index 87814fa5e..6698a5abf 100644 --- a/src/common/download.cpp +++ b/src/common/download.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/download.h b/src/common/download.h index 917cb2278..3097394bc 100644 --- a/src/common/download.h +++ b/src/common/download.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/http_connection.h b/src/common/http_connection.h index 0357a90a0..9fc6be261 100644 --- a/src/common/http_connection.h +++ b/src/common/http_connection.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp index 28a186bf0..4a89876fb 100644 --- a/src/common/i18n.cpp +++ b/src/common/i18n.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/i18n.h b/src/common/i18n.h index 5169cf9f7..d21d00275 100644 --- a/src/common/i18n.h +++ b/src/common/i18n.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/int-util.h b/src/common/int-util.h index 7cec571ad..11e39895e 100644 --- a/src/common/int-util.h +++ b/src/common/int-util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/json_util.h b/src/common/json_util.h index 45046a4fb..661022a6f 100644 --- a/src/common/json_util.h +++ b/src/common/json_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/password.cpp b/src/common/password.cpp index 011123300..ef026c979 100644 --- a/src/common/password.cpp +++ b/src/common/password.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/password.h b/src/common/password.h index 01c6bf05a..7c29effe4 100644 --- a/src/common/password.h +++ b/src/common/password.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp index 4947058d3..41e23130d 100644 --- a/src/common/perf_timer.cpp +++ b/src/common/perf_timer.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // @@ -33,6 +33,52 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "perf" +namespace +{ + uint64_t get_tick_count() + { +#if defined(__x86_64__) + uint32_t hi, lo; + __asm__ volatile("rdtsc" : "=a"(lo), "=d"(hi)); + return (((uint64_t)hi) << 32) | (uint64_t)lo; +#else + return epee::misc_utils::get_ns_count(); +#endif + } + +#ifdef __x86_64__ + uint64_t get_ticks_per_ns() + { + uint64_t t0 = epee::misc_utils::get_ns_count(); + uint64_t r0 = get_tick_count(); + + while (1) + { + uint64_t t = epee::misc_utils::get_ns_count(); + if (t - t0 > 1*1000000000) break; // work one second + } + + uint64_t t1 = epee::misc_utils::get_ns_count(); + uint64_t r1 = get_tick_count(); + uint64_t tpns256 = 256 * (r1 - r0) / (t1 - t0); + return tpns256 ? tpns256 : 1; + } +#endif + +#ifdef __x86_64__ + uint64_t ticks_per_ns = get_ticks_per_ns(); +#endif + + uint64_t ticks_to_ns(uint64_t ticks) + { +#if defined(__x86_64__) + return 256 * ticks / ticks_per_ns; +#else + return ticks; +#endif + } +} + namespace tools { @@ -51,9 +97,9 @@ void set_performance_timer_log_level(el::Level level) performance_timer_log_level = level; } -PerformanceTimer::PerformanceTimer(const std::string &s, uint64_t unit, el::Level l): name(s), unit(unit), level(l), started(false) +PerformanceTimer::PerformanceTimer(const std::string &s, uint64_t unit, el::Level l): name(s), unit(unit), level(l), started(false), paused(false) { - ticks = epee::misc_utils::get_ns_count(); + ticks = get_tick_count(); if (!performance_timers) { MLOG(level, "PERF ----------"); @@ -62,9 +108,10 @@ PerformanceTimer::PerformanceTimer(const std::string &s, uint64_t unit, el::Leve else { PerformanceTimer *pt = performance_timers->back(); - if (!pt->started) + if (!pt->started && !pt->paused) { - MLOG(pt->level, "PERF " << std::string((performance_timers->size()-1) * 2, ' ') << " " << pt->name); + size_t size = 0; for (const auto *tmp: *performance_timers) if (!tmp->paused) ++size; + MLOG(pt->level, "PERF " << std::string((size-1) * 2, ' ') << " " << pt->name); pt->started = true; } } @@ -74,10 +121,12 @@ PerformanceTimer::PerformanceTimer(const std::string &s, uint64_t unit, el::Leve PerformanceTimer::~PerformanceTimer() { performance_timers->pop_back(); - ticks = epee::misc_utils::get_ns_count() - ticks; + if (!paused) + ticks = get_tick_count() - ticks; char s[12]; - snprintf(s, sizeof(s), "%8llu ", (unsigned long long)ticks / (1000000000 / unit)); - MLOG(level, "PERF " << s << std::string(performance_timers->size() * 2, ' ') << " " << name); + snprintf(s, sizeof(s), "%8llu ", (unsigned long long)(ticks_to_ns(ticks) / (1000000000 / unit))); + size_t size = 0; for (const auto *tmp: *performance_timers) if (!tmp->paused || tmp==this) ++size; + MLOG(level, "PERF " << s << std::string(size * 2, ' ') << " " << name); if (performance_timers->empty()) { delete performance_timers; @@ -85,4 +134,20 @@ PerformanceTimer::~PerformanceTimer() } } +void PerformanceTimer::pause() +{ + if (paused) + return; + ticks = get_tick_count() - ticks; + paused = true; +} + +void PerformanceTimer::resume() +{ + if (!paused) + return; + ticks = get_tick_count() - ticks; + paused = false; +} + } diff --git a/src/common/perf_timer.h b/src/common/perf_timer.h index a1d71609c..0e910caf9 100644 --- a/src/common/perf_timer.h +++ b/src/common/perf_timer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // @@ -30,6 +30,7 @@ #include <string> #include <stdio.h> +#include <memory> #include "misc_log_ex.h" #undef MONERO_DEFAULT_LOG_CATEGORY @@ -47,6 +48,8 @@ class PerformanceTimer public: PerformanceTimer(const std::string &s, uint64_t unit, el::Level l = el::Level::Debug); ~PerformanceTimer(); + void pause(); + void resume(); private: std::string name; @@ -54,6 +57,7 @@ private: el::Level level; uint64_t ticks; bool started; + bool paused; }; void set_performance_timer_log_level(el::Level level); @@ -62,8 +66,10 @@ void set_performance_timer_log_level(el::Level level); #define PERF_TIMER_UNIT_L(name, unit, l) tools::PerformanceTimer pt_##name(#name, unit, l) #define PERF_TIMER(name) PERF_TIMER_UNIT(name, 1000) #define PERF_TIMER_L(name, l) PERF_TIMER_UNIT_L(name, 1000, l) -#define PERF_TIMER_START_UNIT(name, unit) tools::PerformanceTimer *pt_##name = new tools::PerformanceTimer(#name, unit, el::Level::Info) +#define PERF_TIMER_START_UNIT(name, unit) std::unique_ptr<tools::PerformanceTimer> pt_##name(new tools::PerformanceTimer(#name, unit, el::Level::Info)) #define PERF_TIMER_START(name) PERF_TIMER_START_UNIT(name, 1000) -#define PERF_TIMER_STOP(name) do { delete pt_##name; pt_##name = NULL; } while(0) +#define PERF_TIMER_STOP(name) do { pt_##name.reset(NULL); } while(0) +#define PERF_TIMER_PAUSE(name) pt_##name->pause() +#define PERF_TIMER_RESUME(name) pt_##name->resume() } diff --git a/src/common/pod-class.h b/src/common/pod-class.h index 3896d5c29..5f6709eef 100644 --- a/src/common/pod-class.h +++ b/src/common/pod-class.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/rpc_client.h b/src/common/rpc_client.h index 297020ef2..64c84ed19 100644 --- a/src/common/rpc_client.h +++ b/src/common/rpc_client.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h index 8fc98d2b0..d7517babb 100644 --- a/src/common/scoped_message_writer.h +++ b/src/common/scoped_message_writer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/sfinae_helpers.h b/src/common/sfinae_helpers.h index ddd456dd2..fa5052a2e 100644 --- a/src/common/sfinae_helpers.h +++ b/src/common/sfinae_helpers.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp index ed1093309..9c2bf4b53 100644 --- a/src/common/stack_trace.cpp +++ b/src/common/stack_trace.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/stack_trace.h b/src/common/stack_trace.h index 0f6bdc08b..272fb89ae 100644 --- a/src/common/stack_trace.h +++ b/src/common/stack_trace.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016, The Monero Project +// Copyright (c) 2016-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp index 5d749e08e..7fd16ceaf 100644 --- a/src/common/threadpool.cpp +++ b/src/common/threadpool.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/threadpool.h b/src/common/threadpool.h index 1d56d7605..a0e53b011 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/unordered_containers_boost_serialization.h b/src/common/unordered_containers_boost_serialization.h index 4d82a1364..d78dc6a30 100644 --- a/src/common/unordered_containers_boost_serialization.h +++ b/src/common/unordered_containers_boost_serialization.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/updates.cpp b/src/common/updates.cpp index 2d9c2d89c..9eb402e0b 100644 --- a/src/common/updates.cpp +++ b/src/common/updates.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/updates.h b/src/common/updates.h index e494ed7ac..6ec22f183 100644 --- a/src/common/updates.h +++ b/src/common/updates.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017, The Monero Project +// Copyright (c) 2017-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/util.cpp b/src/common/util.cpp index bcea70558..659ea31b8 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/util.h b/src/common/util.h index 53ff78af8..5afb42c97 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // diff --git a/src/common/varint.h b/src/common/varint.h index cb785e61a..262bd1360 100644 --- a/src/common/varint.h +++ b/src/common/varint.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2017, The Monero Project +// Copyright (c) 2014-2018, The Monero Project // // All rights reserved. // |