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.
22 #include <glib-object.h>
28 #define ENABLE_TIME_MEASURE
30 #define ENABLE_TIME_STAMP
32 #define DEBUG_MESSAGE_ON
33 #define USE_DLOG_MESSAGE /* for dlog */
34 #define TRACE_FENTER_LEAVE
35 #define ENABLE_CHECK_MEMORY_OCCUPIED_SIZE
37 #define LOG_UI "UI" /* about UI, EFL, */
38 #define LOG_MM "MM" /* about MSL, */
39 #define LOG_FILE "FILE" /* about file */
40 #define LOG_SND "SOUND"
41 #define LOG_SYS "SYSTEM"
42 #define LOG_FWK "FRAMEWROK"
43 #define LOG_CONFIG "CONFIG"
44 #define LOG_CAM "CAMERA" /* #define LOG_CAMERA 0x00000001 */
45 #ifdef DEBUG_MESSAGE_ON
46 #define GET_FILE_NAME(p, f) \
48 p = strrchr(f, '/'); \
55 #ifdef ENABLE_CHECK_MEMORY_STATUS
56 #define CHECK_MEMORY_STATS(s) fprintf(stderr, "[%s]: %s\n", s , __FUNCTION__); \
58 fprintf(stderr, "------------------\n")
60 #define CHECK_MEMORY_STATS(s) G_STMT_START{ (void)0; }G_STMT_END
63 #ifdef ENABLE_CHECK_MEMORY_OCCUPIED_SIZE
65 struct mallinfo g_mem_info;
68 #ifdef USE_DLOG_MESSAGE
75 #define LOG_TAG "cam-app"
77 #define DEBUG_TRACE(fmt, arg...) do { if (TRUE) { \
78 LOGD("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg); \
81 #define debug_msg(domain, fmt, arg...) LOGD("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
82 #define cam_debug(domain, fmt, arg...) LOGD("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
83 #define cam_info(domain, fmt, arg...) LOGI("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
84 #define cam_message(domain, fmt, arg...) LOGI("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
85 #define cam_warning(domain, fmt, arg...) LOGW("[%s : %s : %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
86 #define cam_critical(domain, fmt, arg...) LOGE("[%s : %s: %d] "fmt"\n", __FILE__, __FUNCTION__, __LINE__, ##arg)
88 #ifdef ENABLE_CHECK_MEMORY_OCCUPIED_SIZE
89 #define CHECK_MEMORY_STATS(s) g_mem_info = mallinfo(); \
90 LOGD("\n\n[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.hblkhd + (g_mem_info).uordblks)
93 dlog(MID_CAMERA, DLOG_VERBOSE, "\n\n[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.arena); \
94 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.ordblks); \
95 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.hblks); \
96 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.hblkhd); \
97 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.uordblks); \
98 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.fordblks); \
99 dlog(MID_CAMERA, DLOG_VERBOSE, "[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.keepcost); \
102 #else /* #ifdef USE_DLOG_MESSAGE */
105 cam_log_func(const gchar *_domain, GLogLevelFlags log_level,
106 const char *file_name, const char *func, int line_number,
107 const char *format, ...);
109 #define debug_msg(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_DEBUG, __FILE__, __func__, __LINE__, fmt, ##arg)
110 #define cam_debug(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_DEBUG, __FILE__, __func__, __LINE__, fmt, ##arg)
111 #define cam_info(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_INFO, __FILE__, __func__, __LINE__, fmt, ##arg)
112 #define cam_message(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_MESSAGE, __FILE__, __func__, __LINE__, fmt, ##arg)
113 #define cam_warning(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_WARNING, __FILE__, __func__, __LINE__, fmt, ##arg)
114 #define cam_critical(category, fmt, arg...) cam_log_func(category, G_LOG_LEVEL_CRITICAL, __FILE__, __func__, __LINE__, fmt, ##arg)
116 #ifdef ENABLE_CHECK_MEMORY_OCCUPIED_SIZE
117 #define CHECK_MEMORY_STATS(s) g_mem_info = mallinfo(); \
118 cam_debug(LOG_SYS, "\n\n[[[[[[[[[[ %s : mem size is %d ]]]]]]]]]]\n", s, g_mem_info.hblkhd + (g_mem_info).uordblks)
121 #endif /* DEBUG MESSAGE ON */
124 #define debug_msg(domain, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
125 #define cam_debug(domain, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
126 #define cam_info(domain, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
127 #define cam_message(domain, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
128 #define cam_warning(domain, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
129 #define cam_critical(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
130 #ifdef ENABLE_CHECK_MEMORY_OCCUPIED_SIZE
131 #define CHECK_MEMORY_STATS(s) G_STMT_START{ (void)0; } G_STMT_END
133 #endif /* #ifdef DEBUG_MESSAGE_ON */
134 #define warn_msg cam_warning
135 #define critical_msg cam_critical
136 /* Trace function enter/leave
138 #ifdef TRACE_FENTER_LEAVE
139 #define debug_fenter(domain) cam_debug(domain, " started");
140 #define debug_fleave(domain) cam_debug(domain, " leaved");
142 #define debug_fenter(domain) G_STMT_START{ (void)0; } G_STMT_END
143 #define debug_fleave(domain) G_STMT_START{ (void)0; } G_STMT_END
145 #define cam_ret_if(expr) do { \
150 #define cam_retv_if(expr, val) do { \
155 #define cam_retm_if(expr, fmt, arg...) do { \
157 cam_warning(LOG_UI, fmt, ##arg); \
161 #define cam_retvm_if(expr, val, fmt, arg...) do { \
163 cam_warning(LOG_UI, fmt, ##arg); \
167 /* Trace module elapsed time
169 #ifdef ENABLE_TIME_MEASURE
171 NORMAL_MEASURE_TYPE = 0,
173 CAPTURE_MEASURE_TYPE,
174 REGISTER_MEASURE_TYPE,
175 REC_START_MEASURE_TYPE,
176 REC_COMMIT_MEASURE_TYPE,
180 } cam_time_meature_type;
182 void debug_measure_start(cam_time_meature_type meature_type,
183 const gchar *format, ...);
184 void debug_measure_stop(cam_time_meature_type meature_type,
185 const gchar *format, ...);
186 void debug_measure_init();
187 void debug_measure_close();
189 void debug_time_measure_start(const gchar *format, ...);
190 void debug_time_measure_stop(void);
191 void debug_time_measure_log(const gchar *format, ...);
193 #define debug_time_measure_fenter(fmt, arg...) debug_time_measure_log("%s(). LINE :%d ", __FUNCTION__, __LINE__, ##arg)
194 #define debug_time_measure_fleave(fmt, arg...) debug_time_measure_log("%s(). LINE :%d", __FUNCTION__, __LINE__, ##arg)
197 #define debug_time_measure_start(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
198 #define debug_time_measure_stop() G_STMT_START{ (void)0; } G_STMT_END
199 #define debug_time_measure_log(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
200 #define debug_time_measure_fenter(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
201 #define debug_time_measure_fleave(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
202 #define debug_measure_start(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
203 #define debug_measure_stop(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
204 #define debug_measure_init() G_STMT_START{ (void)0; } G_STMT_END
205 #define debug_measure_close() G_STMT_START{ (void)0; } G_STMT_END
206 #endif /*ENABLE_TIME_MEASURE */
207 #ifdef ENABLE_TIME_STAMP
208 #include <sys/time.h>
209 #include <linux/unistd.h>
211 CAM_MSG_COLOR_DEFAULT = 0,
212 CAM_MSG_COLOR_BLACK = 30,
213 CAM_MSG_COLOR_RED = 31,
214 CAM_MSG_COLOR_GREEN = 32,
215 CAM_MSG_COLOR_YELLOW = 33,
216 CAM_MSG_COLOR_BLUE = 34,
217 CAM_MSG_COLOR_MAGENTA = 35,
218 CAM_MSG_COLOR_CYAN = 36,
219 CAM_MSG_COLOR_WHITE = 37,
222 static long s_time_sec = 0L;
223 static long s_time_usec = 0L;
224 static struct timeval s_cur_time;
226 static pid_t gettid(void)
228 return syscall(__NR_gettid);
231 #define debug_time_reset(fmt, arg...) \
233 struct timeval time; \
234 gettimeofday(&time, NULL); \
236 s_time_sec = time.tv_sec; \
237 s_time_usec = time.tv_usec; \
238 debug_color(CAM_MSG_COLOR_RED, "[TIMER],<%03ld.%03ld>, \t000.000 sec (reset timer)\t000.000\t[%-20.20s:%4d]" fmt "\n", s_time_sec, s_time_usec, __FUNCTION__, __LINE__, ##arg); \
241 #define debug_time_stamp(fmt, arg...) \
243 struct timeval time; \
245 long a_sec, a_usec; \
246 gettimeofday(&time, NULL); \
247 a_sec = time.tv_sec - s_cur_time.tv_sec; \
248 if (s_cur_time.tv_usec > time.tv_usec) { \
249 a_usec = 1000000L - s_cur_time.tv_usec + time.tv_usec; \
252 a_usec = time.tv_usec - s_cur_time.tv_usec; \
255 sec = time.tv_sec - s_time_sec; \
256 if (s_time_usec > time.tv_usec) { \
257 usec = 1000000L - s_time_usec + time.tv_usec; \
260 usec = time.tv_usec - s_time_usec; \
262 debug_color(CAM_MSG_COLOR_RED, "[TIMER],<%03ld.%03ld>, %03ld.%03ld sec (time stamp) %03ld.%03ld\t[%-20.20s:%4d]" fmt "\n", time.tv_sec, time.tv_usec, sec, usec / 1000, a_sec, a_usec/1000, __FUNCTION__, __LINE__, ##arg); \
265 #define debug_time_stamp_simple(fmt, arg...) \
267 struct timeval time; \
268 gettimeofday(&time, NULL); \
269 debug_color(CAM_MSG_COLOR_RED, "[TIMER],<%03ld.%03ld> (reset timer), [%-20.20s:%4d], TID=%d" fmt "\n", time.tv_sec, time.tv_usec, __FUNCTION__, __LINE__, gettid(), ##arg); \
272 #define debug_color(color, fmt, arg...) \
274 fprintf(stderr, "\033[%dm", color); \
275 fprintf(stderr, fmt, ##arg); \
276 fprintf(stderr, "\033[%dm", CAM_MSG_COLOR_DEFAULT); \
281 * NO PROFILING MESSAGE
283 #define debug_time_reset(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
284 #define debug_time_stamp(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
285 #define debug_time_stamp_simple(fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
287 /* Trace GObject deletion
290 void cam_debug_trace_object(gpointer obj, const gchar *format, ...);
292 #define cam_debug_trace_object(obj, fmt, arg...) G_STMT_START{ (void)0; } G_STMT_END
294 #define cam_debug_trace_alloc cam_debug_trace_object
296 #endif /*_CAM_DEBUG_H_*/