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