Commit | Line | Data |
---|---|---|
f79cf0f0 | 1 | /* |
f79cf0f0 PP |
2 | * Copyright 2016 Philippe Proulx <pproulx@efficios.com> |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
8ea705f0 | 23 | #define BT_LOG_TAG "PACKET" |
be514b0c | 24 | #include <babeltrace/lib-logging-internal.h> |
8ea705f0 | 25 | |
8deee039 | 26 | #include <babeltrace/assert-pre-internal.h> |
108b91d0 | 27 | #include <babeltrace/trace-ir/fields-internal.h> |
78cf9df6 | 28 | #include <babeltrace/trace-ir/packet-const.h> |
108b91d0 PP |
29 | #include <babeltrace/trace-ir/packet.h> |
30 | #include <babeltrace/trace-ir/packet-internal.h> | |
31 | #include <babeltrace/trace-ir/field-wrapper-internal.h> | |
32 | #include <babeltrace/trace-ir/trace.h> | |
33 | #include <babeltrace/trace-ir/stream-class-internal.h> | |
34 | #include <babeltrace/trace-ir/stream-class.h> | |
35 | #include <babeltrace/trace-ir/stream.h> | |
36 | #include <babeltrace/trace-ir/stream-internal.h> | |
37 | #include <babeltrace/trace-ir/clock-value-internal.h> | |
38 | #include <babeltrace/trace-ir/trace-internal.h> | |
f79cf0f0 | 39 | #include <babeltrace/object-internal.h> |
8138bfe1 | 40 | #include <babeltrace/object.h> |
8b45963b | 41 | #include <babeltrace/assert-internal.h> |
be514b0c | 42 | #include <inttypes.h> |
f79cf0f0 | 43 | |
7b33a0e0 PP |
44 | #define BT_ASSERT_PRE_PACKET_HOT(_packet) \ |
45 | BT_ASSERT_PRE_HOT((_packet), "Packet", ": %!+a", (_packet)) | |
46 | ||
5fe68922 | 47 | struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet) |
f79cf0f0 | 48 | { |
8b45963b | 49 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
5fe68922 | 50 | return packet->stream; |
f79cf0f0 PP |
51 | } |
52 | ||
78cf9df6 PP |
53 | const struct bt_stream *bt_packet_borrow_stream_const( |
54 | const struct bt_packet *packet) | |
9e550e5f | 55 | { |
78cf9df6 | 56 | return bt_packet_borrow_stream((void *) packet); |
9e550e5f PP |
57 | } |
58 | ||
7b33a0e0 | 59 | struct bt_field *bt_packet_borrow_header_field(struct bt_packet *packet) |
f79cf0f0 | 60 | { |
8b45963b | 61 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 | 62 | return packet->header_field ? packet->header_field->field : NULL; |
f79cf0f0 PP |
63 | } |
64 | ||
78cf9df6 PP |
65 | const struct bt_field *bt_packet_borrow_header_field_const( |
66 | const struct bt_packet *packet) | |
9e550e5f | 67 | { |
78cf9df6 | 68 | return bt_packet_borrow_header_field((void *) packet); |
9e550e5f PP |
69 | } |
70 | ||
7b33a0e0 | 71 | struct bt_field *bt_packet_borrow_context_field(struct bt_packet *packet) |
f79cf0f0 | 72 | { |
a6918753 | 73 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 | 74 | return packet->context_field ? packet->context_field->field : NULL; |
a6918753 | 75 | } |
c5c82c6e | 76 | |
78cf9df6 PP |
77 | const struct bt_field *bt_packet_borrow_context_field_const( |
78 | const struct bt_packet *packet) | |
9e550e5f | 79 | { |
78cf9df6 | 80 | return bt_packet_borrow_context_field((void *) packet); |
9e550e5f PP |
81 | } |
82 | ||
a6918753 | 83 | BT_HIDDEN |
78cf9df6 | 84 | void _bt_packet_set_is_frozen(const struct bt_packet *packet, bool is_frozen) |
a6918753 | 85 | { |
435ec8af | 86 | if (!packet) { |
a6918753 | 87 | return; |
c5c82c6e PP |
88 | } |
89 | ||
7b33a0e0 PP |
90 | BT_LIB_LOGD("Setting packet's frozen state: %![packet-]+a, " |
91 | "is-frozen=%d", packet, is_frozen); | |
a6918753 | 92 | |
7b33a0e0 PP |
93 | if (packet->header_field) { |
94 | BT_LOGD_STR("Setting packet's header field's frozen state."); | |
95 | bt_field_set_is_frozen(packet->header_field->field, | |
c5a24b0a | 96 | is_frozen); |
f79cf0f0 PP |
97 | } |
98 | ||
7b33a0e0 PP |
99 | if (packet->context_field) { |
100 | BT_LOGD_STR("Setting packet's context field's frozen state."); | |
101 | bt_field_set_is_frozen(packet->context_field->field, | |
c5a24b0a | 102 | is_frozen); |
a6918753 PP |
103 | } |
104 | ||
78cf9df6 | 105 | ((struct bt_packet *) packet)->frozen = is_frozen; |
8b45963b PP |
106 | } |
107 | ||
e5815ba2 | 108 | static inline |
7b33a0e0 | 109 | void reset_counter_snapshots(struct bt_packet *packet) |
e5815ba2 | 110 | { |
7b33a0e0 PP |
111 | packet->discarded_event_counter_snapshot.base.avail = |
112 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; | |
113 | packet->packet_counter_snapshot.base.avail = | |
114 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; | |
e5815ba2 PP |
115 | } |
116 | ||
a6918753 | 117 | static inline |
7b33a0e0 | 118 | void reset_packet(struct bt_packet *packet) |
8b45963b | 119 | { |
a6918753 | 120 | BT_ASSERT(packet); |
7b33a0e0 | 121 | BT_LIB_LOGD("Resetting packet: %!+a", packet); |
c5a24b0a | 122 | bt_packet_set_is_frozen(packet, false); |
a6918753 | 123 | |
7b33a0e0 PP |
124 | if (packet->header_field) { |
125 | bt_field_set_is_frozen(packet->header_field->field, false); | |
126 | bt_field_reset(packet->header_field->field); | |
a6918753 PP |
127 | } |
128 | ||
7b33a0e0 PP |
129 | if (packet->context_field) { |
130 | bt_field_set_is_frozen(packet->context_field->field, false); | |
131 | bt_field_reset(packet->context_field->field); | |
a6918753 | 132 | } |
8fc063a2 | 133 | |
7b33a0e0 PP |
134 | if (packet->default_beginning_cv) { |
135 | bt_clock_value_reset(packet->default_beginning_cv); | |
136 | } | |
e5815ba2 | 137 | |
7b33a0e0 PP |
138 | if (packet->default_end_cv) { |
139 | bt_clock_value_reset(packet->default_end_cv); | |
e5815ba2 | 140 | } |
7b33a0e0 PP |
141 | |
142 | reset_counter_snapshots(packet); | |
f79cf0f0 PP |
143 | } |
144 | ||
a6918753 | 145 | static |
7b33a0e0 | 146 | void recycle_header_field(struct bt_field_wrapper *header_field, |
10b7a2e4 | 147 | struct bt_trace_class *tc) |
f79cf0f0 | 148 | { |
a6918753 PP |
149 | BT_ASSERT(header_field); |
150 | BT_LIB_LOGD("Recycling packet header field: " | |
10b7a2e4 PP |
151 | "addr=%p, %![tc-]+T, %![field-]+f", header_field, |
152 | tc, header_field->field); | |
153 | bt_object_pool_recycle_object(&tc->packet_header_field_pool, | |
a6918753 | 154 | header_field); |
f79cf0f0 PP |
155 | } |
156 | ||
a6918753 | 157 | static |
7b33a0e0 | 158 | void recycle_context_field(struct bt_field_wrapper *context_field, |
a6918753 | 159 | struct bt_stream_class *stream_class) |
f79cf0f0 | 160 | { |
a6918753 PP |
161 | BT_ASSERT(context_field); |
162 | BT_LIB_LOGD("Recycling packet context field: " | |
163 | "addr=%p, %![sc-]+S, %![field-]+f", context_field, | |
164 | stream_class, context_field->field); | |
165 | bt_object_pool_recycle_object(&stream_class->packet_context_field_pool, | |
166 | context_field); | |
f79cf0f0 PP |
167 | } |
168 | ||
169 | BT_HIDDEN | |
a6918753 | 170 | void bt_packet_recycle(struct bt_packet *packet) |
f79cf0f0 | 171 | { |
a6918753 | 172 | struct bt_stream *stream; |
f79cf0f0 | 173 | |
a6918753 PP |
174 | BT_ASSERT(packet); |
175 | BT_LIB_LOGD("Recycling packet: %!+a", packet); | |
176 | ||
177 | /* | |
178 | * Those are the important ordered steps: | |
179 | * | |
180 | * 1. Reset the packet object (put any permanent reference it | |
181 | * has, unfreeze it and its fields in developer mode, etc.), | |
182 | * but do NOT put its stream's reference. This stream | |
183 | * contains the pool to which we're about to recycle this | |
184 | * packet object, so we must guarantee its existence thanks | |
185 | * to this existing reference. | |
186 | * | |
187 | * 2. Move the stream reference to our `stream` | |
188 | * variable so that we can set the packet's stream member | |
189 | * to NULL before recycling it. We CANNOT do this after | |
8138bfe1 | 190 | * we put the stream reference because this bt_object_put_ref() |
a6918753 PP |
191 | * could destroy the stream, also destroying its |
192 | * packet pool, thus also destroying our packet object (this | |
193 | * would result in an invalid write access). | |
194 | * | |
195 | * 3. Recycle the packet object. | |
196 | * | |
197 | * 4. Put our stream reference. | |
198 | */ | |
7b33a0e0 | 199 | reset_packet(packet); |
a6918753 PP |
200 | stream = packet->stream; |
201 | BT_ASSERT(stream); | |
202 | packet->stream = NULL; | |
203 | bt_object_pool_recycle_object(&stream->packet_pool, packet); | |
18acc6f8 | 204 | bt_object_put_no_null_check(&stream->base); |
f79cf0f0 PP |
205 | } |
206 | ||
a6918753 PP |
207 | BT_HIDDEN |
208 | void bt_packet_destroy(struct bt_packet *packet) | |
f79cf0f0 | 209 | { |
7b33a0e0 | 210 | BT_LIB_LOGD("Destroying packet: %!+a", packet); |
a6918753 | 211 | |
7b33a0e0 | 212 | if (packet->header_field) { |
a6918753 PP |
213 | if (packet->stream) { |
214 | BT_LOGD_STR("Recycling packet's header field."); | |
7b33a0e0 | 215 | recycle_header_field(packet->header_field, |
10b7a2e4 | 216 | bt_stream_class_borrow_trace_class_inline( |
7b33a0e0 | 217 | packet->stream->class)); |
a6918753 | 218 | } else { |
7b33a0e0 | 219 | bt_field_wrapper_destroy(packet->header_field); |
a6918753 | 220 | } |
1248f5ea PP |
221 | |
222 | packet->header_field = NULL; | |
a6918753 PP |
223 | } |
224 | ||
7b33a0e0 | 225 | if (packet->context_field) { |
a6918753 PP |
226 | if (packet->stream) { |
227 | BT_LOGD_STR("Recycling packet's context field."); | |
7b33a0e0 PP |
228 | recycle_context_field(packet->context_field, |
229 | packet->stream->class); | |
a6918753 | 230 | } else { |
7b33a0e0 | 231 | bt_field_wrapper_destroy(packet->context_field); |
a6918753 | 232 | } |
1248f5ea PP |
233 | |
234 | packet->context_field = NULL; | |
a6918753 PP |
235 | } |
236 | ||
7b33a0e0 PP |
237 | if (packet->default_beginning_cv) { |
238 | BT_LOGD_STR("Recycling beginning clock value."); | |
239 | bt_clock_value_recycle(packet->default_beginning_cv); | |
1248f5ea | 240 | packet->default_beginning_cv = NULL; |
7b33a0e0 PP |
241 | } |
242 | ||
243 | if (packet->default_end_cv) { | |
244 | BT_LOGD_STR("Recycling end clock value."); | |
245 | bt_clock_value_recycle(packet->default_end_cv); | |
1248f5ea | 246 | packet->default_end_cv = NULL; |
7b33a0e0 PP |
247 | } |
248 | ||
d409daba | 249 | BT_LOGD_STR("Putting packet's stream."); |
1248f5ea | 250 | BT_OBJECT_PUT_REF_AND_RESET(packet->stream); |
f79cf0f0 PP |
251 | g_free(packet); |
252 | } | |
253 | ||
a6918753 PP |
254 | BT_HIDDEN |
255 | struct bt_packet *bt_packet_new(struct bt_stream *stream) | |
f79cf0f0 | 256 | { |
839d52a5 | 257 | struct bt_packet *packet = NULL; |
10b7a2e4 | 258 | struct bt_trace_class *trace_class = NULL; |
f79cf0f0 | 259 | |
a6918753 | 260 | BT_ASSERT(stream); |
7b33a0e0 | 261 | BT_LIB_LOGD("Creating packet object: %![stream-]+s", stream); |
839d52a5 | 262 | packet = g_new0(struct bt_packet, 1); |
f79cf0f0 | 263 | if (!packet) { |
8ea705f0 | 264 | BT_LOGE_STR("Failed to allocate one packet object."); |
7b33a0e0 | 265 | goto error; |
f79cf0f0 PP |
266 | } |
267 | ||
1d7bf349 PP |
268 | bt_object_init_shared(&packet->base, |
269 | (bt_object_release_func) bt_packet_recycle); | |
4b70020d PP |
270 | packet->stream = stream; |
271 | bt_object_get_no_null_check(stream); | |
10b7a2e4 PP |
272 | trace_class = bt_stream_class_borrow_trace_class_inline(stream->class); |
273 | BT_ASSERT(trace_class); | |
be514b0c | 274 | |
10b7a2e4 | 275 | if (trace_class->packet_header_fc) { |
7b33a0e0 PP |
276 | BT_LOGD_STR("Creating initial packet header field."); |
277 | packet->header_field = bt_field_wrapper_create( | |
10b7a2e4 PP |
278 | &trace_class->packet_header_field_pool, |
279 | trace_class->packet_header_fc); | |
7b33a0e0 PP |
280 | if (!packet->header_field) { |
281 | BT_LOGE_STR("Cannot create packet header field wrapper."); | |
282 | goto error; | |
be514b0c | 283 | } |
f79cf0f0 PP |
284 | } |
285 | ||
939190b3 | 286 | if (stream->class->packet_context_fc) { |
7b33a0e0 PP |
287 | BT_LOGD_STR("Creating initial packet context field."); |
288 | packet->context_field = bt_field_wrapper_create( | |
289 | &stream->class->packet_context_field_pool, | |
939190b3 | 290 | stream->class->packet_context_fc); |
7b33a0e0 PP |
291 | if (!packet->context_field) { |
292 | BT_LOGE_STR("Cannot create packet context field wrapper."); | |
293 | goto error; | |
be514b0c | 294 | } |
f79cf0f0 PP |
295 | } |
296 | ||
7b33a0e0 PP |
297 | if (stream->class->default_clock_class) { |
298 | if (stream->class->packets_have_default_beginning_cv) { | |
299 | packet->default_beginning_cv = bt_clock_value_create( | |
300 | stream->class->default_clock_class); | |
301 | if (!packet->default_beginning_cv) { | |
302 | /* bt_clock_value_create() logs errors */ | |
303 | goto error; | |
304 | } | |
e5815ba2 PP |
305 | } |
306 | ||
7b33a0e0 PP |
307 | if (stream->class->packets_have_default_end_cv) { |
308 | packet->default_end_cv = bt_clock_value_create( | |
309 | stream->class->default_clock_class); | |
310 | if (!packet->default_end_cv) { | |
311 | /* bt_clock_value_create() logs errors */ | |
312 | goto error; | |
313 | } | |
e5815ba2 PP |
314 | } |
315 | } | |
316 | ||
7b33a0e0 PP |
317 | reset_counter_snapshots(packet); |
318 | BT_LIB_LOGD("Created packet object: %!+a", packet); | |
319 | goto end; | |
e5815ba2 | 320 | |
7b33a0e0 | 321 | error: |
8138bfe1 | 322 | BT_OBJECT_PUT_REF_AND_RESET(packet); |
e5815ba2 PP |
323 | |
324 | end: | |
7b33a0e0 | 325 | return packet; |
e5815ba2 PP |
326 | } |
327 | ||
78cf9df6 | 328 | struct bt_packet *bt_packet_create(struct bt_stream *stream) |
a6918753 PP |
329 | { |
330 | struct bt_packet *packet = NULL; | |
331 | ||
332 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); | |
333 | packet = bt_object_pool_create_object(&stream->packet_pool); | |
c5a24b0a | 334 | if (unlikely(!packet)) { |
a6918753 PP |
335 | BT_LIB_LOGE("Cannot allocate one packet from stream's packet pool: " |
336 | "%![stream-]+s", stream); | |
c5a24b0a | 337 | goto end; |
a6918753 PP |
338 | } |
339 | ||
7b33a0e0 | 340 | if (likely(!packet->stream)) { |
c5a24b0a PP |
341 | packet->stream = stream; |
342 | bt_object_get_no_null_check_no_parent_check( | |
18acc6f8 | 343 | &packet->stream->base); |
a6918753 PP |
344 | } |
345 | ||
a6918753 | 346 | end: |
9e550e5f | 347 | return (void *) packet; |
a6918753 PP |
348 | } |
349 | ||
78cf9df6 PP |
350 | int bt_packet_move_header_field(struct bt_packet *packet, |
351 | struct bt_packet_header_field *header_field) | |
a6918753 | 352 | { |
10b7a2e4 | 353 | struct bt_trace_class *tc; |
a6918753 PP |
354 | struct bt_field_wrapper *field_wrapper = (void *) header_field; |
355 | ||
7b33a0e0 | 356 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
a6918753 | 357 | BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); |
7b33a0e0 | 358 | BT_ASSERT_PRE_PACKET_HOT(packet); |
10b7a2e4 PP |
359 | tc = bt_stream_class_borrow_trace_class_inline(packet->stream->class); |
360 | BT_ASSERT_PRE(tc->packet_header_fc, | |
66fd07a5 | 361 | "Trace class has no packet header field class: %!+T", tc); |
939190b3 | 362 | BT_ASSERT_PRE(field_wrapper->field->class == |
10b7a2e4 | 363 | tc->packet_header_fc, |
939190b3 PP |
364 | "Unexpected packet header field's class: " |
365 | "%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class, | |
10b7a2e4 | 366 | tc->packet_header_fc); |
a6918753 PP |
367 | |
368 | /* Recycle current header field: always exists */ | |
7b33a0e0 | 369 | BT_ASSERT(packet->header_field); |
10b7a2e4 | 370 | recycle_header_field(packet->header_field, tc); |
a6918753 PP |
371 | |
372 | /* Move new field */ | |
7b33a0e0 | 373 | packet->header_field = field_wrapper; |
a6918753 PP |
374 | return 0; |
375 | } | |
376 | ||
78cf9df6 PP |
377 | int bt_packet_move_context_field(struct bt_packet *packet, |
378 | struct bt_packet_context_field *context_field) | |
a6918753 PP |
379 | { |
380 | struct bt_stream_class *stream_class; | |
381 | struct bt_field_wrapper *field_wrapper = (void *) context_field; | |
382 | ||
7b33a0e0 | 383 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
a6918753 | 384 | BT_ASSERT_PRE_NON_NULL(field_wrapper, "Context field"); |
8fc063a2 | 385 | BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); |
7b33a0e0 | 386 | stream_class = packet->stream->class; |
939190b3 | 387 | BT_ASSERT_PRE(stream_class->packet_context_fc, |
66fd07a5 | 388 | "Stream class has no packet context field class: %!+S", |
a6918753 | 389 | stream_class); |
939190b3 PP |
390 | BT_ASSERT_PRE(field_wrapper->field->class == |
391 | stream_class->packet_context_fc, | |
392 | "Unexpected packet header field's class: " | |
393 | "%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class, | |
394 | stream_class->packet_context_fc); | |
a6918753 PP |
395 | |
396 | /* Recycle current context field: always exists */ | |
7b33a0e0 PP |
397 | BT_ASSERT(packet->context_field); |
398 | recycle_context_field(packet->context_field, stream_class); | |
a6918753 PP |
399 | |
400 | /* Move new field */ | |
7b33a0e0 | 401 | packet->context_field = field_wrapper; |
a6918753 PP |
402 | return 0; |
403 | } | |
8fc063a2 | 404 | |
78cf9df6 | 405 | void bt_packet_set_default_beginning_clock_value(struct bt_packet *packet, |
7b33a0e0 | 406 | uint64_t value_cycles) |
8fc063a2 | 407 | { |
7b33a0e0 | 408 | struct bt_stream_class *sc; |
e5815ba2 | 409 | |
8fc063a2 | 410 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 PP |
411 | BT_ASSERT_PRE_PACKET_HOT(packet); |
412 | sc = packet->stream->class; | |
413 | BT_ASSERT(sc); | |
414 | BT_ASSERT_PRE(sc->default_clock_class, | |
415 | "Packet's stream class has no default clock class: " | |
416 | "%![packet-]+a, %![sc-]+S", packet, sc); | |
417 | BT_ASSERT_PRE(sc->packets_have_default_beginning_cv, | |
418 | "Packet's stream class indicates that its packets have " | |
419 | "no default beginning clock value: %![packet-]+a, %![sc-]+S", | |
420 | packet, sc); | |
421 | BT_ASSERT(packet->default_beginning_cv); | |
c8bbf821 PP |
422 | bt_clock_value_set_value_inline(packet->default_beginning_cv, |
423 | value_cycles); | |
7b33a0e0 | 424 | BT_LIB_LOGV("Set packet's default beginning clock value: " |
9e550e5f | 425 | "%![packet-]+a, value=%" PRIu64, packet, value_cycles); |
8fc063a2 PP |
426 | } |
427 | ||
7b33a0e0 | 428 | enum bt_clock_value_status bt_packet_borrow_default_beginning_clock_value( |
78cf9df6 PP |
429 | const struct bt_packet *packet, |
430 | const struct bt_clock_value **clock_value) | |
8fc063a2 | 431 | { |
8fc063a2 | 432 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 PP |
433 | BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)"); |
434 | *clock_value = packet->default_beginning_cv; | |
435 | return BT_CLOCK_VALUE_STATUS_KNOWN; | |
8fc063a2 PP |
436 | } |
437 | ||
78cf9df6 | 438 | void bt_packet_set_default_end_clock_value(struct bt_packet *packet, |
7b33a0e0 | 439 | uint64_t value_cycles) |
8fc063a2 | 440 | { |
7b33a0e0 PP |
441 | struct bt_stream_class *sc; |
442 | ||
8fc063a2 | 443 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 PP |
444 | BT_ASSERT_PRE_PACKET_HOT(packet); |
445 | sc = packet->stream->class; | |
446 | BT_ASSERT(sc); | |
447 | BT_ASSERT_PRE(sc->default_clock_class, | |
448 | "Packet's stream class has no default clock class: " | |
449 | "%![packet-]+a, %![sc-]+S", packet, sc); | |
450 | BT_ASSERT_PRE(sc->packets_have_default_end_cv, | |
451 | "Packet's stream class indicates that its packets have " | |
452 | "no default end clock value: %![packet-]+a, %![sc-]+S", | |
453 | packet, sc); | |
454 | BT_ASSERT(packet->default_end_cv); | |
455 | bt_clock_value_set_value_inline(packet->default_end_cv, value_cycles); | |
456 | BT_LIB_LOGV("Set packet's default end clock value: " | |
9e550e5f | 457 | "%![packet-]+a, value=%" PRIu64, packet, value_cycles); |
e5815ba2 PP |
458 | } |
459 | ||
7b33a0e0 | 460 | enum bt_clock_value_status bt_packet_borrow_default_end_clock_value( |
78cf9df6 PP |
461 | const struct bt_packet *packet, |
462 | const struct bt_clock_value **clock_value) | |
e5815ba2 PP |
463 | { |
464 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); | |
7b33a0e0 PP |
465 | BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)"); |
466 | *clock_value = packet->default_end_cv; | |
467 | return BT_CLOCK_VALUE_STATUS_KNOWN; | |
8fc063a2 PP |
468 | } |
469 | ||
7b33a0e0 | 470 | enum bt_property_availability bt_packet_get_discarded_event_counter_snapshot( |
78cf9df6 | 471 | const struct bt_packet *packet, uint64_t *value) |
8fc063a2 | 472 | { |
e5815ba2 | 473 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 PP |
474 | BT_ASSERT_PRE_NON_NULL(value, "Value (output)"); |
475 | *value = packet->discarded_event_counter_snapshot.value; | |
476 | return packet->discarded_event_counter_snapshot.base.avail; | |
e5815ba2 | 477 | } |
8fc063a2 | 478 | |
78cf9df6 PP |
479 | void bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet, |
480 | uint64_t value) | |
e5815ba2 | 481 | { |
8fc063a2 | 482 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
7b33a0e0 PP |
483 | BT_ASSERT_PRE_PACKET_HOT(packet); |
484 | BT_ASSERT_PRE(packet->stream->class->packets_have_discarded_event_counter_snapshot, | |
485 | "Packet's stream's discarded event counter is not enabled: " | |
486 | "%![packet-]+a", packet); | |
487 | bt_property_uint_set(&packet->discarded_event_counter_snapshot, value); | |
e5815ba2 | 488 | } |
8fc063a2 | 489 | |
7b33a0e0 | 490 | enum bt_property_availability bt_packet_get_packet_counter_snapshot( |
78cf9df6 | 491 | const struct bt_packet *packet, uint64_t *value) |
e5815ba2 PP |
492 | { |
493 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); | |
7b33a0e0 PP |
494 | BT_ASSERT_PRE_NON_NULL(value, "Value (output)"); |
495 | *value = packet->packet_counter_snapshot.value; | |
496 | return packet->packet_counter_snapshot.base.avail; | |
e5815ba2 PP |
497 | } |
498 | ||
78cf9df6 PP |
499 | void bt_packet_set_packet_counter_snapshot(struct bt_packet *packet, |
500 | uint64_t value) | |
e5815ba2 PP |
501 | { |
502 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); | |
7b33a0e0 PP |
503 | BT_ASSERT_PRE_PACKET_HOT(packet); |
504 | BT_ASSERT_PRE(packet->stream->class->packets_have_packet_counter_snapshot, | |
505 | "Packet's stream's packet counter is not enabled: " | |
506 | "%![packet-]+a", packet); | |
507 | bt_property_uint_set(&packet->packet_counter_snapshot, value); | |
8fc063a2 | 508 | } |