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