mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Util: adder PerfTimer
This commit is contained in:
parent
f6a285de87
commit
080fbaa26c
2 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
|
|
16
src/util.h
16
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<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();
|
||||
|
|
Loading…
Reference in a new issue