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