Implement likely/unlikely ifdefs
[babeltrace.git] / include / babeltrace / babeltrace-internal.h
1 #ifndef _BABELTRACE_INTERNAL_H
2 #define _BABELTRACE_INTERNAL_H
3
4 /*
5 * babeltrace/babeltrace-internal.h
6 *
7 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27 #include <stdio.h>
28 #include <glib.h>
29 #include <stdint.h>
30
31 extern int babeltrace_verbose, babeltrace_debug;
32
33 #define printf_verbose(fmt, args...) \
34 do { \
35 if (babeltrace_verbose) \
36 fprintf(stdout, "[verbose] " fmt, ## args); \
37 } while (0)
38
39 #define printf_debug(fmt, args...) \
40 do { \
41 if (babeltrace_debug) \
42 fprintf(stdout, "[debug] " fmt, ## args); \
43 } while (0)
44
45 #define _bt_printf(fp, kindstr, fmt, args...) \
46 fprintf(fp, "[%s]%s%s%s: " fmt "\n", \
47 kindstr, \
48 (babeltrace_debug ? " \"" : ""), \
49 (babeltrace_debug ? __func__ : ""), \
50 (babeltrace_debug ? "\"" : ""), \
51 ## args)
52
53 #define _bt_printfl(fp, kindstr, lineno, fmt, args...) \
54 fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n", \
55 kindstr, \
56 (babeltrace_debug ? " \"" : ""), \
57 (babeltrace_debug ? __func__ : ""), \
58 (babeltrace_debug ? "\"" : ""), \
59 lineno, \
60 ## args)
61
62 /* printf without lineno information */
63 #define printf_fatal(fmt, args...) \
64 _bt_printf(stderr, "fatal", fmt, ## args)
65 #define printf_error(fmt, args...) \
66 _bt_printf(stderr, "error", fmt, ## args)
67 #define printf_warning(fmt, args...) \
68 _bt_printf(stderr, "warning", fmt, ## args)
69
70 /* printf with lineno information */
71 #define printfl_fatal(lineno, fmt, args...) \
72 _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
73 #define printfl_error(lineno, fmt, args...) \
74 _bt_printfl(stderr, "error", lineno, fmt, ## args)
75 #define printfl_warning(lineno, fmt, args...) \
76 _bt_printfl(stderr, "warning", lineno, fmt, ## args)
77
78 /* printf with node lineno information */
79 #define printfn_fatal(node, fmt, args...) \
80 _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
81 #define printfn_error(node, fmt, args...) \
82 _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
83 #define printfn_warning(node, fmt, args...) \
84 _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
85
86 /* fprintf with Node lineno information */
87 #define fprintfn_fatal(fp, node, fmt, args...) \
88 _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
89 #define fprintfn_error(fp, node, fmt, args...) \
90 _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
91 #define fprintfn_warning(fp, node, fmt, args...) \
92 _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
93
94 #ifndef likely
95 # ifdef __GNUC__
96 # define likely(x) __builtin_expect(!!(x), 1)
97 # else
98 # define likely(x) (!!(x))
99 # endif
100 #endif
101
102 #ifndef unlikely
103 # ifdef __GNUC__
104 # define unlikely(x) __builtin_expect(!!(x), 0)
105 # else
106 # define unlikely(x) (!!(x))
107 # endif
108 #endif
109
110 /*
111 * BT_HIDDEN: set the hidden attribute for internal functions
112 */
113 #define BT_HIDDEN __attribute__((visibility("hidden")))
114
115 struct bt_trace_descriptor;
116 struct trace_collection {
117 GPtrArray *array; /* struct bt_trace_descriptor */
118 GHashTable *clocks; /* struct ctf_clock */
119
120 uint64_t single_clock_offset_avg;
121 uint64_t offset_first;
122 int64_t delta_offset_first_sum;
123 int offset_nr;
124 int clock_use_offset_avg;
125 };
126
127 extern int opt_all_field_names,
128 opt_scope_field_names,
129 opt_header_field_names,
130 opt_context_field_names,
131 opt_payload_field_names,
132 opt_all_fields,
133 opt_trace_field,
134 opt_trace_domain_field,
135 opt_trace_procname_field,
136 opt_trace_vpid_field,
137 opt_trace_hostname_field,
138 opt_trace_default_fields,
139 opt_loglevel_field,
140 opt_emf_field,
141 opt_callsite_field,
142 opt_delta_field,
143 opt_clock_cycles,
144 opt_clock_seconds,
145 opt_clock_date,
146 opt_clock_gmt,
147 opt_clock_force_correlate;
148
149 extern uint64_t opt_clock_offset;
150
151 #endif
This page took 0.033209 seconds and 5 git commands to generate.