Commit | Line | Data |
---|---|---|
15fe47e0 PP |
1 | #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H |
2 | #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H | |
3 | ||
4 | /* | |
5 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
91d81473 | 26 | #include "common/macros.h" |
3fadfbc0 | 27 | #include <babeltrace2/babeltrace.h> |
578e048b | 28 | #include "ctfser/ctfser.h" |
15fe47e0 PP |
29 | #include <glib.h> |
30 | #include <stdbool.h> | |
31 | #include <stdint.h> | |
32 | ||
33 | #include "fs-sink-ctf-meta.h" | |
34 | ||
35 | struct fs_sink_trace; | |
36 | ||
37 | struct fs_sink_stream { | |
ffa3b2b3 | 38 | bt_logging_level log_level; |
15fe47e0 PP |
39 | struct fs_sink_trace *trace; |
40 | struct bt_ctfser ctfser; | |
41 | ||
42 | /* Stream's file name */ | |
43 | GString *file_name; | |
44 | ||
45 | /* Weak */ | |
46 | const bt_stream *ir_stream; | |
47 | ||
48 | struct fs_sink_ctf_stream_class *sc; | |
49 | ||
491c35cc | 50 | /* Current packet's state */ |
15fe47e0 | 51 | struct { |
491c35cc PP |
52 | /* |
53 | * True if we're, for this stream, within an opened | |
54 | * packet (got a packet beginning message, but no | |
55 | * packet end message yet). | |
56 | */ | |
15fe47e0 | 57 | bool is_open; |
491c35cc PP |
58 | |
59 | /* | |
60 | * Current beginning default clock snapshot for the | |
61 | * current packet (`UINT64_C(-1)` if not set). | |
62 | */ | |
15fe47e0 | 63 | uint64_t beginning_cs; |
491c35cc PP |
64 | |
65 | /* | |
66 | * Current end default clock snapshot for the current | |
67 | * packet (`UINT64_C(-1)` if not set). | |
68 | */ | |
15fe47e0 | 69 | uint64_t end_cs; |
491c35cc PP |
70 | |
71 | /* | |
72 | * Current packet's content size (bits) for the current | |
73 | * packet. | |
74 | */ | |
15fe47e0 | 75 | uint64_t content_size; |
491c35cc PP |
76 | |
77 | /* | |
78 | * Current packet's total size (bits) for the current | |
79 | * packet. | |
80 | */ | |
15fe47e0 | 81 | uint64_t total_size; |
491c35cc PP |
82 | |
83 | /* | |
84 | * Discarded events (free running) counter for the | |
85 | * current packet. | |
86 | */ | |
15fe47e0 | 87 | uint64_t discarded_events_counter; |
491c35cc PP |
88 | |
89 | /* Sequence number (free running) of the current packet */ | |
15fe47e0 | 90 | uint64_t seq_num; |
491c35cc PP |
91 | |
92 | /* | |
93 | * Offset of the packet context structure within the | |
94 | * current packet (bits). | |
95 | */ | |
15fe47e0 PP |
96 | uint64_t context_offset_bits; |
97 | ||
26fc5aed PP |
98 | /* |
99 | * Owned by this; `NULL` if the current packet is closed | |
100 | * or if the trace IR stream does not support packets. | |
101 | */ | |
15fe47e0 PP |
102 | const bt_packet *packet; |
103 | } packet_state; | |
104 | ||
491c35cc | 105 | /* Previous packet's state */ |
15fe47e0 | 106 | struct { |
491c35cc | 107 | /* End default clock snapshot (`UINT64_C(-1)` if not set) */ |
15fe47e0 | 108 | uint64_t end_cs; |
491c35cc PP |
109 | |
110 | /* Discarded events (free running) counter */ | |
15fe47e0 | 111 | uint64_t discarded_events_counter; |
491c35cc PP |
112 | |
113 | /* Sequence number (free running) */ | |
15fe47e0 PP |
114 | uint64_t seq_num; |
115 | } prev_packet_state; | |
116 | ||
491c35cc | 117 | /* State to handle discarded events */ |
15fe47e0 | 118 | struct { |
491c35cc PP |
119 | /* |
120 | * True if we're in the time range given by a previously | |
121 | * received discarded events message. In this case, | |
122 | * `beginning_cs` and `end_cs` below contain the | |
123 | * beginning and end clock snapshots for this range. | |
124 | * | |
125 | * This is used to validate that, when receiving a | |
126 | * packet end message, the current discarded events time | |
127 | * range matches what's expected for CTF 1.8, that is: | |
128 | * | |
129 | * * Its beginning time is the previous packet's end | |
130 | * time (or the current packet's beginning time if | |
131 | * this is the first packet). | |
132 | * | |
133 | * * Its end time is the current packet's end time. | |
134 | */ | |
15fe47e0 | 135 | bool in_range; |
491c35cc PP |
136 | |
137 | /* | |
138 | * Beginning and end times of the time range given by a | |
139 | * previously received discarded events message. | |
140 | */ | |
15fe47e0 PP |
141 | uint64_t beginning_cs; |
142 | uint64_t end_cs; | |
143 | } discarded_events_state; | |
144 | ||
491c35cc | 145 | /* State to handle discarded packets */ |
15fe47e0 | 146 | struct { |
491c35cc PP |
147 | /* |
148 | * True if we're in the time range given by a previously | |
149 | * received discarded packets message. In this case, | |
150 | * `beginning_cs` and `end_cs` below contain the | |
151 | * beginning and end clock snapshots for this range. | |
152 | * | |
153 | * This is used to validate that, when receiving a | |
154 | * packet beginning message, the current discarded | |
155 | * packets time range matches what's expected for CTF | |
156 | * 1.8, that is: | |
157 | * | |
158 | * * Its beginning time is the previous packet's end | |
159 | * time. | |
160 | * | |
161 | * * Its end time is the current packet's beginning | |
162 | * time. | |
163 | */ | |
15fe47e0 | 164 | bool in_range; |
491c35cc PP |
165 | |
166 | /* | |
167 | * Beginning and end times of the time range given by a | |
168 | * previously received discarded packets message. | |
169 | */ | |
15fe47e0 PP |
170 | uint64_t beginning_cs; |
171 | uint64_t end_cs; | |
172 | } discarded_packets_state; | |
15fe47e0 PP |
173 | }; |
174 | ||
175 | BT_HIDDEN | |
176 | struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace, | |
177 | const bt_stream *ir_stream); | |
178 | ||
179 | BT_HIDDEN | |
180 | void fs_sink_stream_destroy(struct fs_sink_stream *stream); | |
181 | ||
182 | BT_HIDDEN | |
183 | int fs_sink_stream_write_event(struct fs_sink_stream *stream, | |
184 | const bt_clock_snapshot *cs, const bt_event *event, | |
185 | struct fs_sink_ctf_event_class *ec); | |
186 | ||
187 | BT_HIDDEN | |
188 | int fs_sink_stream_open_packet(struct fs_sink_stream *stream, | |
189 | const bt_clock_snapshot *cs, const bt_packet *packet); | |
190 | ||
191 | BT_HIDDEN | |
192 | int fs_sink_stream_close_packet(struct fs_sink_stream *stream, | |
193 | const bt_clock_snapshot *cs); | |
194 | ||
195 | #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */ |