2015-12-23 44 views
0

如何使用babeltrace的python reader api打印完整的跟踪?如何使用babeltrace-python api打印完整的跟踪事件?

使用下面我可以得到一个事件的字段,但我怎么能打印完整的跟踪babeltrace。

import babeltrace 
import sys 

trace_collection = babeltrace.TraceCollection() 
trace_path = sys.argv[1] 

trace_collection.add_traces_recursive(trace_path, 'ctf') 

for event in trace_collection.events: 
    print event.timestamp, event.cycles, event.name 

并且使用事件字典可以获取字段。但如何用Python阅读器复制babeltrace输出?

for event in trace_collection.events: 
    for field in event.items(): 
    print field 

样品babeltrace输出:

[2015-10-20 15:16:34.600508066] (+1.481059687) samplehost sample_trace_provider:INFO: { cpu_id = 1 }, { fileAndLine = "sampletest.cpp:330", msg = "Directing trace stream to channel #0" } 

让我知道是否需要任何进一步的信息。

回答

0

你不能像你所期望的那样在一个陈述中做到这一点。这是因为Babeltrace Python绑定类不会以递归方式实现__str__

运行babeltrace命令时,你得到默认的输出格式被称为CTF-文本和C.实现当然是有办法复制CTF-文本的输出,但是你需要在Python中手动实现漂亮的打印机。

+0

感谢您的信息和评论! – seenu9333