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