From: Philippe Proulx Date: Tue, 26 May 2015 00:15:15 +0000 (-0400) Subject: Add support for discarded events on packet close X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=409386a4c875a1db98aca7aa07ad7a0b36dc60b9;p=deliverable%2Fbarectf.git Add support for discarded events on packet close If a stream's packet context has the "events_discarded" field, its barectf_close_packet() function will accept an additional parameter which indicates the number of discarded events *so far for this stream* (free-running counter, i.e. not per packet). --- diff --git a/barectf/cli.py b/barectf/cli.py index 8aea22e..2905c17 100644 --- a/barectf/cli.py +++ b/barectf/cli.py @@ -378,6 +378,13 @@ class BarectfCodeGenerator: except RuntimeError as e: _perror('stream {}: packet context: "cpu_id": {}'.format(sid, e)) + # if events_discarded exists, must be an unsigned integer + if 'events_discarded' in fields: + try: + self._validate_integer(fields['events_discarded'], signed=False) + except RuntimeError as e: + _perror('stream {}: packet context: "events_discarded": {}'.format(sid, e)) + # Validates an event header. # # stream: TSDL stream containing the event header to validate @@ -1396,6 +1403,12 @@ class BarectfCodeGenerator: scope_prefix, lambda x: '0') fcline_groups.append(fclines) + # events discarded (skip) + elif fname == 'events_discarded': + fclines = self._field_to_clines(fname, ftype, scope_name, + scope_prefix, lambda x: '0') + fcline_groups.append(fclines) + # timestamp_begin elif fname == 'timestamp_begin': fclines = self._field_to_clines(fname, ftype, scope_name, @@ -1432,6 +1445,7 @@ class BarectfCodeGenerator: 'packet_size', 'timestamp_begin', 'timestamp_end', + 'events_discarded', ] # Generates a barectf_open() function. @@ -1679,6 +1693,29 @@ class BarectfCodeGenerator: 'content_size', content_size_integer) + # set events_discarded + if 'events_discarded' in stream.packet_context.fields: + # events_discarded parameter name (provided by user) + pname = self._spc_fname_to_pname('events_discarded') + + # save buffer position + clines.append(_CLine('')) + line = 'ctx_at_bkup = {};'.format(self._CTX_AT) + clines.append(_CLine(line)) + + # go back to field offset + offvar = self._get_offvar_name('events_discarded', 'spc') + line = '{} = ctx->{};'.format(self._CTX_AT, offvar) + clines.append(_CLine(line)) + + # write value + integer = stream.packet_context['events_discarded'] + clines += self._write_field_integer(None, pname, integer) + + # restore buffer position + line = '{} = ctx_at_bkup;'.format(self._CTX_AT) + clines.append(_CLine(line)) + # return 0 clines.append(_CLine('\n')) clines.append(_CLine('return 0;')) @@ -1707,6 +1744,12 @@ class BarectfCodeGenerator: clock_param = self._gen_manual_clock_param(stream) params = ',\n\t{}'.format(clock_param) + if 'events_discarded' in stream.packet_context.fields: + ftype = stream.packet_context['events_discarded'] + ptype = self._get_obj_param_ctype(ftype) + pname = self._spc_fname_to_pname('events_discarded') + params += ',\n\t{} {}'.format(ptype, pname) + t = barectf.templates.FUNC_CLOSE func = t.format(si=self._si_str, prefix=self._prefix, sid=sid, params=params) diff --git a/doc/examples/simple/ctf/metadata b/doc/examples/simple/ctf/metadata index e3d36b4..470b295 100644 --- a/doc/examples/simple/ctf/metadata +++ b/doc/examples/simple/ctf/metadata @@ -59,6 +59,7 @@ stream { my_clock_int_t timestamp_end; uint64_t packet_size; uint64_t content_size; + uint32_t events_discarded; }; event.header := struct { diff --git a/doc/examples/simple/simple.c b/doc/examples/simple/simple.c index bf296ee..f26a9c9 100644 --- a/doc/examples/simple/simple.c +++ b/doc/examples/simple/simple.c @@ -42,8 +42,8 @@ static void simple(uint8_t* buf, size_t sz) barectf_trace_a_few_fields(pctx, -1, 301, -3.14159, "Hello again!", NEW); barectf_trace_bit_packed_integers(pctx, 1, -1, 3, -2, 2, 7, 23, -55, 232); - /* close packet */ - barectf_close_packet(pctx); + /* close packet with 3 discarded events */ + barectf_close_packet(pctx, 3); } static void write_packet(const char* filename, const uint8_t* buf, size_t sz)