[FEATURE] Implement kernel -> user connection
[platform/core/system/swap-manager.git] / daemon / debug.h
1 /*
2  *  DA manager
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9  * Nikita Kalyazin    <n.kalyazin@samsung.com>
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Contributors:
24  * - Samsung RnD Institute Russia
25  *
26  */
27
28
29 #ifndef _DAEMON_DEBUG_H_
30 #define _DAEMON_DEBUG_H_
31
32 #include <stdint.h>             // for uint64_t, int64_t
33 #include <pthread.h>    // for pthread_mutex_t
34 #include <stdarg.h>
35
36 #include "da_protocol.h"
37 #include "utils.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #define printBuf(buf, len) print_buf(buf, len, __func__)
44 void print_buf(char *buf, int len, const char *info);
45
46 #ifdef PARSE_DEBUG_ON
47         #define parse_deb LOGI
48 #else
49         #define parse_deb(...)
50 #endif
51
52 #ifdef THREAD_SAMPLING_DEBUG
53         #define LOGI_th_samp LOGI
54 #else
55         #define LOGI_th_samp(...)
56 #endif
57
58 #ifdef THREAD_REPLAY_DEBUG
59         #define LOGI_th_rep LOGI
60 #else
61         #define LOGI_th_rep(...)
62 #endif
63
64 #ifdef DEBUG
65 #define LOGE(...) do_log("ERR", __func__, __VA_ARGS__)
66 #define LOGW(...) do_log("WRN", __func__, __VA_ARGS__)
67
68 #ifdef USE_LOG_ONCE
69         #define TOKENPASTE(x, y) x ## y
70         #define TOKENPASTE2(x, y) TOKENPASTE(x, y)
71         #define LOG_ONCE_VAR TOKENPASTE2(log_once_var_, __LINE__)
72         #define INIT_LOG_ONCE static char LOG_ONCE_VAR = 0
73
74         #define LOG_ONCE(W_E,...)                               \
75                 INIT_LOG_ONCE;                                  \
76                 if (LOG_ONCE_VAR == 0) {                        \
77                         TOKENPASTE2(LOG, W_E)(__VA_ARGS__);     \
78                         LOG_ONCE_VAR = 1;                       \
79                 }
80         #define LOG_ONCE_E(...) LOG_ONCE(E, __VA_ARGS__)
81         #define LOG_ONCE_W(...) LOG_ONCE(W, __VA_ARGS__)
82 #else
83         #define LOG_ONCE_W(...)
84         #define LOG_ONCE_E(...)
85 #endif
86
87 static inline void do_log(const char *prefix, const char *funcname, ...)
88 {
89         va_list ap;
90         const char *fmt;
91         fprintf(stderr, "[%s][%f] (%s):", prefix, get_uptime(), funcname);
92
93         va_start(ap, funcname);
94         fmt = va_arg(ap, const char *);
95         vfprintf(stderr, fmt, ap);
96         va_end(ap);
97 }
98
99         #ifdef NOLOGI
100                 #define LOGI(...)
101                 #define LOGI_(...)
102         #else
103                 #define LOGI(...) do_log("INF", __func__, __VA_ARGS__)
104                 #define LOGI_(...)      do {            \
105                         fprintf(stderr, __VA_ARGS__);   \
106                         fflush(stderr);                 \
107                 } while (0)
108
109         #endif
110 #else
111         #define LOGI(...)
112         #define LOGI_(...)
113         #define LOGE(...)
114         #define LOGW(...)
115         #define LOG_ONCE_W(...)
116         #define LOG_ONCE_E(...)
117
118 #endif
119
120
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif // _DAEMON_DEBUG_H_