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