def _create_trace(self): trace = btw.Writer(self._trace_path) clock = btw.Clock('test_clock') trace.add_clock(clock) integer_field_type = btw.IntegerFieldDeclaration(32) event_class = btw.EventClass('simple_event') event_class.add_field(integer_field_type, 'int_field') stream_class = btw.StreamClass('empty_packet_stream') stream_class.add_event_class(event_class) stream_class.clock = clock stream = trace.create_stream(stream_class) for i in range(self._expected_event_count): event = btw.Event(event_class) event.payload('int_field').value = i stream.append_event(event) stream.flush() # The CTF writer will not be able to populate the packet context's # timestamp_begin and timestamp_end fields if it is asked to flush # without any queued events. with self.assertRaises(ValueError): stream.flush() packet_context = stream.packet_context packet_context.field('timestamp_begin').value = 1 packet_context.field('timestamp_end').value = 123456 stream.flush()
def _create_trace(self, stream_descriptions): trace_path = tempfile.mkdtemp() trace = btw.Writer(trace_path) clock = btw.Clock('test_clock') clock.uuid = self._clock_uuid trace.add_clock(clock) integer_field_type = btw.IntegerFieldDeclaration(32) event_class = btw.EventClass('simple_event') event_class.add_field(integer_field_type, 'int_field') stream_class = btw.StreamClass('test_stream') stream_class.add_event_class(event_class) stream_class.clock = clock streams = [] stream_entries = [] for stream_id, stream_packets in enumerate(stream_descriptions): stream = trace.create_stream(stream_class) streams.append(stream) for packet in stream_packets: for timestamp in packet.timestamps: stream_entries.append(Entry(stream_id, timestamp)) # Mark the last inserted entry as the end of packet stream_entries[len(stream_entries) - 1].end_of_packet = True # Sort stream entries which will provide us with a time-ordered list of # events to insert in the streams. for entry in sorted(stream_entries, key=lambda entry: entry.timestamp): clock.time = entry.timestamp event = btw.Event(event_class) event.payload('int_field').value = entry.stream_id streams[entry.stream_id].append_event(event) if entry.end_of_packet is True: streams[entry.stream_id].flush() return trace_path
def _write_trace(self): trace = btw.Writer(self._trace_path) clock = btw.Clock('test_clock') trace.add_clock(clock) integer_field_type = btw.IntegerFieldDeclaration(32) event_class = btw.EventClass('simple_event') event_class.add_field(integer_field_type, 'int_field') stream_class = btw.StreamClass('test_stream') stream_class.add_event_class(event_class) stream_class.clock = clock stream_class.packet_context_type = None stream = trace.create_stream(stream_class) for i in range(self._expected_event_count): event = btw.Event(event_class) event.payload('int_field').value = i stream.append_event(event) stream.flush() # It is not valid for a stream to contain more than one packet # if it does not have content_size/packet_size info in its packet # context event = btw.Event(event_class) event.payload('int_field').value = 42 stream.append_event(event) flush_raises = False try: stream.flush() except ValueError: flush_raises = True self.assertTrue(flush_raises) trace.flush_metadata()
else: out_path = args.output_trace if not os.path.isdir(out_path): os.system("mkdir " + out_path) writer = btw.Writer(out_path) # Clock clock_offset = 0 metadata_file = path + "/ust/uid/1000/64-bit/metadata" with open(metadata_file, "r", errors='ignore') as f: lines = f.readlines() for l in lines: if "offset = " in l: clock_offset = int(l.split()[-1][:-1]) clock = btw.Clock('monotonic') clock.description = 'Monotonic clock from AMD RCP' writer.add_clock(clock) # Environment writer.add_environment_field("hostname", "pierre-tensorflow") writer.add_environment_field("domain", "ust") writer.add_environment_field("tracer_name", "lttng-ust") writer.add_environment_field("tracer_major", 2) writer.add_environment_field("tracer_minor", 7) # Create stream class main_stream_class = btw.StreamClass('main_stream') main_stream_class.clock = clock from tracing_events_classes import event_classes
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import sys import tempfile import babeltrace.writer as btw trace_path = tempfile.mkdtemp() print("Writing trace at {}".format(trace_path)) writer = btw.Writer(trace_path) clock = btw.Clock("A_clock") print("Clock name is \"{}\"".format(clock.name)) clock.description = "Simple clock" print("Clock description is \"{}\"".format(clock.description)) print("Clock frequency is {}".format(clock.frequency)) print("Clock precision is {}".format(clock.precision)) print("Clock offset_seconds is {}".format(clock.offset_seconds)) print("Clock offset is {}".format(clock.offset)) print("Clock is absolute: {}".format(clock.absolute)) print("Clock time is {}".format(clock.time)) print("Clock UUID is {}".format(clock.uuid)) writer.add_clock(clock) writer.add_environment_field("Python_version", str(sys.version_info)) stream_class = btw.StreamClass("test_stream")
def __init__(self): if not ClockManager.instance: ClockManager.instance = btw.Clock('A_clock') ClockManager.instance.description = "Big Clock"
sys.exit() # Add the input traces to the collection trace_path = '/ust/uid/1000/64-bit/' collection = btr.TraceCollection() collection.add_trace(sys.argv[1] + trace_path, 'ctf') collection.add_trace(sys.argv[2] + trace_path, 'ctf') print('Read input traces at {} and {}.'.format(sys.argv[1], sys.argv[2])) # Set the output trace out_path = sys.argv[3] print('Output trace will be located at {}.'.format(out_path)) writer = btw.Writer(out_path) # Create the clock and register it to the writer main_clock = btw.Clock('main_clock') writer.add_clock(main_clock) # Create stream class main_stream_class = btw.StreamClass('main_stream') main_stream_class.clock = main_clock # Create stream for event_class in event_classes.values(): main_stream_class.add_event_class(event_class) main_stream = writer.create_stream(main_stream_class) # Create events, based on event classes for r_event in collection.events: name = r_event.name.split(':')[-1]
def create_ctf(trace): # temporary directory holding the CTF trace trace_path = tempfile.mkdtemp() # our writer writer = btw.Writer(trace_path) # create one default clock and register it to the writer clock = btw.Clock('my_clock') clock.description = 'this is my clock' #clock.frequency = 3570000000 writer.add_clock(clock) # create our single stream streams = [] event_types = [] for i in range(8): event_types.append({}) print("iter ", i) # create one default stream class and assign our clock to it stream_class = btw.StreamClass('stream{}'.format(i)) stream_class.clock = clock # create one default event class event_class_cont = btw.EventClass('switch_infcont') event_class_prev = btw.EventClass('switch_infprev') event_class_next = btw.EventClass('switch_infnext') event_class_hypercall = btw.EventClass('hypercall') event_class_hypercall2 = btw.EventClass('hypercall2') event_class_hypercall_version = btw.EventClass('hypercall_version') event_class_hypercall_version_return = btw.EventClass('hypercall_version_return') event_class_running_runnable = btw.EventClass('running_to_runnable') event_class_runnable_running = btw.EventClass('runnable_to_running') event_class_running_block = btw.EventClass('running_to_blocked') event_class_blocked_runnable = btw.EventClass('blocked_to_runnable') # create one 32-bit signed integer field int32_field_decl = btw.IntegerFieldDeclaration(32) int32_field_decl.signed = True # create one 32-bit signed integer field int64_field_decl = btw.IntegerFieldDeclaration(64) int64_field_decl.signed = True # add this field declaration to our event class event_class_blocked_runnable.add_field(int32_field_decl, 'dom') event_class_blocked_runnable.add_field(int32_field_decl, 'vcpu') event_class_running_block.add_field(int32_field_decl, 'dom') event_class_running_block.add_field(int32_field_decl, 'vcpu') event_class_runnable_running.add_field(int32_field_decl, 'dom') event_class_runnable_running.add_field(int32_field_decl, 'vcpu') event_class_running_runnable.add_field(int32_field_decl, 'dom') event_class_running_runnable.add_field(int32_field_decl, 'vcpu') event_class_cont.add_field(int32_field_decl, 'dom') event_class_cont.add_field(int32_field_decl, 'vcpu') event_class_prev.add_field(int32_field_decl, 'dom') event_class_prev.add_field(int32_field_decl, 'vcpu') event_class_next.add_field(int32_field_decl, 'dom') event_class_next.add_field(int32_field_decl, 'vcpu') event_class_hypercall.add_field(int32_field_decl, 'op') event_class_hypercall2.add_field(int32_field_decl, 'op') event_class_hypercall_version.add_field(int32_field_decl, 'id') event_class_hypercall_version_return.add_field(int32_field_decl, 'id') event_types[i]['switch_infcont'] = event_class_cont event_types[i]['switch_infprev'] = event_class_prev event_types[i]['switch_infnext'] = event_class_next event_types[i]['hypercall'] = event_class_hypercall event_types[i]['hypercall2'] = event_class_hypercall2 event_types[i]['hypercall_version'] = event_class_hypercall_version event_types[i]['hypercall_version_return'] = event_class_hypercall_version_return event_types[i]['blocked_to_runnable'] = event_class_blocked_runnable event_types[i]['running_to_blocked'] = event_class_running_block event_types[i]['runnable_to_running'] = event_class_runnable_running event_types[i]['running_to_runnable'] = event_class_running_runnable # register our event class to our stream class stream_class.add_event_class(event_class_cont) stream_class.add_event_class(event_class_prev) stream_class.add_event_class(event_class_next) stream_class.add_event_class(event_class_hypercall) stream_class.add_event_class(event_class_hypercall2) stream_class.add_event_class(event_class_hypercall_version) stream_class.add_event_class(event_class_hypercall_version_return) stream_class.add_event_class(event_class_running_block) stream_class.add_event_class(event_class_blocked_runnable) stream_class.add_event_class(event_class_running_runnable) stream_class.add_event_class(event_class_runnable_running) stream_class.packet_context_type.add_field(int32_field_decl, 'cpu_id') streams.append(writer.create_stream(stream_class)) streams[-1].packet_context.field('cpu_id').value = i used_streams = set() done = False while not done: time = 2 ** 64 e = None selected_s = None for s in trace: if len(s) > 0: temp = s[0] if temp["timestamp"] < time: e = temp time = e["timestamp"] selected_s = s if e is None: done = True break else: e = selected_s.pop(0) event = None cpu = e["cpu"] if e["name"] == "switch_infcont": event = btw.Event(event_types[cpu]["switch_infcont"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "switch_infnext": event = btw.Event(event_types[cpu]["switch_infnext"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "switch_infprev": event = btw.Event(event_types[cpu]["switch_infprev"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "blocked_to_runnable": event = btw.Event(event_types[cpu]["blocked_to_runnable"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "running_to_blocked": event = btw.Event(event_types[cpu]["running_to_blocked"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "runnable_to_running": event = btw.Event(event_types[cpu]["runnable_to_running"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "running_to_runnable": event = btw.Event(event_types[cpu]["running_to_runnable"]) event.payload('dom').value = e["dom"] event.payload('vcpu').value = e["vcpu"] elif e["name"] == "hypercall_op": class_ = event_types[cpu]["hypercall"] event = btw.Event(event_types[cpu]["hypercall"]) #print("cpu={}' class={} ev={}".format(cpu, class_, event)) event.payload('op').value = e["op"] elif e["name"] == "hypercall_op2": event = btw.Event(event_types[cpu]["hypercall2"]) event.payload('op').value = e["op"] elif e["name"] == "hypercall_version": event = btw.Event(event_types[cpu]["hypercall_version"]) event.payload('id').value = e["id"] used_streams.add(cpu) stream = streams[cpu] if event != None: clock.time = to_ns(e["timestamp"]) stream.append_event(event) if e["name"] == "hypercall_version": event = btw.Event(event_types[cpu]["hypercall_version_return"]) event.payload('id').value = e["id"] stream.append_event(event) # flush the stream print('trace path: {}'.format(trace_path)) for s in used_streams: streams[s].flush()