def convert(self, from_dir, to_dir): tc = babeltrace.TraceCollection() tc.add_trace(from_dir, "ctf") clock = CTFWriter.Clock("clk") writer = CTFWriter.Writer(to_dir) writer.add_clock(clock) stream_class = CTFWriter.StreamClass('trace') stream_class.clock = clock stream_class.packet_context_type.add_field(CTFWriter.IntegerFieldDeclaration(32), "cpu_id") for id, clslst in self.handlers.items(): for cls in clslst: for ev in cls.get_generated_events(): stream_class.add_event_class(ev) stream = {} for e in tc.events: clock.time = e.timestamp id = e["cpu_id"] if id not in self.threads: self.threads[id] = ThreadState(self.handlers) stream[id] = writer.create_stream(stream_class) stream[id].packet_context.field("cpu_id").value = id evl = self.threads[id].consume(e) for ev in evl: stream[id].append_event(ev) for s in stream.values(): s.flush()
def create_stream_file(streamfile_dest, my_deque): writer = CTFWriter.Writer(streamfile_dest) clock = CTFWriter.Clock("A_clock") clock.description = "Simple clock" writer.add_clock(clock) writer.add_environment_field("Python_version", str(sys.version_info)) stream_class = CTFWriter.StreamClass("test_stream") stream_class.clock = clock event_class = CTFWriter.EventClass("SimpleEvent") # Create a int32_t equivalent type int32_type = CTFWriter.IntegerFieldDeclaration(32) int32_type.signed = True event_class.add_field(int32_type, "value") # Create a int32_t equivalent type for the event_id_count int32_type = CTFWriter.IntegerFieldDeclaration(32) int32_type.signed = True event_class.add_field(int32_type, "event_id_count") stream_class.add_event_class(event_class) stream = writer.create_stream(stream_class) for item in my_deque: event = CTFWriter.Event(event_class) clock.time = item["timestamp"] integer_field = event.payload("value") integer_field.value = item["value"] integer_field = event.payload("event_id_count") integer_field.value = item["event_id_counter"] stream.append_event(event) stream.flush()
def create_writer(self): self.clock = CTFWriter.Clock("A_clock") self.clock.description = "Simple clock" self.writer = CTFWriter.Writer(self.trace_path) self.writer.add_clock(self.clock) self.writer.add_environment_field("Python_version", str(sys.version_info)) self.writer.add_environment_field("tracer_major", 2) self.writer.add_environment_field("tracer_minor", 8) self.writer.add_environment_field("tracer_patchlevel", 0)
def _create_writer(self): self.writer = CTFWriter.Writer(self.trace_path) self.clock = CTFWriter.Clock("A_clock") self.clock.description = "Simple clock" self.writer.add_clock(self.clock) self.writer.add_environment_field("domain", "ust") self.writer.add_environment_field("tracer_name", "lttng-ust") self.writer.add_environment_field("tracer_major", 2) self.writer.add_environment_field("tracer_minor", 8)
def __init__(self, args, handle, traces): self.args = args self.handle = handle self.traces = traces self.clock = CTFWriter.Clock('monotonic') self.clock.description = 'Monotonic Clock' self.clock.freq = 1000000000 self.writer = CTFWriter.Writer(self.args.output) self.writer.add_clock(self.clock) self.stream_class = CTFWriter.StreamClass('test_stream') self.stream_class.clock = self.clock self.event_classes = {}
filename = "log.txt" # temporary directory holding the CTF trace trace_path = "/home/ctf" print('trace path: {}'.format(trace_path)) while 1: number_of_events = 0 # our writer writer = btw.Writer(trace_path) writer.byte_order = 2 # setto modalità big endian, info trovata su babeltrace.h # create one default clock and register it to the writer # the default frequency is 1 Ghz, that increments clock each nanosecond clock = btw.Clock('my_clock') clock.description = 'this is my clock' #clock.offset_seconds = 18 #clock.time = 18 writer.add_clock(clock) # create stream_profiler_1 stream class and assign our clock to it stream_class = btw.StreamClass('stream_profiler_1') stream_class.clock = clock # create response_time event class, that stores all the response times collected by profiler_1 event_class = btw.EventClass('response_time') # create one 8-bit unsigned integer field. This will be used for code ID. int32_field_decl = btw.IntegerFieldDeclaration(32) int32_field_decl.signed = False
import sys import tempfile try: from babeltrace import CTFWriter, CTFStringEncoding except ImportError: # quick fix for debian-based distros sys.path.append("/usr/local/lib/python%d.%d/site-packages" % (sys.version_info.major, sys.version_info.minor)) from babeltrace import CTFWriter, CTFStringEncoding trace_path = tempfile.mkdtemp() print("Writing trace at {}".format(trace_path)) writer = CTFWriter.Writer(trace_path) clock = CTFWriter.Clock("A_clock") clock.description = "Simple clock" writer.add_clock(clock) writer.add_environment_field("Python_version", str(sys.version_info)) stream_class = CTFWriter.StreamClass("test_stream") stream_class.clock = clock char8_type = CTFWriter.IntegerFieldDeclaration(8) char8_type.signed = True char8_type.encoding = CTFStringEncoding.UTF8 char8_type.alignment = 8 int32_type = CTFWriter.IntegerFieldDeclaration(32) int32_type.signed = True