def translate_to_ctf(input_db, output): graph = bt2.Graph() plugin_path = os.path.join( pathlib.Path(__file__).parent, "bt_plugin_rocm.py") rocm_plugin = bt2.find_plugins_in_path(plugin_path, fail_on_load_error=True)[0] source_component = graph.add_component( rocm_plugin.source_component_classes["RocmSource"], "rocm_source", {"input": input_db}) ctf_plugin = bt2.find_plugin("ctf").sink_component_classes["fs"] sink_component = graph.add_component(ctf_plugin, "ctf_sink", { "path": output, "assume-single-trace": True }) utils_plugin = bt2.find_plugin("utils").filter_component_classes["muxer"] muxer_component = graph.add_component(utils_plugin, "muxer") for i, port in enumerate(source_component.output_ports): graph.connect_ports(source_component.output_ports[port], muxer_component.input_ports["in{}".format(i)]) graph.connect_ports(muxer_component.output_ports["out"], sink_component.input_ports["in"]) graph.run()
def translate_to_ctf(inputs, output): graph = bt2.Graph() rocm_plugin = bt2.find_plugins_in_path("./bt_plugin_rocm.py")[0] source_component = graph.add_component( rocm_plugin.source_component_classes["RocmSource"], "rocm_source", {"inputs": inputs}) ctf_plugin = bt2.find_plugin("ctf").sink_component_classes["fs"] sink_component = graph.add_component(ctf_plugin, "ctf_sink", { "path": output, "assume-single-trace": True }) utils_plugin = bt2.find_plugin("utils").filter_component_classes["muxer"] muxer_component = graph.add_component(utils_plugin, "muxer") for i, port in enumerate(source_component.output_ports): graph.connect_ports(source_component.output_ports[port], muxer_component.input_ports["in{}".format(i)]) graph.connect_ports(muxer_component.output_ports["out"], sink_component.input_ports["in"]) graph.run()
def setUp(self): # A source CC from a plugin. self._dmesg_cc = bt2.find_plugin('text').source_component_classes['dmesg'] assert self._dmesg_cc is not None # A filter CC from a plugin. self._muxer_cc = bt2.find_plugin('utils').filter_component_classes['muxer'] assert self._muxer_cc is not None # A sink CC from a plugin. self._pretty_cc = bt2.find_plugin('text').sink_component_classes['pretty'] assert self._pretty_cc is not None
def _create_trimmer(self, begin_ns, end_ns, name): plugin = bt2.find_plugin('utils') if plugin is None: raise RuntimeError( 'cannot find "utils" plugin (needed for the trimmer)') if 'trimmer' not in plugin.filter_component_classes: raise RuntimeError( 'cannot find "trimmer" filter component class in "utils" plugin' ) params = {} def ns_to_string(ns): s_part = ns // 1000000000 ns_part = ns % 1000000000 return '{}.{:09d}'.format(s_part, ns_part) if begin_ns is not None: params['begin'] = ns_to_string(begin_ns) if end_ns is not None: params['end'] = ns_to_string(end_ns) comp_cls = plugin.filter_component_classes['trimmer'] return self._graph.add_component(comp_cls, name, params)
def from_named_plugin_and_component_class( cls, plugin_name, component_class_name, params=None, obj=None, logging_level=bt2.LoggingLevel.NONE, ): plugin = bt2.find_plugin(plugin_name) if plugin is None: raise ValueError('no such plugin: {}'.format(plugin_name)) if component_class_name in plugin.source_component_classes: comp_class = plugin.source_component_classes[component_class_name] elif component_class_name in plugin.filter_component_classes: comp_class = plugin.filter_component_classes[component_class_name] else: raise KeyError( 'source or filter component class `{}` not found in plugin `{}`'.format( component_class_name, plugin_name ) ) return cls(comp_class, params, obj, logging_level)
def setUp(self): ctf = bt2.find_plugin('ctf') self._fs = ctf.source_component_classes['fs'] self._inputs = [ os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect') ]
def test_add_component_obj_non_python_comp_cls(self): plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False) assert plugin is not None cc = plugin.source_component_classes['dmesg'] assert cc is not None with self.assertRaises(ValueError): self._graph.add_component(cc, 'salut', obj=57)
def test_unconnected_port_raises(self): graph = bt2.Graph() graph.add_component( bt2.find_plugin('text').sink_component_classes['pretty'], 'snk' ) with self.assertRaisesRegex( bt2._Error, 'Single input port is not connected: port-name="in"' ): graph.run()
def _create_muxer(self): plugin = bt2.find_plugin('utils') if plugin is None: raise bt2.Error('cannot find "utils" plugin (needed for the muxer)') if 'muxer' not in plugin.filter_component_classes: raise bt2.Error('cannot find "muxer" filter component class in "utils" plugin') comp_cls = plugin.filter_component_classes['muxer'] return self._graph.add_component(comp_cls, 'muxer')
def __init__(self, intersect_mode=False): """ Creates an empty trace collection. """ self._intersect_mode = intersect_mode self._trace_handles = set() self._next_th_id = 0 self._ctf_plugin = bt2.find_plugin('ctf') assert (self._ctf_plugin is not None) self._fs_comp_cls = self._ctf_plugin.source_component_classes['fs']
def __init__(self, intersect_mode=False): """ Creates an empty trace collection. """ self._intersect_mode = intersect_mode self._trace_handles = set() self._next_th_id = 0 self._ctf_plugin = bt2.find_plugin('ctf') assert(self._ctf_plugin is not None) self._fs_comp_cls = self._ctf_plugin.source_component_classes['fs']
def test_query_with_method_obj_non_python_comp_cls(self): plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False) assert plugin is not None cc = plugin.source_component_classes['dmesg'] assert cc is not None with self.assertRaisesRegex( ValueError, re.escape(r'cannot pass a Python object to a non-Python component class'), ): bt2.QueryExecutor(cc, 'obj', method_obj=object()).query()
def _create_trimmer(self, begin, end, name): plugin = bt2.find_plugin('utils') if plugin is None: raise bt2.Error('cannot find "utils" plugin (needed for the trimmer)') if 'trimmer' not in plugin.filter_component_classes: raise bt2.Error('cannot find "trimmer" filter component class in "utils" plugin') params = {} if begin is not None: params['begin'] = begin if end is not None: params['end'] = end comp_cls = plugin.filter_component_classes['trimmer'] return self._graph.add_component(comp_cls, name, params)
def test_support_info_with_uuid(self): # Test that the right group is reported for each trace. def do_one_query(input, expected_group): qe = bt2.QueryExecutor(fs, 'babeltrace.support-info', { 'input': input, 'type': 'directory' }) result = qe.query() self.assertEqual(result['group'], expected_group) ctf = bt2.find_plugin('ctf') fs = ctf.source_component_classes['fs'] do_one_query(trace_10352_1, '21cdfa5e-9a64-490a-832c-53aca6c101ba') do_one_query(trace_10352_2, '21cdfa5e-9a64-490a-832c-53aca6c101ba') do_one_query(trace_10352_3, '21cdfa5e-9a64-490a-832c-53aca6c101ba') do_one_query(trace_10353_1, '83656eb1-b131-40e7-9666-c04ae279b58c') do_one_query(trace_10353_2, '83656eb1-b131-40e7-9666-c04ae279b58c') do_one_query(trace_10353_3, '83656eb1-b131-40e7-9666-c04ae279b58c')
def _create_comp(self, comp_spec, comp_cls_type): plugin = bt2.find_plugin(comp_spec.plugin_name) if plugin is None: raise bt2.Error('no such plugin: {}'.format(comp_spec.plugin_name)) if comp_cls_type == _CompClsType.SOURCE: comp_classes = plugin.source_component_classes else: comp_classes = plugin.filter_component_classes if comp_spec.component_class_name not in comp_classes: cc_type = 'source' if comp_cls_type == _CompClsType.SOURCE else 'filter' raise bt2.Error('no such {} component class in "{}" plugin: {}'.format(cc_type, comp_spec.plugin_name, comp_spec.component_class_name)) comp_cls = comp_classes[comp_spec.component_class_name] name = self._get_unique_comp_name(comp_spec) comp = self._graph.add_component(comp_cls, name, comp_spec.params) return comp
import datetime import sys import bt2 # Find the `ctf` plugin (shipped with Babeltrace 2). ctf_plugin = bt2.find_plugin('ctf') # Get the `source.ctf.fs` component class from the plugin. fs_cc = ctf_plugin.source_component_classes['fs'] # Create a trace collection message iterator, instantiating a single # `source.ctf.fs` component class with the `inputs` initialization # parameter set to open a single CTF trace. msg_it = bt2.TraceCollectionMessageIterator( bt2.ComponentSpec( fs_cc, { # Get the CTF trace path from the first command-line argument. 'inputs': [sys.argv[1]], })) # Iterate the trace messages. # for msg in msg_it: # # `bt2._EventMessageConst` is the Python type of an event message. # if type(msg) is bt2._EventMessageConst: # # Print event's name. # print(msg.event.name, msg.event.) # Last event's time (ns from origin). last_event_ns_from_origin = None
def _get_comp_cls_from_plugin(self): plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False) assert plugin is not None cc = plugin.source_component_classes['dmesg'] assert cc is not None return cc
def test_find_existing(self): plugin = bt2.find_plugin('ctf', find_in_user_dir=False, find_in_sys_dir=False) self.assertIsNotNone(plugin)
def test_find_existing(self): plugin = bt2.find_plugin('ctf') self.assertIsInstance(plugin, bt2.plugin._Plugin)
def test_filter_comp_classes_len(self): plugin = bt2.find_plugin('utils') self.assertEqual(len(plugin.filter_component_classes), 2)
def setUp(self): ctf = bt2.find_plugin('ctf') self._fs = ctf.source_component_classes['fs'] self._paths = [os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect')] self._executor = bt2.QueryExecutor()
def test_filter_comp_classes_len(self): plugin = bt2.find_plugin('utils', find_in_user_dir=False, find_in_sys_dir=False) self.assertEqual(len(plugin.filter_component_classes), 2)
def setUp(self): self._plugin = bt2.find_plugin('ctf', find_in_user_dir=False, find_in_sys_dir=False)
def setUp(self): self._plugin = bt2.find_plugin('ctf')
def main(): parser = argparse.ArgumentParser( description="Convert a CTF trace to a json trace viewable with google " "chrome") parser.add_argument("ctf", metavar="CTF", type=str, help="Path to the CTF trace") parser.add_argument("-o", "--output", metavar="OUT", type=str, default="trace.json", help="the output file") args = parser.parse_args() if not os.path.isdir(args.ctf): raise NotADirectoryError(args.ctf) ctf_path = None for root, dirs, files in os.walk(args.ctf): for f in files: if f == "metadata": if ctf_path is None: ctf_path = str(root) else: raise RuntimeError("%s is not a single trace (contains " "more than one metadata file!" % args.ctf) if ctf_path is None: raise RuntimeError("%s is not a CTF trace (does not contain a metadata" " file)" % args.ctf) # Find the `ctf` plugin (shipped with Babeltrace 2). ctf_plugin = bt2.find_plugin('ctf') # Get the `source.ctf.fs` component class from the plugin. fs_cc = ctf_plugin.source_component_classes['fs'] # Create a trace collection message iterator, instantiating a single # `source.ctf.fs` component class with the `inputs` initialization # parameter set to open a single CTF trace. msg_it = bt2.TraceCollectionMessageIterator( bt2.ComponentSpec( fs_cc, { # Get the CTF trace path from the first command-line argument. 'inputs': [ctf_path], })) # keep a list of events to dump later to JSON trace_events = [] # Iterate the trace messages. for msg in msg_it: # `bt2._EventMessageConst` is the Python type of an event message. if type(msg) is bt2._EventMessageConst: event = msg.event if (event.name == "reactor_cpp:reaction_execution_starts"): trace_events.append(reaction_execution_starts_to_dict(msg)) elif (event.name == "reactor_cpp:reaction_execution_finishes"): trace_events.append(reaction_execution_finishes_to_dict(msg)) elif (event.name == "reactor_cpp:schedule_action"): trace_events.append(schedule_action_to_dict(msg)) elif (event.name == "reactor_cpp:trigger_reaction"): trace_events.append(trigger_reaction_to_dict(msg)) # add some metadata configure_process_name(trace_events, 0, "Execution") for i in range(1, 128): configure_thread_name(trace_events, 0, i, "Worker %d" % i) for process, pid in pid_registry.items(): configure_process_name(trace_events, pid, process) for thread, tid in tid_registry[process].items(): configure_thread_name(trace_events, pid, tid, thread) data = { "traceEvents": trace_events, "displayTimeUnit": "ns", } with open(args.output, 'w') as outfile: json.dump(data, outfile, indent=2)
def setUp(self): ctf = bt2.find_plugin('ctf') self._fs = ctf.source_component_classes['fs'] self._path = os.path.join(test_ctf_traces_path, 'succeed')
def setUp(self): ctf = bt2.find_plugin("ctf") self._fs = ctf.source_component_classes["fs"]
def test_find_none(self): plugin = bt2.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41') self.assertIsNone(plugin)