update tizen source
[framework/messaging/msg-service.git] / include / utils / MsgDebug.h
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #ifndef __MSG_DEBUG_H__
32 #define __MSG_DEBUG_H__
33
34 /*==================================================================================================
35                                          INCLUDE FILES
36 ==================================================================================================*/
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <sys/time.h>
41 #include <time.h>
42
43 #include "MsgTypes.h"
44 #include "MsgCmdTypes.h"
45
46 extern "C"{
47         #include <dlog.h>
48 };
49
50
51 /*==================================================================================================
52                                     DEFINES
53 ==================================================================================================*/
54 #define USER_TAG "MSG_FW"
55
56 //#define DLOG_ENABLE
57 //#define LOG_ENABLE
58
59
60 /*==================================================================================================
61                                      FUNCTION PROTOTYPES
62 ==================================================================================================*/
63 int get_tid();
64
65
66 #if defined(DLOG_ENABLE)
67
68 #define MSG_FATAL(fmt, ...) \
69         do \
70         {\
71                 SLOG(LOG_ERROR, USER_TAG, "[%s: %s(): %d] ERROR << " fmt " >>\n\n", rindex(__FILE__, '/')+1,  __FUNCTION__, __LINE__, ##__VA_ARGS__);\
72         } while (0)
73
74 #define MSG_DEBUG(fmt, ...)\
75         do\
76         {\
77                 SLOG(LOG_DEBUG, USER_TAG, "[%s: %s(): %d] " fmt"\n\n", rindex(__FILE__, '/')+1,  __FUNCTION__, __LINE__, ##__VA_ARGS__);\
78         } while (0)
79
80 #define MSG_BEGIN() \
81         do\
82     {\
83                 SLOG(LOG_DEBUG, USER_TAG, "[%s: %s(): %d] BEGIN >>>> \n\n", rindex(__FILE__, '/')+1,  __FUNCTION__, __LINE__ );\
84     } while( 0 )
85
86 #define MSG_END() \
87         do\
88     {\
89                 SLOG(LOG_DEBUG, USER_TAG, "[%s: %s(): %d] END   <<<<  \n\n", rindex(__FILE__, '/')+1,  __FUNCTION__, __LINE__ );\
90     } \
91     while( 0 )
92
93 #define MSG_PROFILE_BEGIN(pfid) \
94         unsigned int __prf_l1_##pfid = __LINE__;    \
95         struct timeval __prf_1_##pfid;              \
96         struct timeval __prf_2_##pfid;              \
97         do {                                        \
98                 gettimeofday(&__prf_1_##pfid, 0);       \
99         } while (0)
100
101 #define MSG_PROFILE_END(pfid) \
102         unsigned int __prf_l2_##pfid = __LINE__;\
103         do { \
104                 gettimeofday(&__prf_2_##pfid, 0);\
105                 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
106                 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
107                 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
108                 SLOG(LOG_DEBUG, USER_TAG, "**PROFILE** [MSGFW: %s: %s() %u ~ %u] " #pfid                            \
109                 " -> Elapsed Time: %u.%06u seconds\n",                    \
110                 rindex(__FILE__, '/')+1,                \
111                 __FUNCTION__, \
112                 __prf_l1_##pfid,                                         \
113                 __prf_l2_##pfid,                                         \
114                 (unsigned int)(__ds),                                    \
115                 (unsigned int)(__dm));                                   \
116         } while (0)
117
118 #elif defined(LOG_ENABLE)
119
120 #define MSG_FATAL(fmt, ...) \
121         do \
122         {\
123                 printf("\n[%d] [MSGFW: %s: %s(): %d] *FAILED* << " fmt" >>\n", get_tid(), rindex(__FILE__, '/')+1,  __FUNCTION__, __LINE__,  ##__VA_ARGS__);\
124         } while (0)
125
126 #define MSG_DEBUG(fmt, ...) \
127         do\
128         {\
129                 printf("\n[%d] [MSGFW: %s: %s(): %d] " fmt"\n", get_tid(), rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__);\
130         } while (0)
131
132 #define MSG_BEGIN() \
133         do\
134     {\
135         printf("\n[%d] BEGIN >>>> %s() at [MSGFW: %s: %d]\n", get_tid(),__FUNCTION__, rindex(__FILE__, '/')+1,  __LINE__ );\
136     } while( 0 )
137
138 #define MSG_END() \
139         do\
140     {\
141         printf("\n[%d] END   <<<< %s() at [MSGFW: %s: %d]\n", get_tid(), __FUNCTION__, rindex(__FILE__, '/')+1,  __LINE__); \
142     } \
143     while( 0 )
144
145 #define MSG_PROFILE_BEGIN(pfid) \
146         unsigned int __prf_l1_##pfid = __LINE__;    \
147         struct timeval __prf_1_##pfid;              \
148         struct timeval __prf_2_##pfid;              \
149         do {                                        \
150                 gettimeofday(&__prf_1_##pfid, 0);       \
151         } while (0)
152
153 #define MSG_PROFILE_END(pfid) \
154         unsigned int __prf_l2_##pfid = __LINE__;\
155         do { \
156                 gettimeofday(&__prf_2_##pfid, 0);\
157                 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
158                 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
159                 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
160                 printf("**PROFILE** [MSGFW: %s: %s() %u ~ %u] " #pfid                            \
161                 " -> Elapsed Time: %u.%06u seconds\n",                    \
162                 rindex(__FILE__, '/')+1,                \
163                 __FUNCTION__, \
164                 __prf_l1_##pfid,                                         \
165                 __prf_l2_##pfid,                                         \
166                 (unsigned int)(__ds),                                    \
167                 (unsigned int)(__dm));                                   \
168         } while (0)
169
170 #else
171
172 #define MSG_FATAL(fmt, ...)
173 #define MSG_DEBUG(fmt, ...)
174 #define MSG_BEGIN()
175 #define MSG_END()
176
177 #define MSG_PROFILE_BEGIN(pfid)
178 #define MSG_PROFILE_END(pfid)
179
180 #endif
181
182 const char * MsgDbgCmdStr(MSG_CMD_TYPE_T cmdType);
183 const char * MsgDbgEvtStr(MSG_EVENT_TYPE_T evtType);
184
185 #endif //__MSG_DEBUG_H__
186