-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebug_macros.h
77 lines (61 loc) · 2.75 KB
/
debug_macros.h
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
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _DBG_MACROS_H
#define _DBG_MACROS_H
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define TAG PLUGIN_NAME
#define API_TAG PLUGIN_NAME ".api"
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely(x) __builtin_expect(!!(x), 1)
#define debug_tag(tag, fmt, ...) do { \
if (unlikely(TSIsDebugTagSet(tag))) { \
TSDebug(tag, fmt, ##__VA_ARGS__); \
} \
} while(0)
#define debug(fmt, ...) \
debug_tag(TAG, "DEBUG: [%s:%d] [%s] " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__);
#define info(fmt, ...) \
debug_tag(TAG, "INFO: " fmt, ##__VA_ARGS__);
#define warning(fmt, ...) \
debug_tag(TAG, "WARNING: " fmt, ##__VA_ARGS__);
#define error(fmt, ...) do { \
TSError("[%s:%d] [%s] ERROR: " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
debug_tag(TAG, "[%s:%d] [%s] ERROR: " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
} while (0)
#define fatal(fmt, ...) do { \
TSError("[%s:%d] [%s] ERROR: " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
debug_tag(TAG, "[%s:%d] [%s] ERROR: " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
exit(-1); \
} while (0)
#define debug_api(fmt, ...) \
debug_tag(API_TAG, "DEBUG: [%s:%d] [%s] " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__);
#define error_api(fmt, ...) do { \
TSError("[%s:%d] [%s] ERROR: " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
debug_tag(API_TAG, "ERROR: [%s:%d] [%s] " fmt, __FILE__, __LINE__, __FUNCTION__ , ##__VA_ARGS__); \
} while (0)
#define HRTIME_FOREVER (10*HRTIME_DECADE)
#define HRTIME_DECADE (10*HRTIME_YEAR)
#define HRTIME_YEAR (365*HRTIME_DAY+HRTIME_DAY/4)
#define HRTIME_WEEK (7*HRTIME_DAY)
#define HRTIME_DAY (24*HRTIME_HOUR)
#define HRTIME_HOUR (60*HRTIME_MINUTE)
#define HRTIME_MINUTE (60*HRTIME_SECOND)
#define HRTIME_SECOND (1000*HRTIME_MSECOND)
#define HRTIME_MSECOND (1000*HRTIME_USECOND)
#define HRTIME_USECOND (1000*HRTIME_NSECOND)
#define HRTIME_NSECOND (1LL)
#endif //_DBG_MACROS_H