Skip to content

Commit 82c44db

Browse files
committed
Time logger functions
1 parent 96e9b32 commit 82c44db

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

core/include/tangram/log.h

+42
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,45 @@ do { Tangram::logMsg("ERROR %s:%d: " fmt "\n", __FILENAME__, __LINE__, ## __VA_A
6666
#define LOG(fmt, ...)
6767
#define LOGN(fmt, ...)
6868
#endif
69+
70+
#include <mutex>
71+
#include <chrono>
72+
73+
extern std::chrono::time_point<std::chrono::system_clock> tangram_log_time_start, tangram_log_time_last;
74+
extern std::mutex tangram_log_time_mutex;
75+
76+
#define LOGTIME(fmt, ...) do { \
77+
int l = strlen( __FILENAME__); \
78+
Tangram::logMsg("TIME %-18.*s " fmt "\n", \
79+
l > 4 ? l-4 : l, __FILENAME__, ##__VA_ARGS__); } while (0)
80+
81+
// Overall timing init/reset
82+
#define LOGTOInit() do { \
83+
std::lock_guard<std::mutex> lock(tangram_log_time_mutex); \
84+
tangram_log_time_last = tangram_log_time_start = std::chrono::system_clock::now(); } while(0)
85+
86+
// Overall timing
87+
#define LOGTO(fmt, ...) do { \
88+
std::lock_guard<std::mutex> lock(tangram_log_time_mutex); \
89+
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); \
90+
std::chrono::duration<double> t1 = now - tangram_log_time_start; \
91+
std::chrono::duration<double> t2 = now - tangram_log_time_last; \
92+
tangram_log_time_last = now; \
93+
LOGTIME("%7.2f %7.2f " fmt, t1.count()*1000.f, t2.count()*1000.f, ## __VA_ARGS__); } while(0)
94+
95+
// Local timing init
96+
#define LOGTInit(fmt, ...) \
97+
std::chrono::time_point<std::chrono::system_clock> _time_last, _time_start; \
98+
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); \
99+
std::chrono::duration<double> t0 = now - tangram_log_time_start; \
100+
_time_start = _time_last = now; \
101+
LOGTIME("%7.2f " fmt, t0.count()*1000.f, ## __VA_ARGS__)
102+
103+
// Local timing
104+
#define LOGT(fmt, ...) do { \
105+
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); \
106+
std::chrono::duration<double> t0 = now - tangram_log_time_start; \
107+
std::chrono::duration<double> t1 = now - _time_start; \
108+
std::chrono::duration<double> t2 = now - _time_last; \
109+
_time_last = now; \
110+
LOGTIME("%7.2f %7.2f %7.2f " fmt, t0.count()*1000.f, t1.count()*1000.f, t2.count()*1000.f, ## __VA_ARGS__); } while(0)

core/src/platform.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <fstream>
55
#include <string>
66

7+
std::chrono::time_point<std::chrono::system_clock> tangram_log_time_start, tangram_log_time_last;
8+
std::mutex tangram_log_time_mutex;
9+
710
namespace Tangram {
811

912
Platform::Platform() : m_continuousRendering(false) {}

0 commit comments

Comments
 (0)