Start of bt_component_factory implementation
[babeltrace.git] / include / babeltrace / babeltrace-internal.h
CommitLineData
70bd0a12
JD
1#ifndef _BABELTRACE_INTERNAL_H
2#define _BABELTRACE_INTERNAL_H
3
eb31c5e6
MD
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.
c462e188
MD
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.
eb31c5e6 26 */
70bd0a12
JD
27#include <stdio.h>
28#include <glib.h>
11ac6674 29#include <stdint.h>
f3e4505b
JG
30#include <stdlib.h>
31#include <errno.h>
9a7f65a3 32#include <babeltrace/compat/string.h>
fd3c708f
MD
33
34#define PERROR_BUFLEN 200
70bd0a12
JD
35
36extern int babeltrace_verbose, babeltrace_debug;
37
3394d22e
MD
38#define printf_verbose(fmt, args...) \
39 do { \
40 if (babeltrace_verbose) \
41 fprintf(stdout, "[verbose] " fmt, ## args); \
70bd0a12
JD
42 } while (0)
43
3394d22e
MD
44#define printf_debug(fmt, args...) \
45 do { \
46 if (babeltrace_debug) \
47 fprintf(stdout, "[debug] " fmt, ## args); \
70bd0a12
JD
48 } while (0)
49
b8c621ad
EB
50#define _bt_printf(fp, kindstr, fmt, args...) \
51 fprintf(fp, "[%s]%s%s%s: " fmt "\n", \
52 kindstr, \
fd3c708f
MD
53 babeltrace_debug ? " \"" : "", \
54 babeltrace_debug ? __func__ : "", \
55 babeltrace_debug ? "\"" : "", \
b8c621ad
EB
56 ## args)
57
58#define _bt_printfl(fp, kindstr, lineno, fmt, args...) \
59 fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n", \
60 kindstr, \
fd3c708f
MD
61 babeltrace_debug ? " \"" : "", \
62 babeltrace_debug ? __func__ : "", \
63 babeltrace_debug ? "\"" : "", \
64 lineno, \
65 ## args)
66
67#define _bt_printfe(fp, kindstr, perrorstr, fmt, args...) \
68 fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n", \
69 kindstr, \
70 babeltrace_debug ? " \"" : "", \
71 babeltrace_debug ? __func__ : "", \
72 babeltrace_debug ? "\"" : "", \
73 perrorstr, \
74 ## args)
75
76#define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...) \
77 fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n", \
78 kindstr, \
79 babeltrace_debug ? " \"" : "", \
80 babeltrace_debug ? __func__ : "", \
81 babeltrace_debug ? "\"" : "", \
b8c621ad 82 lineno, \
fd3c708f 83 perrorstr, \
b8c621ad
EB
84 ## args)
85
fd3c708f
MD
86#define _bt_printf_perror(fp, fmt, args...) \
87 ({ \
88 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
695f152d 89 bt_strerror_r(errno, buf, sizeof(buf)); \
fd3c708f
MD
90 _bt_printfe(fp, "error", buf, fmt, ## args); \
91 })
92
93#define _bt_printfl_perror(fp, lineno, fmt, args...) \
94 ({ \
95 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
695f152d 96 bt_strerror_r(errno, buf, sizeof(buf)); \
fd3c708f
MD
97 _bt_printfle(fp, "error", lineno, buf, fmt, ## args); \
98 })
99
b8c621ad
EB
100/* printf without lineno information */
101#define printf_fatal(fmt, args...) \
102 _bt_printf(stderr, "fatal", fmt, ## args)
103#define printf_error(fmt, args...) \
104 _bt_printf(stderr, "error", fmt, ## args)
105#define printf_warning(fmt, args...) \
106 _bt_printf(stderr, "warning", fmt, ## args)
fd3c708f
MD
107#define printf_perror(fmt, args...) \
108 _bt_printf_perror(stderr, fmt, ## args)
b8c621ad
EB
109
110/* printf with lineno information */
111#define printfl_fatal(lineno, fmt, args...) \
112 _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
113#define printfl_error(lineno, fmt, args...) \
114 _bt_printfl(stderr, "error", lineno, fmt, ## args)
115#define printfl_warning(lineno, fmt, args...) \
116 _bt_printfl(stderr, "warning", lineno, fmt, ## args)
fd3c708f
MD
117#define printfl_perror(lineno, fmt, args...) \
118 _bt_printfl_perror(stderr, lineno, fmt, ## args)
b8c621ad
EB
119
120/* printf with node lineno information */
121#define printfn_fatal(node, fmt, args...) \
122 _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
123#define printfn_error(node, fmt, args...) \
124 _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
125#define printfn_warning(node, fmt, args...) \
126 _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
fd3c708f
MD
127#define printfn_perror(node, fmt, args...) \
128 _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
b8c621ad
EB
129
130/* fprintf with Node lineno information */
131#define fprintfn_fatal(fp, node, fmt, args...) \
132 _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
133#define fprintfn_error(fp, node, fmt, args...) \
134 _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
135#define fprintfn_warning(fp, node, fmt, args...) \
136 _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
fd3c708f
MD
137#define fprintfn_perror(fp, node, fmt, args...) \
138 _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
b8c621ad 139
196409fe
EB
140#ifndef likely
141# ifdef __GNUC__
142# define likely(x) __builtin_expect(!!(x), 1)
143# else
144# define likely(x) (!!(x))
145# endif
146#endif
147
148#ifndef unlikely
149# ifdef __GNUC__
150# define unlikely(x) __builtin_expect(!!(x), 0)
151# else
152# define unlikely(x) (!!(x))
153# endif
154#endif
90bf3cef 155
40af9f9f
JG
156#ifndef min
157#define min(a, b) (((a) < (b)) ? (a) : (b))
158#endif
159
160#ifndef max
161#define max(a, b) (((a) > (b)) ? (a) : (b))
162#endif
163
f3e4505b
JG
164#ifndef max_t
165#define max_t(type, a, b) \
166 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
167#endif
168
169/*
170 * Memory allocation zeroed
171 */
172#define zmalloc(x) calloc(1, x)
173
5d6c80a5
JD
174/*
175 * BT_HIDDEN: set the hidden attribute for internal functions
176 */
177#define BT_HIDDEN __attribute__((visibility("hidden")))
178
7237592a
MD
179#define BT_CTF_MAJOR 1
180#define BT_CTF_MINOR 8
181
1b8455b7 182struct bt_trace_descriptor;
70bd0a12 183struct trace_collection {
1b8455b7 184 GPtrArray *array; /* struct bt_trace_descriptor */
a44bc4c9 185 GHashTable *clocks; /* struct ctf_clock */
0716bb06 186
61cf588b
MD
187 int64_t single_clock_offset_avg;
188 int64_t offset_first;
0716bb06
MD
189 int64_t delta_offset_first_sum;
190 int offset_nr;
50052405 191 int clock_use_offset_avg;
70bd0a12
JD
192};
193
cba1661c
MD
194extern int opt_all_field_names,
195 opt_scope_field_names,
196 opt_header_field_names,
197 opt_context_field_names,
82662ad4 198 opt_payload_field_names,
359d7456
MD
199 opt_all_fields,
200 opt_trace_field,
201 opt_trace_domain_field,
202 opt_trace_procname_field,
203 opt_trace_vpid_field,
32cfb8ad 204 opt_trace_hostname_field,
c3815874 205 opt_trace_default_fields,
359d7456 206 opt_loglevel_field,
f6714e20 207 opt_emf_field,
f133896d 208 opt_callsite_field,
11ac6674 209 opt_delta_field,
03798a93 210 opt_clock_cycles,
11ac6674
MD
211 opt_clock_seconds,
212 opt_clock_date,
82ace6d6 213 opt_clock_gmt,
ff9ce920
JG
214 opt_clock_force_correlate,
215 opt_debug_info_full_path;
11ac6674 216
61cf588b
MD
217extern int64_t opt_clock_offset;
218extern int64_t opt_clock_offset_ns;
2654fe9b 219extern int babeltrace_ctf_console_output;
05984e0c 220extern char *opt_debug_info_dir;
5cde0dc1 221extern char *opt_debug_info_target_prefix;
70bd0a12
JD
222
223#endif
This page took 0.050621 seconds and 4 git commands to generate.