-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlog.h
More file actions
140 lines (115 loc) · 3.56 KB
/
log.h
File metadata and controls
140 lines (115 loc) · 3.56 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// Created by mac on 16/10/13.
//
#ifndef HELLO_JNI_MY_LOG_H
#define HELLO_JNI_MY_LOG_H
#include <unistd.h>
#include <android/log.h>
#include <time.h>
#define MY_LOG_LEVEL_VERBOSE 1
#define MY_LOG_LEVEL_DEBUG 2
#define MY_LOG_LEVEL_INFO 3
#define MY_LOG_LEVEL_WARNING 4
#define MY_LOG_LEVEL_ERROR 5
#define MY_LOG_LEVEL_FATAL 6
#define MY_LOG_LEVEL_SILENT 7
#ifndef MY_LOG_TAG
#define MY_LOG_TAG "test"
#endif
#ifndef MY_LOG_LEVEL
#define MY_LOG_LEVEL MY_LOG_LEVEL_VERBOSE
#endif
#define MY_LOG_NOOP (void)0
#define LOG_TAG (strrchr(__FILE__, '/') + 1)
//#define LOG_TAG "mbgl_android"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGETAG(TAG, ...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
#define MY_LOG_PRINT(level, fmt, ...) \
__android_log_print(level, MY_LOG_TAG, fmt, __VA_ARGS__ )
#if MY_LOG_LEVEL_VERBOSE >= MY_LOG_LEVEL
#define MY_LOG_VERBOSE(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_VERBOSE(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_DEBUG >= MY_LOG_LEVEL
#define MY_LOG_DEBUG(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_DEBUG, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_DEBUG(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_INFO >= MY_LOG_LEVEL
#define MY_LOG_INFO(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_INFO, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_INFO(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_WARNING >= MY_LOG_LEVEL
#define MY_LOG_WARNING(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_WARNING, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_WARNING(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_ERROR >= MY_LOG_LEVEL
#define MY_LOG_ERROR(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_ERROR(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_FATAL >= MY_LOG_LEVEL
#define MY_LOG_FATAL(fmt, ...)\
MY_LOG_PRINT(ANDROID_LOG_FATAL, fmt, ##__VA_ARGS__)
#else
#define MY_LOG_FATAL(...) MY_LOG_NOOP
#endif
#if MY_LOG_LEVEL_SILENT >= MY_LOG_LEVEL
#define MY_LOG_ASSERT(expression, fmt, ...)\
if(!expression)\
{\
__android_log_assert(#expression, MY_LOG_TAG, \
fmt, ##__VA_ARGS__);\
}
#else
#define MY_LOG_ASSERT(...) MY_LOG_NOOP
#endif
inline uint64_t GetTimeNano()
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
uint64_t result = t.tv_sec * 1000000000LL + t.tv_nsec;
return result;
}
inline void ShowFPS()
{
#define INTERVALTIME 1000
static unsigned int frameCounter = 0;
static unsigned int prevTimeMs = 0;
static unsigned int lastTimeMS = 0;
static float maxFPS = 0;
static float minFPS = 0;
unsigned int currentTimeMs = GetTimeNano() * 1e-6;
float everyFPS = 1000.0f / (float)(currentTimeMs - lastTimeMS);
if( everyFPS > maxFPS ){
maxFPS = everyFPS;
}
if( everyFPS < minFPS )
{
minFPS = everyFPS;
}
lastTimeMS = currentTimeMs;
frameCounter++;
if (currentTimeMs - prevTimeMs > INTERVALTIME)
{
float elapsedSec = (float)(currentTimeMs - prevTimeMs) / 1000.0f;
float currentFPS = (float)frameCounter / elapsedSec;
LOGI("submit, FPS: %0.2f, maxFPS: %0.2f, minFPS: %0.2f", currentFPS, maxFPS, minFPS);
minFPS = currentFPS;
maxFPS = currentFPS;
frameCounter = 0;
prevTimeMs = currentTimeMs;
}
}
#endif //HELLO_JNI_MY_LOG_H