diff options
author | Gabda <gabda87@gmail.com> | 2019-02-28 12:18:06 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-03-09 01:05:47 +0100 |
commit | 7e7563f15f999cac5c140cb93e917905a9450df4 (patch) | |
tree | 358177588b7e5865a4d24bd5723ac9835b4a9a49 /src | |
parent | 4be2c1022e8576f139035ba41cdae97cf3799f5c (diff) | |
download | openttd-7e7563f15f999cac5c140cb93e917905a9450df4.tar.xz |
Add: Chrono based TIC() and TOC() in debug
Diffstat (limited to 'src')
-rw-r--r-- | src/debug.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/debug.h b/src/debug.h index 1eaa20868..3faefffaf 100644 --- a/src/debug.h +++ b/src/debug.h @@ -13,6 +13,7 @@ #define DEBUG_H #include "cpu.h" +#include <chrono> /* Debugging messages policy: * These should be the severities used for direct DEBUG() calls @@ -83,6 +84,9 @@ const char *GetDebugString(); * * TIC() / TOC() creates its own block, so make sure not the mangle * it with another block. + * + * The output is counted in CPU cycles, and not comparable accross + * machines. Mainly useful for local optimisations. **/ #define TIC() {\ uint64 _xxx_ = ottd_rdtsc();\ @@ -98,6 +102,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::microseconds>(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); |