| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#pragma once |
| 30 |
|
| 31 |
#include <cstdint> |
| 32 |
#include <string> |
| 33 |
#include <stdio.h> |
| 34 |
#include <memory> |
| 35 |
#include "misc_log_ex.h" |
| 36 |
|
| 37 |
namespace tools |
| 38 |
{ |
| 39 |
|
| 40 |
class PerformanceTimer; |
| 41 |
|
| 42 |
extern el::Level performance_timer_log_level; |
| 43 |
|
| 44 |
uint64_t get_tick_count(); |
| 45 |
uint64_t get_ticks_per_ns(); |
| 46 |
uint64_t ticks_to_ns(uint64_t ticks); |
| 47 |
|
| 48 |
class PerformanceTimer |
| 49 |
{ |
| 50 |
public: |
| 51 |
PerformanceTimer(bool paused = false); |
| 52 |
~PerformanceTimer(); |
| 53 |
void pause(); |
| 54 |
void resume(); |
| 55 |
void reset(); |
| 56 |
uint64_t value() const; |
| 57 |
operator uint64_t() const { return value(); } |
| 58 |
|
| 59 |
protected: |
| 60 |
uint64_t ticks; |
| 61 |
bool started; |
| 62 |
bool paused; |
| 63 |
}; |
| 64 |
|
| 65 |
class LoggingPerformanceTimer: public PerformanceTimer |
| 66 |
{ |
| 67 |
public: |
| 68 |
LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l = el::Level::Info); |
| 69 |
~LoggingPerformanceTimer(); |
| 70 |
|
| 71 |
private: |
| 72 |
std::string name; |
| 73 |
std::string cat; |
| 74 |
uint64_t unit; |
| 75 |
el::Level level; |
| 76 |
}; |
| 77 |
|
| 78 |
void set_performance_timer_log_level(el::Level level); |
| 79 |
|
| 80 |
#define PERF_TIMER_NAME(name) pt_##name |
| 81 |
#define PERF_TIMER_UNIT(name, unit) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, tools::performance_timer_log_level) |
| 82 |
#define PERF_TIMER_UNIT_L(name, unit, l) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)t_##name(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, l) |
| 83 |
#define PERF_TIMER(name) PERF_TIMER_UNIT(name, 1000000) |
| 84 |
#define PERF_TIMER_L(name, l) PERF_TIMER_UNIT_L(name, 1000000, l) |
| 85 |
#define PERF_TIMER_START_UNIT(name, unit) std::unique_ptr<tools::LoggingPerformanceTimer> PERF_TIMER_NAME(name)(new tools::LoggingPerformanceTimer(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, el::Level::Info)) |
| 86 |
#define PERF_TIMER_START(name) PERF_TIMER_START_UNIT(name, 1000000) |
| 87 |
#define PERF_TIMER_STOP(name) do { PERF_TIMER_NAME(name).reset(NULL); } while(0) |
| 88 |
#define PERF_TIMER_PAUSE(name) PERF_TIMER_NAME(name).pause() |
| 89 |
#define PERF_TIMER_RESUME(name) PERF_TIMER_NAME(name).resume() |
| 90 |
|
| 91 |
} |