1 #ifndef _BABELTRACE_INTERNAL_H
2 #define _BABELTRACE_INTERNAL_H
5 * babeltrace/babeltrace-internal.h
7 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/compat/string.h>
32 #define PERROR_BUFLEN 200
34 extern int babeltrace_verbose
, babeltrace_debug
;
36 #define printf_verbose(fmt, args...) \
38 if (babeltrace_verbose) \
39 fprintf(stdout, "[verbose] " fmt, ## args); \
42 #define printf_debug(fmt, args...) \
44 if (babeltrace_debug) \
45 fprintf(stdout, "[debug] " fmt, ## args); \
48 #define _bt_printf(fp, kindstr, fmt, args...) \
49 fprintf(fp, "[%s]%s%s%s: " fmt "\n", \
51 babeltrace_debug ? " \"" : "", \
52 babeltrace_debug ? __func__ : "", \
53 babeltrace_debug ? "\"" : "", \
56 #define _bt_printfl(fp, kindstr, lineno, fmt, args...) \
57 fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n", \
59 babeltrace_debug ? " \"" : "", \
60 babeltrace_debug ? __func__ : "", \
61 babeltrace_debug ? "\"" : "", \
65 #define _bt_printfe(fp, kindstr, perrorstr, fmt, args...) \
66 fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n", \
68 babeltrace_debug ? " \"" : "", \
69 babeltrace_debug ? __func__ : "", \
70 babeltrace_debug ? "\"" : "", \
74 #define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...) \
75 fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n", \
77 babeltrace_debug ? " \"" : "", \
78 babeltrace_debug ? __func__ : "", \
79 babeltrace_debug ? "\"" : "", \
84 #define _bt_printf_perror(fp, fmt, args...) \
86 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
87 compat_strerror_r(errno, buf, sizeof(buf)); \
88 _bt_printfe(fp, "error", buf, fmt, ## args); \
91 #define _bt_printfl_perror(fp, lineno, fmt, args...) \
93 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
94 compat_strerror_r(errno, buf, sizeof(buf)); \
95 _bt_printfle(fp, "error", lineno, buf, fmt, ## args); \
98 /* printf without lineno information */
99 #define printf_fatal(fmt, args...) \
100 _bt_printf(stderr, "fatal", fmt, ## args)
101 #define printf_error(fmt, args...) \
102 _bt_printf(stderr, "error", fmt, ## args)
103 #define printf_warning(fmt, args...) \
104 _bt_printf(stderr, "warning", fmt, ## args)
105 #define printf_perror(fmt, args...) \
106 _bt_printf_perror(stderr, fmt, ## args)
108 /* printf with lineno information */
109 #define printfl_fatal(lineno, fmt, args...) \
110 _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
111 #define printfl_error(lineno, fmt, args...) \
112 _bt_printfl(stderr, "error", lineno, fmt, ## args)
113 #define printfl_warning(lineno, fmt, args...) \
114 _bt_printfl(stderr, "warning", lineno, fmt, ## args)
115 #define printfl_perror(lineno, fmt, args...) \
116 _bt_printfl_perror(stderr, lineno, fmt, ## args)
118 /* printf with node lineno information */
119 #define printfn_fatal(node, fmt, args...) \
120 _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
121 #define printfn_error(node, fmt, args...) \
122 _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
123 #define printfn_warning(node, fmt, args...) \
124 _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
125 #define printfn_perror(node, fmt, args...) \
126 _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
128 /* fprintf with Node lineno information */
129 #define fprintfn_fatal(fp, node, fmt, args...) \
130 _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
131 #define fprintfn_error(fp, node, fmt, args...) \
132 _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
133 #define fprintfn_warning(fp, node, fmt, args...) \
134 _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
135 #define fprintfn_perror(fp, node, fmt, args...) \
136 _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
140 # define likely(x) __builtin_expect(!!(x), 1)
142 # define likely(x) (!!(x))
148 # define unlikely(x) __builtin_expect(!!(x), 0)
150 # define unlikely(x) (!!(x))
155 * BT_HIDDEN: set the hidden attribute for internal functions
157 #define BT_HIDDEN __attribute__((visibility("hidden")))
159 #define BT_CTF_MAJOR 1
160 #define BT_CTF_MINOR 8
162 struct bt_trace_descriptor
;
163 struct trace_collection
{
164 GPtrArray
*array
; /* struct bt_trace_descriptor */
165 GHashTable
*clocks
; /* struct ctf_clock */
167 uint64_t single_clock_offset_avg
;
168 uint64_t offset_first
;
169 int64_t delta_offset_first_sum
;
171 int clock_use_offset_avg
;
174 extern int opt_all_field_names
,
175 opt_scope_field_names
,
176 opt_header_field_names
,
177 opt_context_field_names
,
178 opt_payload_field_names
,
181 opt_trace_domain_field
,
182 opt_trace_procname_field
,
183 opt_trace_vpid_field
,
184 opt_trace_hostname_field
,
185 opt_trace_default_fields
,
194 opt_clock_force_correlate
;
196 extern uint64_t opt_clock_offset
;
197 extern uint64_t opt_clock_offset_ns
;
198 extern int babeltrace_ctf_console_output
;