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 _define_stream_class(self): self.stream_class = CTFWriter.StreamClass("test_stream") self.stream_class.clock = self.clock # Add cpu_ip to existing stream packet context type t = self.stream_class.packet_context_type t.add_field(self.uint32_type, "cpu_id") # Define stream event context type t = CTFWriter.StructureFieldDeclaration() t.add_field(self.uint64_hex_type, "_ip") t.add_field(self.int32_type, "_vpid") self.stream_class.event_context_type = t
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 = {}
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 # add this field declaration to response_time event class event_class.add_field(int32_field_decl, 'ID_field') # create one 32-bit signed integer field. This will be used for code ID. int64_field_decl = btw.IntegerFieldDeclaration(64) int64_field_decl.signed = False # add this field declaration to response_time event class
def create_stream_class(self): self.stream_class = CTFWriter.StreamClass("test_stream") self.stream_class.clock = self.clock
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 int32_type.alignment = 8 uint32_type = CTFWriter.IntegerFieldDeclaration(32) uint32_type.signed = False uint32_type.alignment = 8