Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-stream.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
8 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
9
10 #include "common/macros.h"
11 #include <babeltrace2/babeltrace.h>
12 #include "ctfser/ctfser.h"
13 #include <glib.h>
14 #include <stdbool.h>
15 #include <stdint.h>
16
17 #include "fs-sink-ctf-meta.h"
18
19 struct fs_sink_trace;
20
21 struct fs_sink_stream {
22 bt_logging_level log_level;
23 struct fs_sink_trace *trace;
24 struct bt_ctfser ctfser;
25
26 /* Stream's file name */
27 GString *file_name;
28
29 /* Weak */
30 const bt_stream *ir_stream;
31
32 struct fs_sink_ctf_stream_class *sc;
33
34 /* Current packet's state */
35 struct {
36 /*
37 * True if we're, for this stream, within an opened
38 * packet (got a packet beginning message, but no
39 * packet end message yet).
40 */
41 bool is_open;
42
43 /*
44 * Current beginning default clock snapshot for the
45 * current packet (`UINT64_C(-1)` if not set).
46 */
47 uint64_t beginning_cs;
48
49 /*
50 * Current end default clock snapshot for the current
51 * packet (`UINT64_C(-1)` if not set).
52 */
53 uint64_t end_cs;
54
55 /*
56 * Current packet's content size (bits) for the current
57 * packet.
58 */
59 uint64_t content_size;
60
61 /*
62 * Current packet's total size (bits) for the current
63 * packet.
64 */
65 uint64_t total_size;
66
67 /*
68 * Discarded events (free running) counter for the
69 * current packet.
70 */
71 uint64_t discarded_events_counter;
72
73 /* Sequence number (free running) of the current packet */
74 uint64_t seq_num;
75
76 /*
77 * Offset of the packet context structure within the
78 * current packet (bits).
79 */
80 uint64_t context_offset_bits;
81
82 /*
83 * Owned by this; `NULL` if the current packet is closed
84 * or if the trace IR stream does not support packets.
85 */
86 const bt_packet *packet;
87 } packet_state;
88
89 /* Previous packet's state */
90 struct {
91 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
92 uint64_t end_cs;
93
94 /* Discarded events (free running) counter */
95 uint64_t discarded_events_counter;
96
97 /* Sequence number (free running) */
98 uint64_t seq_num;
99 } prev_packet_state;
100
101 /* State to handle discarded events */
102 struct {
103 /*
104 * True if we're in the time range given by a previously
105 * received discarded events message. In this case,
106 * `beginning_cs` and `end_cs` below contain the
107 * beginning and end clock snapshots for this range.
108 *
109 * This is used to validate that, when receiving a
110 * packet end message, the current discarded events time
111 * range matches what's expected for CTF 1.8, that is:
112 *
113 * * Its beginning time is the previous packet's end
114 * time (or the current packet's beginning time if
115 * this is the first packet).
116 *
117 * * Its end time is the current packet's end time.
118 */
119 bool in_range;
120
121 /*
122 * Beginning and end times of the time range given by a
123 * previously received discarded events message.
124 */
125 uint64_t beginning_cs;
126 uint64_t end_cs;
127 } discarded_events_state;
128
129 /* State to handle discarded packets */
130 struct {
131 /*
132 * True if we're in the time range given by a previously
133 * received discarded packets message. In this case,
134 * `beginning_cs` and `end_cs` below contain the
135 * beginning and end clock snapshots for this range.
136 *
137 * This is used to validate that, when receiving a
138 * packet beginning message, the current discarded
139 * packets time range matches what's expected for CTF
140 * 1.8, that is:
141 *
142 * * Its beginning time is the previous packet's end
143 * time.
144 *
145 * * Its end time is the current packet's beginning
146 * time.
147 */
148 bool in_range;
149
150 /*
151 * Beginning and end times of the time range given by a
152 * previously received discarded packets message.
153 */
154 uint64_t beginning_cs;
155 uint64_t end_cs;
156 } discarded_packets_state;
157 };
158
159 BT_HIDDEN
160 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
161 const bt_stream *ir_stream);
162
163 BT_HIDDEN
164 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
165
166 BT_HIDDEN
167 int fs_sink_stream_write_event(struct fs_sink_stream *stream,
168 const bt_clock_snapshot *cs, const bt_event *event,
169 struct fs_sink_ctf_event_class *ec);
170
171 BT_HIDDEN
172 int fs_sink_stream_open_packet(struct fs_sink_stream *stream,
173 const bt_clock_snapshot *cs, const bt_packet *packet);
174
175 BT_HIDDEN
176 int fs_sink_stream_close_packet(struct fs_sink_stream *stream,
177 const bt_clock_snapshot *cs);
178
179 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */
This page took 0.036312 seconds and 4 git commands to generate.