Tizen 2.1 base
[sdk/emulator/qemu.git] / hw / yagl_log.h
1 #ifndef _QEMU_YAGL_LOG_H
2 #define _QEMU_YAGL_LOG_H
3
4 #include "yagl_types.h"
5
6 //#define YAGL_LOG_DISABLE
7
8 typedef enum
9 {
10     yagl_log_level_off = 0,
11     yagl_log_level_error = 1,
12     yagl_log_level_warn = 2,
13     yagl_log_level_info = 3,
14     yagl_log_level_debug = 4,
15     yagl_log_level_trace = 5
16 } yagl_log_level;
17
18 #define yagl_log_level_max yagl_log_level_trace
19
20 void yagl_log_init(void);
21
22 void yagl_log_cleanup(void);
23
24 void yagl_log_event(yagl_log_level log_level,
25                     yagl_pid process_id,
26                     yagl_tid thread_id,
27                     const char* facility,
28                     int line,
29                     const char* format, ...);
30
31 void yagl_log_func_enter(yagl_pid process_id,
32                          yagl_tid thread_id,
33                          const char* func,
34                          int line,
35                          const char* format, ...);
36
37 void yagl_log_func_exit(yagl_pid process_id,
38                         yagl_tid thread_id,
39                         const char* func,
40                         int line,
41                         const char* format, ...);
42
43 /*
44  * Convenience function that uses datatypes instead of format strings, one for each
45  * function argument.
46  *
47  * 'num_args' is number of arguments to the function, then come 'num_args'
48  * (datatype, arg) strings, then come 'num_args' arguments. i.e. the call is
49  * like this:
50  * yagl_log_func_enter_split(0, 0, "my_func", 123, 2, "EGLint", "arg_1", "EGLDisplay", "arg_2", 12, my_ptr);
51  *
52  * This function uses constant size storage for final format string creation,
53  * be sure not to pass too many arguments, the overall size must not
54  * exceed 1024 characters.
55  *
56  * If one of the argument datatypes is not a supported datatype, then argument
57  * formatting is skipped and "..." is printed instead.
58  */
59 void yagl_log_func_enter_split(yagl_pid process_id,
60                                yagl_tid thread_id,
61                                const char* func,
62                                int line,
63                                int num_args, ...);
64
65 /*
66  * Same as above, but only one datatype is required and only one argument
67  * is needed. i.e.:
68  * yagl_log_func_exit_split(0, 0, "my_func", 234, "EGLint", 123);
69  */
70 void yagl_log_func_exit_split(yagl_pid process_id,
71                               yagl_tid thread_id,
72                               const char* func,
73                               int line,
74                               const char* datatype, ...);
75
76 bool yagl_log_is_enabled_for_level(yagl_log_level log_level);
77
78 bool yagl_log_is_enabled_for_facility(const char* facility);
79
80 bool yagl_log_is_enabled_for_func_tracing(void);
81
82 #ifndef YAGL_LOG_DISABLE
83 #define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...) \
84     do \
85     { \
86         if ( yagl_log_is_enabled_for_level(yagl_log_level_##log_level) && \
87              yagl_log_is_enabled_for_facility(facility) ) \
88         { \
89             yagl_log_event(yagl_log_level_##log_level, pid, tid, facility, __LINE__, format,##__VA_ARGS__); \
90         } \
91     } while(0)
92
93 #define YAGL_LOG_FUNC_SET(pid, tid, func) \
94     const char* _yagl_log_current_func = #func; \
95     yagl_pid _yagl_log_current_pid = pid; \
96     yagl_tid _yagl_log_current_tid = tid
97
98 #define YAGL_LOG_FUNC_SET_TS(ts, func) \
99     YAGL_LOG_FUNC_SET((ts)->ps->id, (ts)->id, func)
100
101 #define YAGL_LOG_FUNC_ENTER(pid, tid, func, format, ...) \
102     YAGL_LOG_FUNC_SET(pid, tid, func); \
103     do \
104     { \
105         if ( yagl_log_is_enabled_for_func_tracing() && \
106              yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
107         { \
108             yagl_log_func_enter(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
109         } \
110     } while(0)
111
112 #define YAGL_LOG_FUNC_ENTER_NPT(func, format, ...) \
113     YAGL_LOG_FUNC_ENTER(0, 0, func, format,##__VA_ARGS__)
114
115 #define YAGL_LOG_FUNC_ENTER_TS(ts, func, format, ...) \
116     YAGL_LOG_FUNC_ENTER((ts)->ps->id, (ts)->id, func, format,##__VA_ARGS__)
117
118 #define YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, num_args, ...) \
119     YAGL_LOG_FUNC_SET(pid, tid, func); \
120     do \
121     { \
122         if ( yagl_log_is_enabled_for_func_tracing() && \
123              yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
124         { \
125             yagl_log_func_enter_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, num_args,##__VA_ARGS__); \
126         } \
127     } while(0)
128
129 #define YAGL_LOG_FUNC_EXIT(format, ...) \
130     do \
131     { \
132         if ( yagl_log_is_enabled_for_func_tracing() && \
133              yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
134         { \
135             yagl_log_func_exit(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
136         } \
137     } while(0)
138
139 #define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret) \
140     do \
141     { \
142         if ( yagl_log_is_enabled_for_func_tracing() && \
143              yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
144         { \
145             yagl_log_func_exit_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, #ret_type, ret); \
146         } \
147     } while(0)
148 #else
149 #define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...)
150 #define YAGL_LOG_FUNC_SET(pid, tid, func)
151 #define YAGL_LOG_FUNC_SET_TS(ts, func)
152 #define YAGL_LOG_FUNC_ENTER(pid, tid, func, format, ...)
153 #define YAGL_LOG_FUNC_ENTER_NPT(func, format, ...)
154 #define YAGL_LOG_FUNC_ENTER_TS(ts, func, format, ...)
155 #define YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, num_args, ...)
156 #define YAGL_LOG_FUNC_EXIT(format, ...)
157 #define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret)
158 #endif
159
160 #define YAGL_LOG_FUNC_ENTER_SPLIT0(pid, tid, func) YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, 0)
161
162 #define YAGL_LOG_FUNC_ENTER_SPLIT1(pid, tid, func, arg0_type, arg0) \
163     YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, 1, #arg0_type, #arg0, arg0)
164
165 #define YAGL_LOG_FUNC_ENTER_SPLIT2(pid, tid, func, arg0_type, arg1_type, arg0, arg1) \
166     YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, 2, #arg0_type, #arg0, #arg1_type, #arg1, arg0, arg1)
167
168 #define YAGL_LOG_FUNC_ENTER_SPLIT3( pid, tid, func, \
169                                     arg0_type, arg1_type, arg2_type, \
170                                     arg0, arg1, arg2 ) \
171     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 3, \
172                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, \
173                                arg0, arg1, arg2 )
174
175 #define YAGL_LOG_FUNC_ENTER_SPLIT4( pid, tid, func, \
176                                     arg0_type, arg1_type, arg2_type, arg3_type, \
177                                     arg0, arg1, arg2, arg3 ) \
178     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 4, \
179                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, \
180                                arg0, arg1, arg2, arg3 )
181
182 #define YAGL_LOG_FUNC_ENTER_SPLIT5( pid, tid, func, \
183                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, \
184                                     arg0, arg1, arg2, arg3, arg4 ) \
185     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 5, \
186                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, \
187                                arg0, arg1, arg2, arg3, arg4 )
188
189 #define YAGL_LOG_FUNC_ENTER_SPLIT6( pid, tid, func, \
190                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, \
191                                     arg0, arg1, arg2, arg3, arg4, arg5 ) \
192     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 6, \
193                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, \
194                                arg0, arg1, arg2, arg3, arg4, arg5 )
195
196 #define YAGL_LOG_FUNC_ENTER_SPLIT7( pid, tid, func, \
197                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, \
198                                     arg0, arg1, arg2, arg3, arg4, arg5, arg6 ) \
199     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 7, \
200                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, #arg6_type, #arg6, \
201                                arg0, arg1, arg2, arg3, arg4, arg5, arg6 )
202
203 #define YAGL_LOG_FUNC_ENTER_SPLIT8( pid, tid, func, \
204                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, \
205                                     arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ) \
206     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 8, \
207                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, #arg6_type, #arg6, #arg7_type, #arg7, \
208                                arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 )
209
210 #define YAGL_LOG_FUNC_ENTER_SPLIT9( pid, tid, func, \
211                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, \
212                                     arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ) \
213     YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 9, \
214                                #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, #arg6_type, #arg6, #arg7_type, #arg7, #arg8_type, #arg8, \
215                                arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )
216
217 #define YAGL_LOG_TRACE(format, ...) YAGL_LOG_EVENT(trace, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
218 #define YAGL_LOG_DEBUG(format, ...) YAGL_LOG_EVENT(debug, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
219 #define YAGL_LOG_INFO(format, ...) YAGL_LOG_EVENT(info, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
220 #define YAGL_LOG_WARN(format, ...) YAGL_LOG_EVENT(warn, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
221 #define YAGL_LOG_ERROR(format, ...) YAGL_LOG_EVENT(error, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
222 #define YAGL_LOG_CRITICAL(format, ...) \
223     yagl_log_event(yagl_log_level_error, 0, 0, __FUNCTION__, __LINE__, format,##__VA_ARGS__)
224
225 #endif