Add support for discarded events on packet close
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 26 May 2015 00:15:15 +0000 (20:15 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 26 May 2015 00:18:25 +0000 (20:18 -0400)
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).

barectf/cli.py
doc/examples/simple/ctf/metadata
doc/examples/simple/simple.c

index 8aea22e9bd3dcd2042dff551beb9c05745a92ece..2905c1776faea813dc881a78eee91ea960d183ba 100644 (file)
@@ -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)
index e3d36b43396671fbfbb1ee24c8b7571d4ecbc52b..470b29573101dfaa29f51a0de3cf6857e604c89c 100644 (file)
@@ -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 {
index bf296eecc2db5fe959f6c5aaf230fcdfee4263e2..f26a9c9c2344e167373c42d3c039f98d710a9127 100644 (file)
@@ -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)
This page took 0.02646 seconds and 4 git commands to generate.