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 "common/macros.h"
16 #include "ctfser/ctfser.h"
18 #include "fs-sink-ctf-meta.hpp"
24 bt_logging_level log_level;
25 struct fs_sink_trace *trace;
26 struct bt_ctfser ctfser;
28 /* Stream's file name */
32 const bt_stream *ir_stream;
34 struct fs_sink_ctf_stream_class *sc;
36 /* Current packet's state */
40 * True if we're, for this stream, within an opened
41 * packet (got a packet beginning message, but no
42 * packet end message yet).
47 * Current beginning default clock snapshot for the
48 * current packet (`UINT64_C(-1)` if not set).
50 uint64_t beginning_cs;
53 * Current end default clock snapshot for the current
54 * packet (`UINT64_C(-1)` if not set).
59 * Current packet's content size (bits) for the current
62 uint64_t content_size;
65 * Current packet's total size (bits) for the current
71 * Discarded events (free running) counter for the
74 uint64_t discarded_events_counter;
76 /* Sequence number (free running) of the current packet */
80 * Offset of the packet context structure within the
81 * current packet (bits).
83 uint64_t context_offset_bits;
86 * Owned by this; `NULL` if the current packet is closed
87 * or if the trace IR stream does not support packets.
89 const bt_packet *packet;
92 /* Previous packet's state */
95 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
98 /* Discarded events (free running) counter */
99 uint64_t discarded_events_counter;
101 /* Sequence number (free running) */
105 /* State to handle discarded events */
109 * True if we're in the time range given by a previously
110 * received discarded events message. In this case,
111 * `beginning_cs` and `end_cs` below contain the
112 * beginning and end clock snapshots for this range.
114 * This is used to validate that, when receiving a
115 * packet end message, the current discarded events time
116 * range matches what's expected for CTF 1.8, that is:
118 * * Its beginning time is the previous packet's end
119 * time (or the current packet's beginning time if
120 * this is the first packet).
122 * * Its end time is the current packet's end time.
127 * Beginning and end times of the time range given by a
128 * previously received discarded events message.
130 uint64_t beginning_cs;
132 } discarded_events_state;
134 /* State to handle discarded packets */
138 * True if we're in the time range given by a previously
139 * received discarded packets message. In this case,
140 * `beginning_cs` and `end_cs` below contain the
141 * beginning and end clock snapshots for this range.
143 * This is used to validate that, when receiving a
144 * packet beginning message, the current discarded
145 * packets time range matches what's expected for CTF
148 * * Its beginning time is the previous packet's end
151 * * Its end time is the current packet's beginning
157 * Beginning and end times of the time range given by a
158 * previously received discarded packets message.
160 uint64_t beginning_cs;
162 } discarded_packets_state;
165 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
166 const bt_stream *ir_stream);
168 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
170 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
171 const bt_event *event, struct fs_sink_ctf_event_class *ec);
173 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
174 const bt_packet *packet);
176 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
178 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */