2015-12-23 49 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