pythonlttngbabeltrace

How do I get debug_info from lttng ctf trace using babeltrace python bindings?


I'm using the Babeltrace python3 bindings to read an lttng ust trace that contains debug_info. When I run Babeltrace from the shell I see the debug_info in the output:

[13:28:29.998652878] (+0.000000321) hsm-dev lttng_ust_cyg_profile:func_exit: { cpu_id = 1 }, { ip = 0x4008E5, debug_info = { bin = "a.out@0x4008e5", func = "foo+0" }, vpid = 28208, vtid = 28211 }, { addr = 0x4008E5, call_site = 0x400957 }

From the python bindings I can get the other event fields (cpu_id, ip, addr, call_site...) but I get key errors trying to access debug_info, bin or func.

import babeltrace

collection = babeltrace.TraceCollection()
collection.add_traces_recursive('lttng-traces/a.out-20170624-132829/', 'ctf')

for e in collection.events:
    if e.name ==  'lttng_ust_cyg_profile:func_entry':
        print(e['addr'])
        print(e['func'])

Traceback (most recent call last):
  File "fields.py", line 9, in <module>
    print(e['func'])
  File "/usr/lib/python3/dist-packages/babeltrace.py", line 865, in __getitem__
    raise KeyError(field_name)
KeyError: 'func'

Is there a way to get those fields from Python?

I'm using Babeltrace 1.5.2


Solution

  • Not yet. It is possible with the Babeltrace 2 Python bindings, after building the appropriate processing graph and running it, but this major revision is not released as of this date (pre stage).

    There's a hack for debug information in Babeltrace 1 in which the text output "injects" virtual fields at print time, but they are not available before that, so that's why you can't access e['func'], for example.

    Your best bet for the moment is to create a babeltrace CLI subprocess and, one line of output at a time, use a regex to find the fields you need. Ugly, but that's what available today.