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
14 #include <babeltrace2/babeltrace.h>
16 #include "common/macros.h"
17 #include "ctfser/ctfser.h"
19 #include "fs-sink-ctf-meta.hpp"
25 bt_logging_level log_level;
26 struct fs_sink_trace *trace;
27 struct bt_ctfser ctfser;
29 /* Stream's file name */
33 const bt_stream *ir_stream;
35 struct fs_sink_ctf_stream_class *sc;
37 /* Current packet's state */
41 * True if we're, for this stream, within an opened
42 * packet (got a packet beginning message, but no
43 * packet end message yet).
48 * Current beginning default clock snapshot for the
49 * current packet (`UINT64_C(-1)` if not set).
51 uint64_t beginning_cs;
54 * Current end default clock snapshot for the current
55 * packet (`UINT64_C(-1)` if not set).
60 * Current packet's content size (bits) for the current
63 uint64_t content_size;
66 * Current packet's total size (bits) for the current
72 * Discarded events (free running) counter for the
75 uint64_t discarded_events_counter;
77 /* Sequence number (free running) of the current packet */
81 * Offset of the packet context structure within the
82 * current packet (bits).
84 uint64_t context_offset_bits;
87 * Owned by this; `NULL` if the current packet is closed
88 * or if the trace IR stream does not support packets.
90 const bt_packet *packet;
93 /* Previous packet's state */
96 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
99 /* Discarded events (free running) counter */
100 uint64_t discarded_events_counter;
102 /* Sequence number (free running) */
106 /* State to handle discarded events */
110 * True if we're in the time range given by a previously
111 * received discarded events message. In this case,
112 * `beginning_cs` and `end_cs` below contain the
113 * beginning and end clock snapshots for this range.
115 * This is used to validate that, when receiving a
116 * packet end message, the current discarded events time
117 * range matches what's expected for CTF 1.8, that is:
119 * * Its beginning time is the previous packet's end
120 * time (or the current packet's beginning time if
121 * this is the first packet).
123 * * Its end time is the current packet's end time.
128 * Beginning and end times of the time range given by a
129 * previously received discarded events message.
131 uint64_t beginning_cs;
133 } discarded_events_state;
135 /* State to handle discarded packets */
139 * True if we're in the time range given by a previously
140 * received discarded packets message. In this case,
141 * `beginning_cs` and `end_cs` below contain the
142 * beginning and end clock snapshots for this range.
144 * This is used to validate that, when receiving a
145 * packet beginning message, the current discarded
146 * packets time range matches what's expected for CTF
149 * * Its beginning time is the previous packet's end
152 * * Its end time is the current packet's beginning
158 * Beginning and end times of the time range given by a
159 * previously received discarded packets message.
161 uint64_t beginning_cs;
163 } discarded_packets_state;
166 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
167 const bt_stream *ir_stream);
169 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
171 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
172 const bt_event *event, struct fs_sink_ctf_event_class *ec);
174 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
175 const bt_packet *packet);
177 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
179 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */