sink.ctf.fs: honor component's initial log level
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-stream.h
1 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
2 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
3
4 /*
5 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #include "common/macros.h"
27 #include <babeltrace2/babeltrace.h>
28 #include "ctfser/ctfser.h"
29 #include <glib.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32
33 #include "fs-sink-ctf-meta.h"
34
35 struct fs_sink_trace;
36
37 struct fs_sink_stream {
38 bt_logging_level log_level;
39 struct fs_sink_trace *trace;
40 struct bt_ctfser ctfser;
41
42 /* Stream's file name */
43 GString *file_name;
44
45 /* Weak */
46 const bt_stream *ir_stream;
47
48 struct fs_sink_ctf_stream_class *sc;
49
50 /* Current packet's state */
51 struct {
52 /*
53 * True if we're, for this stream, within an opened
54 * packet (got a packet beginning message, but no
55 * packet end message yet).
56 */
57 bool is_open;
58
59 /*
60 * Current beginning default clock snapshot for the
61 * current packet (`UINT64_C(-1)` if not set).
62 */
63 uint64_t beginning_cs;
64
65 /*
66 * Current end default clock snapshot for the current
67 * packet (`UINT64_C(-1)` if not set).
68 */
69 uint64_t end_cs;
70
71 /*
72 * Current packet's content size (bits) for the current
73 * packet.
74 */
75 uint64_t content_size;
76
77 /*
78 * Current packet's total size (bits) for the current
79 * packet.
80 */
81 uint64_t total_size;
82
83 /*
84 * Discarded events (free running) counter for the
85 * current packet.
86 */
87 uint64_t discarded_events_counter;
88
89 /* Sequence number (free running) of the current packet */
90 uint64_t seq_num;
91
92 /*
93 * Offset of the packet context structure within the
94 * current packet (bits).
95 */
96 uint64_t context_offset_bits;
97
98 /* Owned by this */
99 const bt_packet *packet;
100 } packet_state;
101
102 /* Previous packet's state */
103 struct {
104 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
105 uint64_t end_cs;
106
107 /* Discarded events (free running) counter */
108 uint64_t discarded_events_counter;
109
110 /* Sequence number (free running) */
111 uint64_t seq_num;
112 } prev_packet_state;
113
114 /* State to handle discarded events */
115 struct {
116 /*
117 * True if we're in the time range given by a previously
118 * received discarded events message. In this case,
119 * `beginning_cs` and `end_cs` below contain the
120 * beginning and end clock snapshots for this range.
121 *
122 * This is used to validate that, when receiving a
123 * packet end message, the current discarded events time
124 * range matches what's expected for CTF 1.8, that is:
125 *
126 * * Its beginning time is the previous packet's end
127 * time (or the current packet's beginning time if
128 * this is the first packet).
129 *
130 * * Its end time is the current packet's end time.
131 */
132 bool in_range;
133
134 /*
135 * Beginning and end times of the time range given by a
136 * previously received discarded events message.
137 */
138 uint64_t beginning_cs;
139 uint64_t end_cs;
140 } discarded_events_state;
141
142 /* State to handle discarded packets */
143 struct {
144 /*
145 * True if we're in the time range given by a previously
146 * received discarded packets message. In this case,
147 * `beginning_cs` and `end_cs` below contain the
148 * beginning and end clock snapshots for this range.
149 *
150 * This is used to validate that, when receiving a
151 * packet beginning message, the current discarded
152 * packets time range matches what's expected for CTF
153 * 1.8, that is:
154 *
155 * * Its beginning time is the previous packet's end
156 * time.
157 *
158 * * Its end time is the current packet's beginning
159 * time.
160 */
161 bool in_range;
162
163 /*
164 * Beginning and end times of the time range given by a
165 * previously received discarded packets message.
166 */
167 uint64_t beginning_cs;
168 uint64_t end_cs;
169 } discarded_packets_state;
170 };
171
172 BT_HIDDEN
173 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
174 const bt_stream *ir_stream);
175
176 BT_HIDDEN
177 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
178
179 BT_HIDDEN
180 int fs_sink_stream_write_event(struct fs_sink_stream *stream,
181 const bt_clock_snapshot *cs, const bt_event *event,
182 struct fs_sink_ctf_event_class *ec);
183
184 BT_HIDDEN
185 int fs_sink_stream_open_packet(struct fs_sink_stream *stream,
186 const bt_clock_snapshot *cs, const bt_packet *packet);
187
188 BT_HIDDEN
189 int fs_sink_stream_close_packet(struct fs_sink_stream *stream,
190 const bt_clock_snapshot *cs);
191
192 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */
This page took 0.035898 seconds and 5 git commands to generate.