summaryrefslogtreecommitdiff
path: root/include/yagl_log.h
blob: ca3f3e96030ceee9e47a6c84006dcbfc47f604c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
 * YaGL
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact :
 * Stanislav Vorobiov <s.vorobiov@samsung.com>
 * Jinhyung Jo <jinhyung.jo@samsung.com>
 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Contributors:
 * - S-Core Co., Ltd
 *
 */

#ifndef _YAGL_LOG_H_
#define _YAGL_LOG_H_

#include "yagl_export.h"
#include "yagl_types.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>

typedef enum
{
    yagl_log_level_off = 0,
    yagl_log_level_error = 1,
    yagl_log_level_warn = 2,
    yagl_log_level_info = 3,
    yagl_log_level_debug = 4,
    yagl_log_level_trace = 5
} yagl_log_level;

#define yagl_log_level_max 5

YAGL_API void yagl_log_init(void);

YAGL_API void yagl_log_event(yagl_log_level log_level,
                             pid_t process_id,
                             pid_t thread_id,
                             const char* facility,
                             int line,
                             const char* format, ...);

YAGL_API void yagl_log_func_enter(pid_t process_id,
                                  pid_t thread_id,
                                  const char* func,
                                  int line,
                                  const char* format, ...);

YAGL_API void yagl_log_func_exit(pid_t process_id,
                                 pid_t thread_id,
                                 const char* func,
                                 int line,
                                 const char* format, ...);

/*
 * Convenience function that uses datatypes instead of format strings, one for each
 * function argument.
 *
 * 'num_args' is number of arguments to the function, then come 'num_args'
 * (datatype, arg) strings, then come 'num_args' arguments. i.e. the call is
 * like this:
 * yagl_log_func_enter_split(0, 0, "my_func", 123, 2, "EGLint", "arg_1", "EGLDisplay", "arg_2", 12, my_ptr);
 *
 * This function uses constant size storage for final format string creation,
 * be sure not to pass too many arguments, the overall size must not
 * exceed 1024 characters.
 *
 * If one of the argument datatypes is not a supported datatype, then argument
 * formatting is skipped and "..." is printed instead.
 */
YAGL_API void yagl_log_func_enter_split(pid_t process_id,
                                        pid_t thread_id,
                                        const char* func,
                                        int line,
                                        int num_args, ...);

/*
 * Same as above, but only one datatype is required and only one argument
 * is needed. i.e.:
 * yagl_log_func_exit_split(0, 0, "my_func", 234, "EGLint", 123);
 */
YAGL_API void yagl_log_func_exit_split(pid_t process_id,
                                       pid_t thread_id,
                                       const char* func,
                                       int line,
                                       const char* datatype, ...);

YAGL_API int yagl_log_is_enabled_for_level(yagl_log_level log_level);

YAGL_API int yagl_log_is_enabled_for_facility(const char* facility);

YAGL_API int yagl_log_is_enabled_for_func_tracing(void);

