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