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"
19 bt_logging_level log_level;
20 struct fs_sink_trace *trace;
21 struct bt_ctfser ctfser;
23 /* Stream's file name */
27 const bt_stream *ir_stream;
29 struct fs_sink_ctf_stream_class *sc;
31 /* Current packet's state */
35 * True if we're, for this stream, within an opened
36 * packet (got a packet beginning message, but no
37 * packet end message yet).
42 * Current beginning default clock snapshot for the
43 * current packet (`UINT64_C(-1)` if not set).
45 uint64_t beginning_cs;
48 * Current end default clock snapshot for the current
49 * packet (`UINT64_C(-1)` if not set).
54 * Current packet's content size (bits) for the current
57 uint64_t content_size;
60 * Current packet's total size (bits) for the current
66 * Discarded events (free running) counter for the
69 uint64_t discarded_events_counter;
71 /* Sequence number (free running) of the current packet */
75 * Offset of the packet context structure within the
76 * current packet (bits).
78 uint64_t context_offset_bits;
81 * Owned by this; `NULL` if the current packet is closed
82 * or if the trace IR stream does not support packets.
84 const bt_packet *packet;
87 /* Previous packet's state */
90 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
93 /* Discarded events (free running) counter */
94 uint64_t discarded_events_counter;
96 /* Sequence number (free running) */
100 /* State to handle discarded events */
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.
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:
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).
117 * * Its end time is the current packet's end time.
122 * Beginning and end times of the time range given by a
123 * previously received discarded events message.
125 uint64_t beginning_cs;
127 } discarded_events_state;
129 /* State to handle discarded packets */
133 * True if we're in the time range given by a previously
134 * received discarded packets message. In this case,
135 * `beginning_cs` and `end_cs` below contain the
136 * beginning and end clock snapshots for this range.
138 * This is used to validate that, when receiving a
139 * packet beginning message, the current discarded
140 * packets time range matches what's expected for CTF
143 * * Its beginning time is the previous packet's end
146 * * Its end time is the current packet's beginning
152 * Beginning and end times of the time range given by a
153 * previously received discarded packets message.
155 uint64_t beginning_cs;
157 } discarded_packets_state;
160 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
161 const bt_stream *ir_stream);
163 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
165 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
166 const bt_event *event, struct fs_sink_ctf_event_class *ec);
168 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
169 const bt_packet *packet);
171 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
173 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */