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.h"
21 struct fs_sink_stream
{
22 bt_logging_level log_level
;
23 struct fs_sink_trace
*trace
;
24 struct bt_ctfser ctfser
;
26 /* Stream's file name */
30 const bt_stream
*ir_stream
;
32 struct fs_sink_ctf_stream_class
*sc
;
34 /* Current packet's state */
37 * True if we're, for this stream, within an opened
38 * packet (got a packet beginning message, but no
39 * packet end message yet).
44 * Current beginning default clock snapshot for the
45 * current packet (`UINT64_C(-1)` if not set).
47 uint64_t beginning_cs
;
50 * Current end default clock snapshot for the current
51 * packet (`UINT64_C(-1)` if not set).
56 * Current packet's content size (bits) for the current
59 uint64_t content_size
;
62 * Current packet's total size (bits) for the current
68 * Discarded events (free running) counter for the
71 uint64_t discarded_events_counter
;
73 /* Sequence number (free running) of the current packet */
77 * Offset of the packet context structure within the
78 * current packet (bits).
80 uint64_t context_offset_bits
;
83 * Owned by this; `NULL` if the current packet is closed
84 * or if the trace IR stream does not support packets.
86 const bt_packet
*packet
;
89 /* Previous packet's state */
91 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
94 /* Discarded events (free running) counter */
95 uint64_t discarded_events_counter
;
97 /* Sequence number (free running) */
101 /* 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 */
132 * True if we're in the time range given by a previously
133 * received discarded packets message. In this case,
134 * `beginning_cs` and `end_cs` below contain the
135 * beginning and end clock snapshots for this range.
137 * This is used to validate that, when receiving a
138 * packet beginning message, the current discarded
139 * packets time range matches what's expected for CTF
142 * * Its beginning time is the previous packet's end
145 * * Its end time is the current packet's beginning
151 * Beginning and end times of the time range given by a
152 * previously received discarded packets message.
154 uint64_t beginning_cs
;
156 } discarded_packets_state
;
160 struct fs_sink_stream
*fs_sink_stream_create(struct fs_sink_trace
*trace
,
161 const bt_stream
*ir_stream
);
164 void fs_sink_stream_destroy(struct fs_sink_stream
*stream
);
167 int fs_sink_stream_write_event(struct fs_sink_stream
*stream
,
168 const bt_clock_snapshot
*cs
, const bt_event
*event
,
169 struct fs_sink_ctf_event_class
*ec
);
172 int fs_sink_stream_open_packet(struct fs_sink_stream
*stream
,
173 const bt_clock_snapshot
*cs
, const bt_packet
*packet
);
176 int fs_sink_stream_close_packet(struct fs_sink_stream
*stream
,
177 const bt_clock_snapshot
*cs
);
179 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */