From ebd6b75cc8bbfa8979fc0f1d5c805298d8472124 Mon Sep 17 00:00:00 2001 From: Gabda Date: Thu, 28 Feb 2019 12:18:06 +0100 Subject: [PATCH] Add: Chrono based TIC() and TOC() in debug --- src/debug.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/debug.h b/src/debug.h index 1eaa208680be8..3f0f691e42874 100644 --- a/src/debug.h +++ b/src/debug.h @@ -13,6 +13,7 @@ #define DEBUG_H #include "cpu.h" +#include /* Debugging messages policy: * These should be the severities used for direct DEBUG() calls @@ -98,6 +99,22 @@ const char *GetDebugString(); }\ } +/* Chrono based version. The output is in microseconds. */ +#define TICC() {\ + auto _start_ = std::chrono::high_resolution_clock::now();\ + static uint64 _sum_ = 0;\ + static uint32 _i_ = 0; + +#define TOCC(str, _count_)\ + _sum_ += (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - _start_)).count();\ + if (++_i_ == _count_) {\ + DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " us [avg: %.1f us]", str, _sum_, _sum_/(double)_i_);\ + _i_ = 0;\ + _sum_ = 0;\ + }\ +} + + void ShowInfo(const char *str); void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);