Commit | Line | Data |
---|---|---|
15fe47e0 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
15fe47e0 | 3 | * |
0235b0db | 4 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> |
15fe47e0 PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H |
8 | #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H | |
9 | ||
91d81473 | 10 | #include "common/macros.h" |
3fadfbc0 | 11 | #include <babeltrace2/babeltrace.h> |
578e048b | 12 | #include "ctfser/ctfser.h" |
15fe47e0 PP |
13 | #include <glib.h> |
14 | #include <stdbool.h> | |
15 | #include <stdint.h> | |
16 | ||
17 | #include "fs-sink-ctf-meta.h" | |
18 | ||
19 | struct fs_sink_trace; | |
20 | ||
21 | struct fs_sink_stream { | |
ffa3b2b3 | 22 | bt_logging_level log_level; |
15fe47e0 PP |
23 | struct fs_sink_trace *trace; |
24 | struct bt_ctfser ctfser; | |
25 | ||
26 | /* Stream's file name */ | |
27 | GString *file_name; | |
28 | ||
29 | /* Weak */ | |
30 | const bt_stream *ir_stream; | |
31 | ||
32 | struct fs_sink_ctf_stream_class *sc; | |
33 | ||
491c35cc | 34 | /* Current packet's state */ |
15fe47e0 | 35 | struct { |
491c35cc PP |
36 | /* |
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). | |
40 | */ | |
15fe47e0 | 41 | bool is_open; |
491c35cc PP |
42 | |
43 | /* | |
44 | * Current beginning default clock snapshot for the | |
45 | * current packet (`UINT64_C(-1)` if not set). | |
46 | */ | |
15fe47e0 | 47 | uint64_t beginning_cs; |
491c35cc PP |
48 | |
49 | /* | |
50 | * Current end default clock snapshot for the current | |
51 | * packet (`UINT64_C(-1)` if not set). | |
52 | */ | |
15fe47e0 | 53 | uint64_t end_cs; |
491c35cc PP |
54 | |
55 | /* | |
56 | * Current packet's content size (bits) for the current | |
57 | * packet. | |
58 | */ | |
15fe47e0 | 59 | uint64_t content_size; |
491c35cc PP |
60 | |
61 | /* | |
62 | * Current packet's total size (bits) for the current | |
63 | * packet. | |
64 | */ | |
15fe47e0 | 65 | uint64_t total_size; |
491c35cc PP |
66 | |
67 | /* | |
68 | * Discarded events (free running) counter for the | |
69 | * current packet. | |
70 | */ | |
15fe47e0 | 71 | uint64_t discarded_events_counter; |
491c35cc PP |
72 | |
73 | /* Sequence number (free running) of the current packet */ | |
15fe47e0 | 74 | uint64_t seq_num; |
491c35cc PP |
75 | |
76 | /* | |
77 | * Offset of the packet context structure within the | |
78 | * current packet (bits). | |
79 | */ | |
15fe47e0 PP |
80 | uint64_t context_offset_bits; |
81 | ||
26fc5aed PP |
82 | /* |
83 | * Owned by this; `NULL` if the current packet is closed | |
84 | * or if the trace IR stream does not support packets. | |
85 | */ | |
15fe47e0 PP |
86 | const bt_packet *packet; |
87 | } packet_state; | |
88 | ||
491c35cc | 89 | /* Previous packet's state */ |
15fe47e0 | 90 | struct { |
491c35cc | 91 | /* End default clock snapshot (`UINT64_C(-1)` if not set) */ |
15fe47e0 | 92 | uint64_t end_cs; |
491c35cc PP |
93 | |
94 | /* Discarded events (free running) counter */ | |
15fe47e0 | 95 | uint64_t discarded_events_counter; |
491c35cc PP |
96 | |
97 | /* Sequence number (free running) */ | |
15fe47e0 PP |
98 | uint64_t seq_num; |
99 | } prev_packet_state; | |
100 | ||
491c35cc | 101 | /* State to handle discarded events */ |
15fe47e0 | 102 | struct { |
491c35cc PP |
103 | /* |
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. | |
108 | * | |
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: | |
112 | * | |
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). | |
116 | * | |
117 | * * Its end time is the current packet's end time. | |
118 | */ | |
15fe47e0 | 119 | bool in_range; |
491c35cc PP |
120 | |
121 | /* | |
122 | * Beginning and end times of the time range given by a | |
123 | * previously received discarded events message. | |
124 | */ | |
15fe47e0 PP |
125 | uint64_t beginning_cs; |
126 | uint64_t end_cs; | |
127 | } discarded_events_state; | |
128 | ||
491c35cc | 129 | /* State to handle discarded packets */ |
15fe47e0 | 130 | struct { |
491c35cc PP |
131 | /* |
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. | |
136 | * | |
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 | |
140 | * 1.8, that is: | |
141 | * | |
142 | * * Its beginning time is the previous packet's end | |
143 | * time. | |
144 | * | |
145 | * * Its end time is the current packet's beginning | |
146 | * time. | |
147 | */ | |
15fe47e0 | 148 | bool in_range; |
491c35cc PP |
149 | |
150 | /* | |
151 | * Beginning and end times of the time range given by a | |
152 | * previously received discarded packets message. | |
153 | */ | |
15fe47e0 PP |
154 | uint64_t beginning_cs; |
155 | uint64_t end_cs; | |
156 | } discarded_packets_state; | |
15fe47e0 PP |
157 | }; |
158 | ||
159 | BT_HIDDEN | |
160 | struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace, | |
161 | const bt_stream *ir_stream); | |
162 | ||
163 | BT_HIDDEN | |
164 | void fs_sink_stream_destroy(struct fs_sink_stream *stream); | |
165 | ||
166 | BT_HIDDEN | |
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); | |
170 | ||
171 | BT_HIDDEN | |
172 | int fs_sink_stream_open_packet(struct fs_sink_stream *stream, | |
173 | const bt_clock_snapshot *cs, const bt_packet *packet); | |
174 | ||
175 | BT_HIDDEN | |
176 | int fs_sink_stream_close_packet(struct fs_sink_stream *stream, | |
177 | const bt_clock_snapshot *cs); | |
178 | ||
179 | #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */ |