[lttng-dev] [RFC PATCH babeltrace] ctf-writer: Add support for the cpu_id field
Jérémie Galarneau
jeremie.galarneau at efficios.com
Tue Jun 3 10:23:59 EDT 2014
On Tue, Jun 3, 2014 at 3:39 AM, Sebastian Andrzej Siewior
<bigeasy at linutronix.de> wrote:
> On 06/02/2014 07:08 PM, Jérémie Galarneau wrote:
>> Hi Sebastian,
>
> Hi Jérémie,
>
>> I'd prefer we provide a generic way of adding fields to the packet
>> context. Something akin to what's provided for structures which would
>> let users define arbitrary packet context fields.
>>
>> I propose adding
>>
>> int bt_ctf_stream_class_add_packet_context_field(const char
>> *field_name, struct bt_ctf_field_type *field_type);
>>
>> and
>>
>> struct bt_ctf_field *bt_ctf_stream_get_packet_context_field(const char
>> *field_name);
>>
>> I'm open to better naming suggestions, but hopefully I'm getting the
>> functionality across.
>>
>> Thoughts?
> Looks like a few lines more than what I hoped for. Let me try your way.
> So what you suggest is something like that:
>
> ---
> struct bt_ctf_field_type *cpu_num;
>
> cpu_num = bt_ctf_field_type_integer_create(31);
>
> bt_ctf_field_signed_integer_set_value(cpu_num, 2);
> bt_ctf_stream_class_add_packet_context_field("cpu", cpu_num);
>
More like
/* Create and init a stream class... */
struct bt_ctf_stream_class *stream_class = ....;
struct bt_ctf_field_type *cpu_id_type;
/* Add a cpu_id field to the packet_context */
cpu_id_type = bt_ctf_field_type_integer_create(32);
bt_ctf_stream_class_add_packet_context_field("cpu_id", cpu_id_type);
/* Instantiate a stream */
struct bt_ctf_stream *stream = bt_ctf_writer_create_stream(writer,
stream_class);
/* Populate packet context fields */
struct bt_ctf_field *cpu_id_field =
bt_ctf_stream_get_packet_context(stream, "cpu_id");
bt_ctf_field_signed_integer_set_value(cpu_id_field, 2);
bt_ctf_field_put(cpu_id_field);
...
The packet_context values will be written when a flush is called. The
flush call should fail if a packet_context value has not been set.
Adding packet_context fields should fail if a stream of this class has
already been instantiated.
> ---
>
> and then I try to change the CPU number I have to
> bt_ctf_field_signed_integer_set_value() + flush like I did before,
> right?
> For that to work I would have to keep an array of everything that came
> via bt_ctf_stream_class_add_packet_context_field() and attach to struct
> bt_ctf_stream so I have those fields in init_packet_context().
>
> Is this what you had in mind?
Pretty much.
The stream_class should contain an array of field names and field
types belonging to the packet_context whereas the stream should
contain an array of field names and fields.
Regards,
Jérémie
>
>>
>> Jérémie
>
> Sebastian
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list