1 #ifndef _QEMU_YAGL_LOG_H
2 #define _QEMU_YAGL_LOG_H
4 #include "yagl_types.h"
6 //#define YAGL_LOG_DISABLE
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
18 #define yagl_log_level_max yagl_log_level_trace
20 void yagl_log_init(void);
22 void yagl_log_cleanup(void);
24 void yagl_log_event(yagl_log_level log_level,
29 const char* format, ...);
31 void yagl_log_func_enter(yagl_pid process_id,
35 const char* format, ...);
37 void yagl_log_func_exit(yagl_pid process_id,
41 const char* format, ...);
44 * Convenience function that uses datatypes instead of format strings, one for each
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
50 * yagl_log_func_enter_split(0, 0, "my_func", 123, 2, "EGLint", "arg_1", "EGLDisplay", "arg_2", 12, my_ptr);
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.
56 * If one of the argument datatypes is not a supported datatype, then argument
57 * formatting is skipped and "..." is printed instead.
59 void yagl_log_func_enter_split(yagl_pid process_id,
66 * Same as above, but only one datatype is required and only one argument
68 * yagl_log_func_exit_split(0, 0, "my_func", 234, "EGLint", 123);
70 void yagl_log_func_exit_split(yagl_pid process_id,
74 const char* datatype, ...);
76 bool yagl_log_is_enabled_for_level(yagl_log_level log_level);
78 bool yagl_log_is_enabled_for_facility(const char* facility);
80 bool yagl_log_is_enabled_for_func_tracing(void);
82 #ifndef YAGL_LOG_DISABLE
83 #define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...) \
86 if ( yagl_log_is_enabled_for_level(yagl_log_level_##log_level) && \
87 yagl_log_is_enabled_for_facility(facility) ) \
89 yagl_log_event(yagl_log_level_##log_level, pid, tid, facility, __LINE__, format,##__VA_ARGS__); \
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
98 #define YAGL_LOG_FUNC_SET_TS(ts, func) \
99 YAGL_LOG_FUNC_SET((ts)->ps->id, (ts)->id, func)
101 #define YAGL_LOG_FUNC_ENTER(pid, tid, func, format, ...) \
102 YAGL_LOG_FUNC_SET(pid, tid, func); \
105 if ( yagl_log_is_enabled_for_func_tracing() && \
106 yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
108 yagl_log_func_enter(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
112 #define YAGL_LOG_FUNC_ENTER_NPT(func, format, ...) \
113 YAGL_LOG_FUNC_ENTER(0, 0, func, format,##__VA_ARGS__)
115 #define YAGL_LOG_FUNC_ENTER_TS(ts, func, format, ...) \
116 YAGL_LOG_FUNC_ENTER((ts)->ps->id, (ts)->id, func, format,##__VA_ARGS__)
118 #define YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, num_args, ...) \
119 YAGL_LOG_FUNC_SET(pid, tid, func); \
122 if ( yagl_log_is_enabled_for_func_tracing() && \
123 yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
125 yagl_log_func_enter_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, num_args,##__VA_ARGS__); \
129 #define YAGL_LOG_FUNC_EXIT(format, ...) \
132 if ( yagl_log_is_enabled_for_func_tracing() && \
133 yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
135 yagl_log_func_exit(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
139 #define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret) \
142 if ( yagl_log_is_enabled_for_func_tracing() && \
143 yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
145 yagl_log_func_exit_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, #ret_type, ret); \
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)
160 #define YAGL_LOG_FUNC_ENTER_SPLIT0(pid, tid, func) YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, 0)
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)
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)
168 #define YAGL_LOG_FUNC_ENTER_SPLIT3( pid, tid, func, \
169 arg0_type, arg1_type, arg2_type, \
171 YAGL_LOG_FUNC_ENTER_SPLIT( pid, tid, func, 3, \
172 #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, \
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 )
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 )
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 )
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 )
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 )
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 )
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__)