-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmrlog.h
executable file
·79 lines (73 loc) · 2.27 KB
/
mrlog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef MR_LOG_H_
#define MR_LOG_H_
#ifdef ANDROID_LOG
#include <android/log.h>
#define LOG_TAG "mrlog"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__))
#elif IOS_LOG
#define LOGI(...) printf(__VA_ARGS__)
#define LOGD(...) printf(__VA_ARGS__)
#define LOGE(...) printf(__VA_ARGS__)
#else
#define LOGI(...)
#define LOGD(...)
#define LOGE(...)
#endif
#if _WIN32
#include <windows.h>
class MRTimerSingleton{
public:
LONGLONG _freq;
static MRTimerSingleton * getInstance(){
static MRTimerSingleton instance;
return &instance;
}
private:
MRTimerSingleton(){
LARGE_INTEGER tmp;
QueryPerformanceFrequency(&tmp);
_freq = tmp.QuadPart;
}
};
inline float mrtimer_elapse(const LARGE_INTEGER &func){
LARGE_INTEGER func_e;
QueryPerformanceCounter(&func_e);
return (LONGLONG)((func_e.QuadPart - func.QuadPart) * 1000.0 / MRTimerSingleton::getInstance()->_freq);
};
#define MRTIMER_START(func) LARGE_INTEGER func; QueryPerformanceCounter(&func);
#define MRTIMER_END(func) mrtimer_elapse(func)
#else
#include <sys/time.h>
#ifdef __cplusplus
inline float mrtimer_elapse(const timeval& func){
timeval func_e;
gettimeofday(&func_e, NULL);
return (func_e.tv_sec - func.tv_sec) * 1000 + (func_e.tv_usec - func.tv_usec) / 1000.0;
}
#define MRTIMER_START(func) timeval func; gettimeofday(&func, NULL);
#define MRTIMER_END(func) mrtimer_elapse(func)
#endif
static long getTime(){
struct timeval tp;
gettimeofday(&tp, NULL);
long ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return ms;
}
static int fps()
{
static int fps = 0;
static long lastTime = 0;
static int frameCount = 0;
long curTime = getTime();
if (curTime - lastTime > 1000){
fps = frameCount;
frameCount = 0;
lastTime = curTime;
}
++frameCount;
return fps;
}
#endif
#endif