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
10 #include "common/macros.h"
11 #include <babeltrace2/babeltrace.h>
12 #include "ctfser/ctfser.h"
17 #include "fs-sink-ctf-meta.hpp"
23 bt_logging_level log_level;
24 struct fs_sink_trace *trace;
25 struct bt_ctfser ctfser;
27 /* Stream's file name */
31 const bt_stream *ir_stream;
33 struct fs_sink_ctf_stream_class *sc;
35 /* Current packet's state */
39 * True if we're, for this stream, within an opened
40 * packet (got a packet beginning message, but no
41 * packet end message yet).
46 * Current beginning default clock snapshot for the
47 * current packet (`UINT64_C(-1)` if not set).
49 uint64_t beginning_cs;
52 * Current end default clock snapshot for the current
53 * packet (`UINT64_C(-1)` if not set).
58 * Current packet's content size (bits) for the current
61 uint64_t content_size;
64 * Current packet's total size (bits) for the current
70 * Discarded events (free running) counter for the
73 uint64_t discarded_events_counter;
75 /* Sequence number (free running) of the current packet */
79 * Offset of the packet context structure within the
80 * current packet (bits).
82 uint64_t context_offset_bits;
85 * Owned by this; `NULL` if the current packet is closed
86 * or if the trace IR stream does not support packets.
88 const bt_packet *packet;
91 /* Previous packet's state */
94 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
97 /* Discarded events (free running) counter */
98 uint64_t discarded_events_counter;
100 /* Sequence number (free running) */
104 /* State to handle discarded events */
108 * True if we're in the time range given by a previously
109 * received discarded events message. In this case,
110 * `beginning_cs` and `end_cs` below contain the
111 * beginning and end clock snapshots for this range.
113 * This is used to validate that, when receiving a
114 * packet end message, the current discarded events time
115 * range matches what's expected for CTF 1.8, that is:
117 * * Its beginning time is the previous packet's end
118 * time (or the current packet's beginning time if
119 * this is the first packet).
121 * * Its end time is the current packet's end time.
126 * Beginning and end times of the time range given by a
127 * previously received discarded events message.
129 uint64_t beginning_cs;
131 } discarded_events_state;
133 /* State to handle discarded packets */
137 * True if we're in the time range given by a previously
138 * received discarded packets message. In this case,
139 * `beginning_cs` and `end_cs` below contain the
140 * beginning and end clock snapshots for this range.
142 * This is used to validate that, when receiving a
143 * packet beginning message, the current discarded
144 * packets time range matches what's expected for CTF
147 * * Its beginning time is the previous packet's end
150 * * Its end time is the current packet's beginning
156 * Beginning and end times of the time range given by a
157 * previously received discarded packets message.
159 uint64_t beginning_cs;
161 } discarded_packets_state;
164 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
165 const bt_stream *ir_stream);
167 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
169 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
170 const bt_event *event, struct fs_sink_ctf_event_class *ec);
172 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
173 const bt_packet *packet);
175 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
177 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */