From mboxrd@z Thu Jan 1 00:00:00 1970 From: jdesfossez@efficios.com (Julien Desfossez) Date: Wed, 12 Oct 2016 11:23:51 -0400 Subject: [lttng-dev] [lttng-ust] [babeltrace] use case question - field names in event classes In-Reply-To: <7110ec441dc2f14caee4a447826c31f7.squirrel@email.powweb.com> References: <8867c80160a75f382ac5dd3f50d2014b.squirrel@email.powweb.com> <7110ec441dc2f14caee4a447826c31f7.squirrel@email.powweb.com> Message-ID: <20161012152351.GA26170@sinkpad.internal.efficios.com> On 12-Oct-2016 08:51:46 AM, Staffan Tjernstrom wrote: > > > > In the code, before calling the associated `two_ints_and_string` > > tracepoint, and only once: > > > > tracepoint(my_app, log_statement_field_names, 1, > > "widget_height", "widget_width", "widget_name", ""); > > > > Then: > > > > tracepoint(my_app, two_ints_and_string, 1, height, width, name); > > > > Then in your Python script you can register the dynamic field names > > when > > you get a `log_statement_field_names` event and use them when you get > > a > > "real" event (not tested): > > > > id_to_field_names = {} > > > > # open trace, etc. > > > > # some loop over the trace's events: > > if evt.name == 'log_statement_field_names': > > field_names = (evt['arg1'], evt['arg2'], evt['arg3'], > > evt['arg4']) > > id_to_field_names[evt['id']] = field_names > > elif evt.name == 'two_ints_and_string': > > field_names = id_to_field_names[evt['id']] > > print('{}: {}'.format(field_names[0], evt['value1'])) > > print('{}: {}'.format(field_names[1], evt['value2'])) > > print('{}: {}'.format(field_names[2], evt['value3'])) > > print() > > > > Now this is a great use case for future extensions of LTTng-UST and/or > > the upcoming CTF 2. > > > > Phil > > > Thanks - I hadn't thought of the Python bindings - I think we could > make that work (maybe wrapping the two tracepoint incantations into a > single macro definition). If you want some help generating the boiler plate Python code for parsing your trace, I recommend the parser_generator.py script from lttng-analyses: https://github.com/lttng/lttng-analyses/blob/master/parser_generator.py Julien