Util: adder PerfTimer

This commit is contained in:
SChernykh 2023-03-30 19:09:15 +02:00
parent f6a285de87
commit 080fbaa26c
2 changed files with 23 additions and 0 deletions

View file

@ -707,4 +707,11 @@ void remove_portmapping(int external_port)
}
#endif
NOINLINE PerfTimer::~PerfTimer()
{
using namespace std::chrono;
const duration<double, std::milli> dt = high_resolution_clock::now() - m_start;
LOGINFO(m_level, m_name << " took " << dt.count() << " ms");
}
} // namespace p2pool

View file

@ -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<std::chrono::high_resolution_clock> 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();