tizen 2.3.1 release
[kernel/api/system-resource.git] / src / common / trace.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21 /*
22  * @file trace.h
23  * Common macros for tracing
24  */
25
26 #ifndef _SYSTEM_RESOURCE_TRACE_H_
27 #define _SYSTEM_RESOURCE_TRACE_H_
28
29 #include "config.h"
30 #include <dlog.h>
31 #include <errno.h>
32 #include <signal.h>
33 #include <stdio.h>
34
35 #undef LOG_TAG
36 #define LOG_TAG "RESOURCED"
37
38 #define WALK_TREE(list, func) g_tree_foreach((GTree *)list, func, NULL)
39
40 #define _E(fmt, arg...) LOGE("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
41 #define _D(fmt, arg...) LOGD("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
42 #define _I(fmt, arg...) LOGI("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
43
44 #define _SE(fmt, arg...) SECURE_LOGE("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
45 #define _SD(fmt, arg...) SECURE_LOGD("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
46 #define _SI(fmt, arg...) SECURE_LOGI("[%s,%d] "fmt, __FUNCTION__, __LINE__, ##arg)
47
48 #define TRACE_DB_ERR(a) if (a != NULL) { \
49         _D("%s\n", a); \
50         sqlite3_free(a); \
51 }
52
53 #define TRACE_RET_ERRCODE(type, error_code) do { \
54         char buf[256]; \
55         strerror_r(-error_code, buf, sizeof(buf)); \
56         _##type("errno %d, errmsg %s", error_code, buf); \
57 } while (0)
58
59 #define DTRACE_RET_ERRCODE(error_code) TRACE_RET_ERRCODE(D, error_code)
60
61 #define ETRACE_RET_ERRCODE(error_code) TRACE_RET_ERRCODE(E, error_code)
62
63 #define TRACE_RET_ERRCODE_MSG(type, error_code, fmt, arg...) do { \
64         char buf[256]; \
65         _##type(fmt, ##arg); \
66         strerror_r(-error_code, buf, sizeof(buf)); \
67         _##type("errno %d, errmsg %s", error_code, buf); \
68 } while (0)
69
70 #define DTRACE_RET_ERRCODE_MSG(error_code, fmt, arg...) \
71         TRACE_RET_ERRCODE_MSG(D, error_code, fmt, ##arg)
72
73 #define ETRACE_RET_ERRCODE_MSG(error_code, fmt, arg...) \
74         TRACE_RET_ERRCODE_MSG(E, error_code, fmt, ##arg)
75
76 #define DTRACE_ERRNO() TRACE_RET_ERRCODE(D, -errno)
77
78 #define ETRACE_ERRNO() TRACE_RET_ERRCODE(E, -errno)
79
80 #define DTRACE_ERRNO_MSG(fmt, arg...) \
81         TRACE_RET_ERRCODE_MSG(D, -errno, fmt, ##arg)
82
83 #define ETRACE_ERRNO_MSG(fmt, arg...) \
84         TRACE_RET_ERRCODE_MSG(E, -errno, fmt, ##arg)
85
86 #endif  /* _SYSTEM_RESOURCE_TRACE_H_ */