4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9 * Nikita Kalyazin <n.kalyazin@samsung.com>
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * - Samsung RnD Institute Russia
29 #ifndef _DAEMON_DEBUG_H_
30 #define _DAEMON_DEBUG_H_
32 #include <stdint.h> // for uint64_t, int64_t
33 #include <pthread.h> // for pthread_mutex_t
36 #include "da_protocol.h"
43 #define printBuf(buf, len) print_buf(buf, len, __func__)
44 void print_buf(char *buf, int len, const char *info);
47 #define parse_deb LOGI
49 #define parse_deb(...)
52 #ifdef THREAD_SAMPLING_DEBUG
53 #define LOGI_th_samp LOGI
55 #define LOGI_th_samp(...)
58 #ifdef THREAD_REPLAY_DEBUG
59 #define LOGI_th_rep LOGI
61 #define LOGI_th_rep(...)
65 #define LOGE(...) do_log("ERR", __func__, __VA_ARGS__)
66 #define LOGW(...) do_log("WRN", __func__, __VA_ARGS__)
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
74 #define LOG_ONCE(W_E,...) \
76 if (LOG_ONCE_VAR == 0) { \
77 TOKENPASTE2(LOG, W_E)(__VA_ARGS__); \
80 #define LOG_ONCE_E(...) LOG_ONCE(E, __VA_ARGS__)
81 #define LOG_ONCE_W(...) LOG_ONCE(W, __VA_ARGS__)
83 #define LOG_ONCE_W(...)
84 #define LOG_ONCE_E(...)
87 static inline void do_log(const char *prefix, const char *funcname, ...)
91 fprintf(stderr, "[%s][%f] (%s):", prefix, get_uptime(), funcname);
93 va_start(ap, funcname);
94 fmt = va_arg(ap, const char *);
95 vfprintf(stderr, fmt, ap);
103 #define LOGI(...) do_log("INF", __func__, __VA_ARGS__)
104 #define LOGI_(...) do { \
105 fprintf(stderr, __VA_ARGS__); \
115 #define LOG_ONCE_W(...)
116 #define LOG_ONCE_E(...)
126 #endif // _DAEMON_DEBUG_H_