From b5baa850a46c353c6f61a2834729766d4ebeb581 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Wed, 21 Nov 2018 14:14:41 +0100 Subject: [PATCH] Time logger functions --- core/include/tangram/log.h | 42 ++++++++++++++++++++++++++++++++++++++ core/src/platform.cpp | 3 +++ 2 files changed, 45 insertions(+) diff --git a/core/include/tangram/log.h b/core/include/tangram/log.h index be7c148234..8e1f531eed 100644 --- a/core/include/tangram/log.h +++ b/core/include/tangram/log.h @@ -66,3 +66,45 @@ do { Tangram::logMsg("ERROR %s:%d: " fmt "\n", __FILENAME__, __LINE__, ## __VA_A #define LOG(fmt, ...) #define LOGN(fmt, ...) #endif + +#include +#include + +extern std::chrono::time_point tangram_log_time_start, tangram_log_time_last; +extern std::mutex tangram_log_time_mutex; + +#define LOGTIME(fmt, ...) do { \ + int l = strlen( __FILENAME__); \ + Tangram::logMsg("TIME %-18.*s " fmt "\n", \ + l > 4 ? l-4 : l, __FILENAME__, ##__VA_ARGS__); } while (0) + +// Overall timing init/reset +#define LOGTOInit() do { \ + std::lock_guard lock(tangram_log_time_mutex); \ + tangram_log_time_last = tangram_log_time_start = std::chrono::system_clock::now(); } while(0) + +// Overall timing +#define LOGTO(fmt, ...) do { \ + std::lock_guard lock(tangram_log_time_mutex); \ + std::chrono::time_point now = std::chrono::system_clock::now(); \ + std::chrono::duration t1 = now - tangram_log_time_start; \ + std::chrono::duration t2 = now - tangram_log_time_last; \ + tangram_log_time_last = now; \ + LOGTIME("%7.2f %7.2f " fmt, t1.count()*1000.f, t2.count()*1000.f, ## __VA_ARGS__); } while(0) + +// Local timing init +#define LOGTInit(fmt, ...) \ + std::chrono::time_point _time_last, _time_start; \ + std::chrono::time_point now = std::chrono::system_clock::now(); \ + std::chrono::duration t0 = now - tangram_log_time_start; \ + _time_start = _time_last = now; \ + LOGTIME("%7.2f " fmt, t0.count()*1000.f, ## __VA_ARGS__) + +// Local timing +#define LOGT(fmt, ...) do { \ + std::chrono::time_point now = std::chrono::system_clock::now(); \ + std::chrono::duration t0 = now - tangram_log_time_start; \ + std::chrono::duration t1 = now - _time_start; \ + std::chrono::duration t2 = now - _time_last; \ + _time_last = now; \ + LOGTIME("%7.2f %7.2f %7.2f " fmt, t0.count()*1000.f, t1.count()*1000.f, t2.count()*1000.f, ## __VA_ARGS__); } while(0) diff --git a/core/src/platform.cpp b/core/src/platform.cpp index a0b84d3f01..fb9d6cbd78 100644 --- a/core/src/platform.cpp +++ b/core/src/platform.cpp @@ -4,6 +4,9 @@ #include #include +std::chrono::time_point tangram_log_time_start, tangram_log_time_last; +std::mutex tangram_log_time_mutex; + namespace Tangram { Platform::Platform() : m_continuousRendering(false) {}