self._serialize_write_dst_id_statements_templ = self._create_template('serialize-write-dst-id-statements.j2')
self._serialize_write_timestamp_statements_templ = self._create_template('serialize-write-timestamp-statements.j2')
self._serialize_write_packet_size_statements_templ = self._create_template('serialize-write-packet-size-statements.j2')
+ self._serialize_write_seq_num_statements_templ = self._create_template('serialize-write-seq-num-statements.j2')
self._serialize_write_skip_save_statements_templ = self._create_template('serialize-write-skip-save-statements.j2')
self._serialize_write_ert_id_statements_templ = self._create_template('serialize-write-ert-id-statements.j2')
self._size_align_statements_templ = self._create_template('size-align-statements.j2')
'packet_size',
'content_size',
'events_discarded',
+ 'packet_seq_num',
}
parts.append(self._proto_params_str(dst._pkt_ctx_ft, _RootFtPrefixes.PC, const_params,
exclude_set))
'timestamp_end': self._serialize_write_skip_save_statements_templ,
'events_discarded': self._serialize_write_skip_save_statements_templ,
'content_size': self._serialize_write_skip_save_statements_templ,
+ 'packet_seq_num': self._serialize_write_seq_num_statements_templ,
}
pkt_ctx_op = builder.build_for_root_ft(dst._pkt_ctx_ft, _RootFtPrefixes.PC,
spec_serialize_write_templates)
content_size_field_type: _DefaultableUIntFt = DEFAULT_FIELD_TYPE,
beginning_timestamp_field_type: _OptDefaultableUIntFt = None,
end_timestamp_field_type: _OptDefaultableUIntFt = None,
- discarded_event_records_snapshot_counter_field_type: _OptDefaultableUIntFt = DEFAULT_FIELD_TYPE):
+ discarded_event_records_snapshot_counter_field_type: _OptDefaultableUIntFt = DEFAULT_FIELD_TYPE,
+ sequence_number_field_type: _OptDefaultableUIntFt = None):
def get_ft(user_ft: _OptDefaultableUIntFt) -> _OptUIntFt:
if user_ft == DEFAULT_FIELD_TYPE:
return UnsignedIntegerFieldType(64)
self._beginning_timestamp_field_type = get_ft(beginning_timestamp_field_type)
self._end_timestamp_field_type = get_ft(end_timestamp_field_type)
self._discarded_event_records_snapshot_counter_field_type = get_ft(discarded_event_records_snapshot_counter_field_type)
+ self._sequence_number_field_type = get_ft(sequence_number_field_type)
+
+ @property
+ def sequence_number_field_type(self) -> _OptUIntFt:
+ return self._sequence_number_field_type
@property
def total_size_field_type(self) -> _OptUIntFt:
True)
add_member_if_exists('events_discarded',
self._features.packet_features.discarded_event_records_snapshot_counter_field_type)
+ add_member_if_exists('packet_seq_num',
+ self._features.packet_features.sequence_number_field_type)
if self._packet_context_field_type_extra_members is not None:
for name, field_type in self._packet_context_field_type_extra_members.items():
pkt_disc_er_counter_snap_ft = barectf_config.DEFAULT_FIELD_TYPE
ert_id_ft = barectf_config.DEFAULT_FIELD_TYPE
ert_ts_ft = None
+ pkt_seq_num_ft = None
if def_clk_type is not None:
# The data stream type has a default clock type.
pkt_disc_er_counter_snap_ft = self._feature_ft(pkt_node,
'discarded-event-records-counter-snapshot-field-type',
pkt_disc_er_counter_snap_ft)
+ pkt_seq_num_ft = self._feature_ft(pkt_node, 'sequence-number-field-type',
+ pkt_seq_num_ft)
# create event record feature field types
er_node = features_node.get('event-record')
pkt_content_size_ft,
pkt_beginning_ts_ft,
pkt_end_ts_ft,
- pkt_disc_er_counter_snap_ft)
+ pkt_disc_er_counter_snap_ft,
+ pkt_seq_num_ft)
er_features = barectf_config.DataStreamTypeEventRecordFeatures(ert_id_ft, ert_ts_ft)
features = barectf_config.DataStreamTypeFeatures(pkt_features, er_features)
resolve_ft_alias_from(pkt_node, 'end-timestamp-field-type')
resolve_ft_alias_from(pkt_node,
'discarded-event-records-counter-snapshot-field-type')
+ resolve_ft_alias_from(pkt_node, 'sequence-number-field-type')
except _ConfigurationParseError as exc:
_append_error_ctx(exc, f'`{pkt_prop_name}` property')
apply_ft_inheritance(pkt_node, 'end-timestamp-field-type')
apply_ft_inheritance(pkt_node,
'discarded-event-records-counter-snapshot-field-type')
+ apply_ft_inheritance(pkt_node, 'sequence-number-field-type')
er_node = features_node.get('event-record')
normalize_struct_ft_member_nodes(pkt_node, 'end-timestamp-field-type')
normalize_struct_ft_member_nodes(pkt_node,
'discarded-event-records-counter-snapshot-field-type')
+ normalize_struct_ft_member_nodes(pkt_node, 'sequence-number-field-type')
er_node = features_node.get('event-record')
$ref: '#/definitions/partial-ft'
discarded-event-records-counter-snapshot-field-type:
$ref: '#/definitions/partial-ft'
+ sequence-number-field-type:
+ $ref: '#/definitions/partial-ft'
else:
type: 'null'
event-record:
$ref: '#/definitions/opt-or-def-feature-uint-ft'
discarded-event-records-counter-snapshot-field-type:
$ref: '#/definitions/opt-or-def-feature-uint-ft'
+ sequence-number-field-type:
+ $ref: '#/definitions/opt-or-def-feature-uint-ft'
additionalProperties: false
else:
type: 'null'
return {{ prefix }}packet_events_discarded(vctx);
}
+uint32_t {{ prefix }}packet_sequence_number(const void * const vctx)
+{
+ return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->sequence_number;
+}
+
uint8_t *{{ prefix }}packet_buf(const void * const vctx)
{
return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->buf;
ctx->packet_size = _BYTES_TO_BITS(buf_size);
ctx->at = 0;
ctx->events_discarded = 0;
+ ctx->sequence_number = 0;
ctx->packet_is_open = 0;
ctx->in_tracing_section = 0;
ctx->is_tracing_enabled = 1;
/* Mark packet as closed */
ctx->packet_is_open = 0;
+ {% if 'packet_seq_num' in dst._pkt_ctx_ft.members %}
+ /* Increment sequence number for next packet */
+ ctx->sequence_number++;
+ {% endif %}
/* Not tracing anymore */
ctx->in_tracing_section = saved_in_tracing_section;
int {{ prefix }}packet_is_empty(const void *vctx);
uint32_t {{ prefix }}packet_events_discarded(const void *vctx);
uint32_t {{ prefix }}discarded_event_records_count(const void * const vctx);
+uint32_t {{ prefix }}packet_sequence_number(const void * const vctx);
uint8_t *{{ prefix }}packet_buf(const void *vctx);
uint8_t *{{ prefix }}packet_buf_addr(const void * const vctx);
void {{ prefix }}packet_set_buf(void *vctx, uint8_t *buf, uint32_t buf_size);
/* Discarded event records counter snapshot */
uint32_t events_discarded;
+ /* Packet's sequence number */
+ uint32_t sequence_number;
+
/* Current packet is open? */
int packet_is_open;
--- /dev/null
+{#
+ # The MIT License (MIT)
+ #
+ # Copyright (c) 2022 Jon Lamb <jon@auxon.io>
+ #
+ # Permission is hereby granted, free of charge, to any person obtaining
+ # a copy of this software and associated documentation files (the
+ # "Software"), to deal in the Software without restriction, including
+ # without limitation the rights to use, copy, modify, merge, publish,
+ # distribute, sublicense, and/or sell copies of the Software, and to
+ # permit persons to whom the Software is furnished to do so, subject to
+ # the following conditions:
+ #
+ # The above copyright notice and this permission notice shall be
+ # included in all copies or substantial portions of the Software.
+ #
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ #}
+{% set c_type = op.ft | ft_c_type %}
+{% set src = 'ctx->sequence_number' %}
+/* Write `packet_seq_num` field */
+{% include 'c/serialize-write-bit-array-statements.j2' %}
xref:yaml:dst-obj.adoc#disc-er-counter-snapshot-ft-prop[`discarded-event-records-counter-snapshot-field-type`
property].
-** [.opt]##Optional##A packet sequence number.
+** [.opt]##Optional##A packet sequence number (within its <<ds,data
+ stream>>).
++
+See the data stream type packet features object's
+xref:yaml:dst-obj.adoc#seq-num-ft-prop[`sequence-number-field-type`
+property].
+
** [.opt]##Optional##User fields.
+
See the data stream type object's
xref:how-barectf-works:ctf-primer.adoc#disc-er-counter[discarded event
records] in the barectf context `vctx`.
+* [[barectf-pkt-seq-num-func]]{empty}
++
+[source,c]
+----
+uint32_t barectf_packet_sequence_number(const void *vctx);
+----
++
+Returns the packet sequence number in the barectf context `vctx`.
+
* {empty}
+
[source,c]
A packet closing function:
-. Writes some
- xref:how-barectf-works:ctf-primer.adoc#pkt[packet context]
+. Marks the current packet as being closed.
+
+. Writes some xref:how-barectf-works:ctf-primer.adoc#pkt[packet context]
fields.
-. Marks the current packet as being closed.
+. If the
+ xref:yaml:dst-obj.adoc#seq-num-ft-prop[`sequence-number-field-type`
+ packet feature] of the corresponding data stream type is enabled:
+ increments the packet sequence number of `sctx`.
In general, a <<cb-close,packet closing platform callback function>> and
a platform finalization function (for the last packet) call this
If this property's value is a string, it must be the name of an existing
xref:trace-type-obj.adoc#ft-aliases-prop[field type alias].
|Use a default field type (true)
+
+|[[seq-num-ft-prop]]`sequence-number-field-type`
+|Unsigned xref:int-ft-obj.adoc[integer field type object], string,
+or boolean
+|Type of packet context's sequence number field.
+
+If this property's value is a string, it must be the name of an existing
+xref:trace-type-obj.adoc#ft-aliases-prop[field type alias].
+|Disabled (false)
|===
[[er-features-obj]]
----
====
+.Data stream type object with an enabled packet <<seq-num-ft-prop,sequence number field type feature>>.
+====
+[source,yaml]
+----
+$features:
+ packet:
+ sequence-number-field-type: true
+event-record-types:
+ # ...
+----
+====
+
.Data stream type object with 16-bit packet <<total-size-ft-prop,total>> and <<content-size-ft-prop,content size field type features>>.
====
[source,yaml]
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2022 Jon Lamb <jon@auxon.io>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+%YAML 1.2
+--- !<tag:barectf.org,2020/3/config>
+trace:
+ type:
+ $include:
+ - base-no-features.yaml
+ data-stream-types:
+ default:
+ $features:
+ packet:
+ sequence-number-field-type: true
+ event-record-types:
+ ev:
+ payload-field-type:
+ class: struct
+ members:
+ - s:
+ field-type:
+ class: string
--- /dev/null
+/* CTF 1.8 */
+
+/*
+ * The MIT License (MIT)
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ *
+ *
+ * For more details, see <https://barectf.org/>.
+ */
+
+trace {
+ major = 1;
+ minor = 8;
+ byte_order = le;
+ packet.header := struct {
+ integer {
+ signed = false;
+ size = 64;
+ align = 8;
+ byte_order = native;
+ base = 10;
+ } stream_id;
+ } align(8);
+};
+
+env {
+ domain = "bare";
+ tracer_name = "barectf";
+};
+
+clock {
+ name = default;
+ freq = 1000000000;
+ precision = 0;
+ offset_s = 0;
+ offset = 0;
+ absolute = false;
+};
+
+/* Data stream type `default` */
+stream {
+ id = 0;
+ packet.context := struct {
+ integer {
+ signed = false;
+ size = 64;
+ align = 8;
+ byte_order = native;
+ base = 10;
+ } packet_size;
+ integer {
+ signed = false;
+ size = 64;
+ align = 8;
+ byte_order = native;
+ base = 10;
+ } content_size;
+ integer {
+ signed = false;
+ size = 64;
+ align = 8;
+ byte_order = native;
+ base = 10;
+ } packet_seq_num;
+ } align(8);
+ event.header := struct {
+ integer {
+ signed = false;
+ size = 64;
+ align = 8;
+ byte_order = native;
+ base = 10;
+ } id;
+ } align(8);
+};
+
+event {
+ stream_id = 0;
+ id = 0;
+ name = "dummy";
+ fields := struct {
+ string {
+ encoding = UTF8;
+ } u;
+ } align(1);
+};
+
+event {
+ stream_id = 0;
+ id = 1;
+ name = "ev";
+ fields := struct {
+ string {
+ encoding = UTF8;
+ } s;
+ } align(1);
+};
--- /dev/null
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2022 Jon Lamb <jon@auxon.io>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+#include <stdint.h>
+
+#include "test-platform.h"
+#include "barectf.h"
+
+int main(void)
+{
+ struct test_platform_ctx * const platform_ctx = test_platform_init(64);
+
+ assert(platform_ctx);
+ assert(barectf_packet_sequence_number(test_platform_barectf_ctx(platform_ctx)) == 0);
+ barectf_trace_ev(test_platform_barectf_ctx(platform_ctx),
+ "I feel special.");
+ barectf_trace_ev(test_platform_barectf_ctx(platform_ctx),
+ "I feel special.");
+ assert(barectf_packet_sequence_number(test_platform_barectf_ctx(platform_ctx)) == 1);
+ barectf_trace_ev(test_platform_barectf_ctx(platform_ctx),
+ "I feel special.");
+ assert(barectf_packet_sequence_number(test_platform_barectf_ctx(platform_ctx)) == 2);
+ barectf_trace_ev(test_platform_barectf_ctx(platform_ctx),
+ "I feel special.");
+ assert(barectf_packet_sequence_number(test_platform_barectf_ctx(platform_ctx)) == 3);
+ test_platform_fini(platform_ctx);
+ return 0;
+}