2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "cam_debug.h"
22 /* #include <debug-message.h> */
24 #define LOG_LEVEL_FLAGS (G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_DEBUG | \
25 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | \
26 G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION)
28 #define LOG_FILTER_CRITICAL G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR
29 #define LOG_FILTER_WARNING LOG_FILTER_CRITICAL | G_LOG_LEVEL_WARNING
30 #define LOG_FILTER_MESSAGE LOG_FILTER_WARNING | G_LOG_LEVEL_MESSAGE
31 #define LOG_FILTER_INFO LOG_FILTER_MESSAGE | G_LOG_LEVEL_INFO
32 #define LOG_FILTER_DEBUG LOG_FILTER_INFO | G_LOG_LEVEL_DEBUG
33 #define LOG_FILTER_ALL LOG_FILTER_DEBUG
43 #define __cam_print_debug(domain, msg) \
45 printf("\x1b[%dm\x1b[%dm[DEBUG.%s] %s", BG_BLACK, FG_GREEN, domain, msg); \
46 printf("\x1b[0m\n"); \
49 #define __cam_print_info(domain, msg) \
51 printf("\x1b[%dm\x1b[%dm[INFO.%s] %s", BG_BLACK, FG_PUPPLE, domain, msg); \
52 printf("\x1b[0m\n"); \
55 #define __cam_print_msg(domain, msg) \
57 printf("\x1b[%dm\x1b[%dm[MESSAGE.%s] %s", BG_BLACK, FG_CYAN, domain, msg); \
58 printf("\x1b[0m\n"); \
61 #define __cam_print_warning(domain, msg) \
63 printf("\x1b[%dm\x1b[%dm[WARNING.%s] %s", BG_BLACK, FG_YELLOW, domain, msg); \
64 printf("\x1b[0m\n"); \
67 #define __cam_print_critical(domain, msg) \
69 printf("\x1b[%dm\x1b[%dm[CRITICAL.%s] %s", BG_BLACK, FG_RED, domain, msg); \
70 printf("\x1b[0m\n"); \
73 #define __cam_print_error(domain, msg) \
75 printf("\x1b[%dm\x1b[%dm**ERROR.%s: %s", BG_BLACK, FG_RED, domain, msg); \
76 printf("\x1b[0m\n"); \
79 #ifdef ENABLE_TIME_MEASURE
81 static GTimer *g_timer = NULL;
82 static gdouble previous_elapsed = 0;
84 static GTimer *g_measure_timer = NULL;
85 static gdouble previous_time[MEASURE_TYPE_MAX] = { 0 };
87 static char debug_type[MEASURE_TYPE_MAX][200] = {
88 "NORMAL_MEASURE_TYPE",
90 "CAPTURE_MEASURE_TIME",
91 "REGISTER_FILE_MEASURE_TIME",
92 "REC_START_MEASURE_TIME",
93 "REC_COMMIT_MEASURE_TIME",
94 "REVIEW_MEASURE_TIME",
100 gboolean memcheck = false;
102 EXPORT_API void debug_start_memcheck()
110 EXPORT_API void debug_stop_memcheck()
119 void debug_measure_init()
121 g_measure_timer = g_timer_new();
125 for (type = 0; type < MEASURE_TYPE_MAX; type++) {
126 previous_time[type] = 0;
132 void debug_measure_close()
134 if (g_measure_timer) {
135 g_timer_destroy(g_measure_timer);
136 g_measure_timer = NULL;
141 for (type = 0; type < MEASURE_TYPE_MAX; type++) {
142 previous_time[type] = 0;
148 void debug_measure_start(cam_time_meature_type meature_type,
149 const gchar *format, ...)
151 char buf[512] = { '\0', };
153 va_start(ap, format);
154 vsnprintf(buf, sizeof(buf), format, ap);
157 bool request_reset = true;
160 if(meature_type ==APP_LAUNCHING_TYPE)
162 if(g_measure_timer == NULL)
164 debug_measure_init();
165 previous_time[meature_type] = g_timer_elapsed(g_measure_timer, NULL);
169 if (g_measure_timer == NULL)
170 debug_measure_init();
172 for (type = 0; type < MEASURE_TYPE_MAX; type++) {
173 if (previous_time[type] != 0)
174 request_reset = false;
178 g_timer_reset(g_measure_timer);
180 previous_time[meature_type] = g_timer_elapsed(g_measure_timer, NULL);
182 /* cam_debug_time(LOG_TIME, "START %s : %s",debug_type[meature_type] , buf); */
185 void debug_measure_stop(cam_time_meature_type meature_type,
186 const gchar *format, ...)
188 char buf[512] = { '\0', };
190 va_start(ap, format);
191 vsnprintf(buf, sizeof(buf), format, ap);
194 gdouble current_elapsed = g_timer_elapsed(g_measure_timer, NULL);
195 gdouble meature_time = 0.0;
197 meature_time = (current_elapsed - previous_time[meature_type]);
199 cam_debug_time(LOG_TIME, "%s measure time = %.02f (sec) function %s\n",
200 debug_type[meature_type], (gfloat) (meature_time), buf);
202 previous_time[meature_type] = 0;
205 void debug_time_measure_log(const gchar *format, ...)
208 g_return_if_fail(g_timer);
209 gdouble elapsed = g_timer_elapsed(g_timer, NULL);
211 char buf[512] = {'\0',};
213 va_start(ap, format);
214 vsnprintf(buf, sizeof(buf), format, ap);
217 // cam_debug_time(LOG_TIME, "%s, measure_time = %.02f (ms)", buf, (gfloat)(elapsed - previous_elapsed));
219 previous_elapsed = elapsed;
224 void debug_time_measure_start(const gchar *format, ...)
226 char buf[512] = { '\0', };
228 va_start(ap, format);
229 vsnprintf(buf, sizeof(buf), format, ap);
232 if (g_timer == NULL) {
233 g_timer = g_timer_new();
235 g_timer_start(g_timer);
238 previous_elapsed = g_timer_elapsed(g_timer, NULL);
241 cam_debug_time(LOG_TIME, "\nNEW MEASUREMENT: %s", buf);
242 cam_debug_time(LOG_TIME, "UNIT NAME, TOTAL ELAPSED, ELAPSED");
246 void debug_time_measure_stop(void)
249 g_timer_destroy(g_timer);
253 #endif /*ENABLE_TIME_MEASURE */
255 #ifdef DEBUG_MESSAGE_ON
256 #ifndef USE_DLOG_MESSAGE
258 cam_log_func(const gchar *_domain, GLogLevelFlags log_level,
259 const char *file_name, const char *func, int line_number,
260 const char *format, ...)
264 char msg_buf[1024] = "\0", message[2048] = "\0";
266 GET_FILE_NAME(p, (char *)file_name);
268 va_start(args, format);
269 vsnprintf(msg_buf, sizeof(msg_buf), format, args);
271 snprintf(message, sizeof(message), "[%s:%s:#%d]%s", p, func,
272 line_number, msg_buf);
275 if (log_level & G_LOG_LEVEL_DEBUG) {
276 __cam_print_debug(_domain, message);
277 } else if (log_level & G_LOG_LEVEL_INFO) {
278 __cam_print_info(_domain, message);
279 } else if (log_level & G_LOG_LEVEL_MESSAGE) {
280 __cam_print_msg(_domain, message);
281 } else if (log_level & G_LOG_LEVEL_WARNING) {
282 __cam_print_warning(_domain, message);
283 } else if (log_level & G_LOG_LEVEL_CRITICAL) {
284 __cam_print_critical(_domain, message);
285 } else if (log_level & G_LOG_LEVEL_ERROR) {
286 __cam_print_error(_domain, message);