#ifndef NDEBUG
#define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...) \
    do \
    { \
        if ( yagl_log_is_enabled_for_level(yagl_log_level_##log_level) && \
             yagl_log_is_enabled_for_facility(facility) ) \
        { \
            yagl_log_event(yagl_log_level_##log_level, pid, tid, facility, __LINE__, format,##__VA_ARGS__); \
        } \
    } while(0)

#define YAGL_LOG_FUNC_SET(func) \
    const char* _yagl_log_current_func = #func; \
    pid_t _yagl_log_current_pid = getpid(); \
    pid_t _yagl_log_current_tid = syscall(SYS_gettid)

#define YAGL_LOG_FUNC_ENTER(func, format, ...) \
    YAGL_LOG_FUNC_SET(func); \
    do \
    { \
        if ( yagl_log_is_enabled_for_func_tracing() && \
             yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
        { \
            yagl_log_func_enter(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
        } \
    } while(0)

#define YAGL_LOG_FUNC_ENTER_SPLIT(func, num_args, ...) \
    YAGL_LOG_FUNC_SET(func); \
    do \
    { \
        if ( yagl_log_is_enabled_for_func_tracing() && \
             yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
        { \
            yagl_log_func_enter_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, num_args,##__VA_ARGS__); \
        } \
    } while(0)

#define YAGL_LOG_FUNC_EXIT(format, ...) \
    do \
    { \
        if ( yagl_log_is_enabled_for_func_tracing() && \
             yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
        { \
            yagl_log_func_exit(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
        } \
    } while(0)

#define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret) \
    do \
    { \
        if ( yagl_log_is_enabled_for_func_tracing() && \
             yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
        { \
            yagl_log_func_exit_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, #ret_type, ret); \
        } \
    } while(0)
#else
#define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...)
#define YAGL_LOG_FUNC_SET(func)
#define YAGL_LOG_FUNC_ENTER(func, format, ...)
#define YAGL_LOG_FUNC_ENTER_SPLIT(func, num_args, ...)
#define YAGL_LOG_FUNC_EXIT(format, ...)
#define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret)
#endif

#define YAGL_LOG_FUNC_ENTER_SPLIT0(func) YAGL_LOG_FUNC_ENTER_SPLIT(func, 0)

#define YAGL_LOG_FUNC_ENTER_SPLIT1(func, arg0_type, arg0) \
    YAGL_LOG_FUNC_ENTER_SPLIT(func, 1, #arg0_type, #arg0, arg0)

#define YAGL_LOG_FUNC_ENTER_SPLIT2(func, arg0_type, arg1_type, arg0, arg1) \
    YAGL_LOG_FUNC_ENTER_SPLIT(func, 2, #arg0_type, #arg0, #arg1_type, #arg1, arg0, arg1)

#define YAGL_LOG_FUNC_ENTER_SPLIT3( func, \
                                    arg0_type, arg1_type, arg2_type, \
                                    arg0, arg1, arg2 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 3, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, \
                               arg0, arg1, arg2 )

#define YAGL_LOG_FUNC_ENTER_SPLIT4( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, \
                                    arg0, arg1, arg2, arg3 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 4, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, \
                               arg0, arg1, arg2, arg3 )

#define YAGL_LOG_FUNC_ENTER_SPLIT5( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, \
                                    arg0, arg1, arg2, arg3, arg4 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 5, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, \
                               arg0, arg1, arg2, arg3, arg4 )

#define YAGL_LOG_FUNC_ENTER_SPLIT6( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, \
                                    arg0, arg1, arg2, arg3, arg4, arg5 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 6, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, \
                               arg0, arg1, arg2, arg3, arg4, arg5 )

#define YAGL_LOG_FUNC_ENTER_SPLIT7( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, \
                                    arg0, arg1, arg2, arg3, arg4, arg5, arg6 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 7, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, #arg6_type, #arg6, \
                               arg0, arg1, arg2, arg3, arg4, arg5, arg6 )

#define YAGL_LOG_FUNC_ENTER_SPLIT8( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, \
                                    arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 8, \
                               #arg0_type, #arg0, #arg1_type, #arg1, #arg2_type, #arg2, #arg3_type, #arg3, #arg4_type, #arg4, #arg5_type, #arg5, #arg6_type, #arg6, #arg7_type, #arg7, \
                               arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 )

#define YAGL_LOG_FUNC_ENTER_SPLIT9( func, \
                                    arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, \
                                    arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 9, \
                               #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, \
                               arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )

#define YAGL_LOG_FUNC_ENTER_SPLIT10( func, \
                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, arg9_type, \
                                     arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 10, \
                               #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, #arg9_type, #arg9, \
                               arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 )

#define YAGL_LOG_FUNC_ENTER_SPLIT11( func, \
                                     arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, arg9_type, arg10_type, \
                                     arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 ) \
    YAGL_LOG_FUNC_ENTER_SPLIT( func, 11, \
                               #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, #arg9_type, #arg9, #arg10_type, #arg10, \
                               arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 )

#define YAGL_LOG_TRACE(format, ...) YAGL_LOG_EVENT(trace, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
#define YAGL_LOG_DEBUG(format, ...) YAGL_LOG_EVENT(debug, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
#define YAGL_LOG_INFO(format, ...) YAGL_LOG_EVENT(info, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
#define YAGL_LOG_WARN(format, ...) YAGL_LOG_EVENT(warn, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
#define YAGL_LOG_ERROR(format, ...) YAGL_LOG_EVENT(error, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)

#endif