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 | ||
ae2be88d SM |
7 | #ifndef BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP |
8 | #define BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP | |
0235b0db | 9 | |
15fe47e0 | 10 | #include <glib.h> |
15fe47e0 PP |
11 | #include <stdint.h> |
12 | ||
c802cacb SM |
13 | #include <babeltrace2/babeltrace.h> |
14 | ||
3c20ac12 | 15 | #include "cpp-common/bt2c/logging.hpp" |
c802cacb SM |
16 | #include "ctfser/ctfser.h" |
17 | ||
150640e8 SM |
18 | struct fs_sink_trace; |
19 | struct fs_sink_ctf_stream_class; | |
20 | ||
4164020e SM |
21 | struct fs_sink_stream |
22 | { | |
3c20ac12 SM |
23 | explicit fs_sink_stream(const bt2c::Logger& parentLogger) : |
24 | logger {parentLogger, "PLUGIN/SINK.CTF.FS/STREAM"} | |
25 | { | |
26 | } | |
27 | ||
28 | bt2c::Logger logger; | |
150640e8 SM |
29 | fs_sink_trace *trace = nullptr; |
30 | bt_ctfser ctfser {}; | |
4164020e SM |
31 | |
32 | /* Stream's file name */ | |
150640e8 | 33 | GString *file_name = nullptr; |
4164020e SM |
34 | |
35 | /* Weak */ | |
150640e8 | 36 | const bt_stream *ir_stream = nullptr; |
4164020e | 37 | |
150640e8 | 38 | fs_sink_ctf_stream_class *sc = nullptr; |
4164020e SM |
39 | |
40 | /* Current packet's state */ | |
41 | struct | |
42 | { | |
43 | /* | |
44 | * True if we're, for this stream, within an opened | |
45 | * packet (got a packet beginning message, but no | |
46 | * packet end message yet). | |
47 | */ | |
150640e8 | 48 | bool is_open = false; |
4164020e SM |
49 | |
50 | /* | |
51 | * Current beginning default clock snapshot for the | |
52 | * current packet (`UINT64_C(-1)` if not set). | |
53 | */ | |
150640e8 | 54 | uint64_t beginning_cs = 0; |
4164020e SM |
55 | |
56 | /* | |
57 | * Current end default clock snapshot for the current | |
58 | * packet (`UINT64_C(-1)` if not set). | |
59 | */ | |
150640e8 | 60 | uint64_t end_cs = 0; |
4164020e SM |
61 | |
62 | /* | |
63 | * Current packet's content size (bits) for the current | |
64 | * packet. | |
65 | */ | |
150640e8 | 66 | uint64_t content_size = 0; |
4164020e SM |
67 | |
68 | /* | |
69 | * Current packet's total size (bits) for the current | |
70 | * packet. | |
71 | */ | |
150640e8 | 72 | uint64_t total_size = 0; |
4164020e SM |
73 | |
74 | /* | |
75 | * Discarded events (free running) counter for the | |
76 | * current packet. | |
77 | */ | |
150640e8 | 78 | uint64_t discarded_events_counter = 0; |
4164020e SM |
79 | |
80 | /* Sequence number (free running) of the current packet */ | |
150640e8 | 81 | uint64_t seq_num = 0; |
4164020e SM |
82 | |
83 | /* | |
84 | * Offset of the packet context structure within the | |
85 | * current packet (bits). | |
86 | */ | |
150640e8 | 87 | uint64_t context_offset_bits = 0; |
4164020e SM |
88 | |
89 | /* | |
90 | * Owned by this; `NULL` if the current packet is closed | |
91 | * or if the trace IR stream does not support packets. | |
92 | */ | |
150640e8 | 93 | const bt_packet *packet = nullptr; |
4164020e SM |
94 | } packet_state; |
95 | ||
96 | /* Previous packet's state */ | |
97 | struct | |
98 | { | |
99 | /* End default clock snapshot (`UINT64_C(-1)` if not set) */ | |
150640e8 | 100 | uint64_t end_cs = 0; |
4164020e SM |
101 | |
102 | /* Discarded events (free running) counter */ | |
150640e8 | 103 | uint64_t discarded_events_counter = 0; |
4164020e SM |
104 | |
105 | /* Sequence number (free running) */ | |
150640e8 | 106 | uint64_t seq_num = 0; |
4164020e SM |
107 | } prev_packet_state; |
108 | ||
109 | /* State to handle discarded events */ | |
110 | struct | |
111 | { | |
112 | /* | |
113 | * True if we're in the time range given by a previously | |
114 | * received discarded events message. In this case, | |
115 | * `beginning_cs` and `end_cs` below contain the | |
116 | * beginning and end clock snapshots for this range. | |
117 | * | |
118 | * This is used to validate that, when receiving a | |
119 | * packet end message, the current discarded events time | |
120 | * range matches what's expected for CTF 1.8, that is: | |
121 | * | |
122 | * * Its beginning time is the previous packet's end | |
123 | * time (or the current packet's beginning time if | |
124 | * this is the first packet). | |
125 | * | |
126 | * * Its end time is the current packet's end time. | |
127 | */ | |
150640e8 | 128 | bool in_range = false; |
4164020e SM |
129 | |
130 | /* | |
131 | * Beginning and end times of the time range given by a | |
132 | * previously received discarded events message. | |
133 | */ | |
150640e8 SM |
134 | uint64_t beginning_cs = 0; |
135 | uint64_t end_cs = 0; | |
4164020e SM |
136 | } discarded_events_state; |
137 | ||
138 | /* State to handle discarded packets */ | |
139 | struct | |
140 | { | |
141 | /* | |
142 | * True if we're in the time range given by a previously | |
143 | * received discarded packets message. In this case, | |
144 | * `beginning_cs` and `end_cs` below contain the | |
145 | * beginning and end clock snapshots for this range. | |
146 | * | |
147 | * This is used to validate that, when receiving a | |
148 | * packet beginning message, the current discarded | |
149 | * packets time range matches what's expected for CTF | |
150 | * 1.8, that is: | |
151 | * | |
152 | * * Its beginning time is the previous packet's end | |
153 | * time. | |
154 | * | |
155 | * * Its end time is the current packet's beginning | |
156 | * time. | |
157 | */ | |
150640e8 | 158 | bool in_range = false; |
4164020e SM |
159 | |
160 | /* | |
161 | * Beginning and end times of the time range given by a | |
162 | * previously received discarded packets message. | |
163 | */ | |
150640e8 SM |
164 | uint64_t beginning_cs = 0; |
165 | uint64_t end_cs = 0; | |
4164020e | 166 | } discarded_packets_state; |
15fe47e0 PP |
167 | }; |
168 | ||
15fe47e0 | 169 | struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace, |
4164020e | 170 | const bt_stream *ir_stream); |
15fe47e0 | 171 | |
15fe47e0 PP |
172 | void fs_sink_stream_destroy(struct fs_sink_stream *stream); |
173 | ||
4164020e SM |
174 | int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs, |
175 | const bt_event *event, struct fs_sink_ctf_event_class *ec); | |
15fe47e0 | 176 | |
4164020e SM |
177 | int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs, |
178 | const bt_packet *packet); | |
15fe47e0 | 179 | |
4164020e | 180 | int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs); |
15fe47e0 | 181 | |
ae2be88d | 182 | #endif /* BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_STREAM_HPP */ |