2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
7 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
8 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
13 #include <babeltrace2/babeltrace.h>
15 #include "ctfser/ctfser.h"
18 struct fs_sink_ctf_stream_class;
22 bt_logging_level log_level = BT_LOGGING_LEVEL_NONE;
23 fs_sink_trace *trace = nullptr;
26 /* Stream's file name */
27 GString *file_name = nullptr;
30 const bt_stream *ir_stream = nullptr;
32 fs_sink_ctf_stream_class *sc = nullptr;
34 /* Current packet's state */
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).
45 * Current beginning default clock snapshot for the
46 * current packet (`UINT64_C(-1)` if not set).
48 uint64_t beginning_cs = 0;
51 * Current end default clock snapshot for the current
52 * packet (`UINT64_C(-1)` if not set).
57 * Current packet's content size (bits) for the current
60 uint64_t content_size = 0;
63 * Current packet's total size (bits) for the current
66 uint64_t total_size = 0;
69 * Discarded events (free running) counter for the
72 uint64_t discarded_events_counter = 0;
74 /* Sequence number (free running) of the current packet */
78 * Offset of the packet context structure within the
79 * current packet (bits).
81 uint64_t context_offset_bits = 0;
84 * Owned by this; `NULL` if the current packet is closed
85 * or if the trace IR stream does not support packets.
87 const bt_packet *packet = nullptr;
90 /* Previous packet's state */
93 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
96 /* Discarded events (free running) counter */
97 uint64_t discarded_events_counter = 0;
99 /* Sequence number (free running) */
100 uint64_t seq_num = 0;
103 /* State to handle discarded events */
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.
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:
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).
120 * * Its end time is the current packet's end time.
122 bool in_range = false;
125 * Beginning and end times of the time range given by a
126 * previously received discarded events message.
128 uint64_t beginning_cs = 0;
130 } discarded_events_state;
132 /* State to handle discarded packets */
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.
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
146 * * Its beginning time is the previous packet's end
149 * * Its end time is the current packet's beginning
152 bool in_range = false;
155 * Beginning and end times of the time range given by a
156 * previously received discarded packets message.
158 uint64_t beginning_cs = 0;
160 } discarded_packets_state;
163 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
164 const bt_stream *ir_stream);
166 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
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);
171 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
172 const bt_packet *packet);
174 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
176 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */