diff --git a/src/util.cpp b/src/util.cpp index 4d17c9e..5784078 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -707,4 +707,11 @@ void remove_portmapping(int external_port) } #endif +NOINLINE PerfTimer::~PerfTimer() +{ + using namespace std::chrono; + const duration dt = high_resolution_clock::now() - m_start; + LOGINFO(m_level, m_name << " took " << dt.count() << " ms"); +} + } // namespace p2pool diff --git a/src/util.h b/src/util.h index afac17c..189eb03 100644 --- a/src/util.h +++ b/src/util.h @@ -259,6 +259,22 @@ int add_portmapping(int external_port, int internal_port); void remove_portmapping(int external_port); #endif +struct PerfTimer +{ + FORCEINLINE PerfTimer(int level, const char* name) : m_level(level), m_name(name), m_start(std::chrono::high_resolution_clock::now()) {} + ~PerfTimer(); + + int m_level; + const char* m_name; + std::chrono::time_point m_start; +}; + +#ifdef P2POOL_LOG_DISABLE +#define PERFLOG(level, name) +#else +#define PERFLOG(level, name) PerfTimer CONCAT(perf_timer_, __LINE__)(level, name) +#endif + } // namespace p2pool void memory_tracking_start();