2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
7 #ifndef BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP
8 #define BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP
13 #include <babeltrace2/babeltrace.h>
15 #include "cpp-common/bt2c/logging.hpp"
16 #include "ctfser/ctfser.h"
19 struct fs_sink_ctf_stream_class;
23 explicit fs_sink_stream(const bt2c::Logger& parentLogger) :
24 logger {parentLogger, "PLUGIN/SINK.CTF.FS/STREAM"}
29 fs_sink_trace *trace = nullptr;
32 /* Stream's file name */
33 GString *file_name = nullptr;
36 const bt_stream *ir_stream = nullptr;
38 fs_sink_ctf_stream_class *sc = nullptr;
40 /* Current packet's state */
44 * True if we're, for this stream, within an opened
45 * packet (got a packet beginning message, but no
46 * packet end message yet).
51 * Current beginning default clock snapshot for the
52 * current packet (`UINT64_C(-1)` if not set).
54 uint64_t beginning_cs = 0;
57 * Current end default clock snapshot for the current
58 * packet (`UINT64_C(-1)` if not set).
63 * Current packet's content size (bits) for the current
66 uint64_t content_size = 0;
69 * Current packet's total size (bits) for the current
72 uint64_t total_size = 0;
75 * Discarded events (free running) counter for the
78 uint64_t discarded_events_counter = 0;
80 /* Sequence number (free running) of the current packet */
84 * Offset of the packet context structure within the
85 * current packet (bits).
87 uint64_t context_offset_bits = 0;
90 * Owned by this; `NULL` if the current packet is closed
91 * or if the trace IR stream does not support packets.
93 const bt_packet *packet = nullptr;
96 /* Previous packet's state */
99 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
102 /* Discarded events (free running) counter */
103 uint64_t discarded_events_counter = 0;
105 /* Sequence number (free running) */
106 uint64_t seq_num = 0;
109 /* State to handle discarded events */
113 * True if we're in the time range given by a previously
114 * received discarded events message. In this case,
115 * `beginning_cs` and `end_cs` below contain the
116 * beginning and end clock snapshots for this range.
118 * This is used to validate that, when receiving a
119 * packet end message, the current discarded events time
120 * range matches what's expected for CTF 1.8, that is:
122 * * Its beginning time is the previous packet's end
123 * time (or the current packet's beginning time if
124 * this is the first packet).
126 * * Its end time is the current packet's end time.
128 bool in_range = false;
131 * Beginning and end times of the time range given by a
132 * previously received discarded events message.
134 uint64_t beginning_cs = 0;
136 } discarded_events_state;
138 /* State to handle discarded packets */
142 * True if we're in the time range given by a previously
143 * received discarded packets message. In this case,
144 * `beginning_cs` and `end_cs` below contain the
145 * beginning and end clock snapshots for this range.
147 * This is used to validate that, when receiving a
148 * packet beginning message, the current discarded
149 * packets time range matches what's expected for CTF
152 * * Its beginning time is the previous packet's end
155 * * Its end time is the current packet's beginning
158 bool in_range = false;
161 * Beginning and end times of the time range given by a
162 * previously received discarded packets message.
164 uint64_t beginning_cs = 0;
166 } discarded_packets_state;
169 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
170 const bt_stream *ir_stream);
172 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
174 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
175 const bt_event *event, struct fs_sink_ctf_event_class *ec);
177 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
178 const bt_packet *packet);
180 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
182 #endif /* BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP */