| 27 | |
| 28 | #ifdef USE_TIMER |
| 29 | class Timer { |
| 30 | public: |
| 31 | typedef std::chrono::system_clock::time_point time_point; |
| 32 | typedef std::chrono::high_resolution_clock clock; |
| 33 | |
| 34 | static std::unordered_map<std::string, int> occurrence; |
| 35 | |
| 36 | const char *prompt; |
| 37 | int log_frequency; |
| 38 | time_point start; |
| 39 | |
| 40 | Timer(const char *_prompt, int _log_frequency = 1) |
| 41 | : prompt(_prompt), log_frequency(_log_frequency), start(clock::now()) { |
| 42 | if (occurrence.find(prompt) == occurrence.end()) |
| 43 | occurrence[prompt] = 0; |
| 44 | } |
| 45 | |
| 46 | ~Timer() { |
| 47 | time_point end = clock::now(); |
| 48 | LOG_IF(INFO, ++occurrence[prompt] == 1) << prompt << ": " << (end - start).count() / 1.0e6 << " ms"; |
| 49 | occurrence[prompt] %= log_frequency; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | std::unordered_map<std::string, int> Timer::occurrence; |
| 54 | #else |
nothing calls this directly
no outgoing calls
no test coverage detected