Exemplo n.º 1
0
 def test_iter_custom_filter(self):
     src_spec = bt2.ComponentSpec('ctf', 'fs',
                                  _3EVENTS_INTERSECT_TRACE_PATH)
     flt_spec = bt2.ComponentSpec('utils', 'trimmer', {
         'end': 13515309000000075,
     })
     notif_iter = bt2.TraceCollectionNotificationIterator(
         src_spec, flt_spec, notification_types=[bt2.EventNotification])
     self.assertEqual(len(list(notif_iter)), 5)
Exemplo n.º 2
0
 def test_iter_no_intersection_end(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     notif_iter = bt2.TraceCollectionNotificationIterator(
         specs,
         notification_types=[bt2.EventNotification],
         end=13515309.000000075)
     self.assertEqual(len(list(notif_iter)), 5)
Exemplo n.º 3
0
 def test_iter_intersection_subscribe(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     notif_iter = bt2.TraceCollectionNotificationIterator(
         specs,
         stream_intersection_mode=True,
         notification_types=[bt2.EventNotification])
     self.assertEqual(len(list(notif_iter)), 3)
Exemplo n.º 4
0
 def test_iter_intersection_subscribe(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     msg_iter = bt2.TraceCollectionMessageIterator(
         specs,
         stream_intersection_mode=True,
         message_types=[bt2.EventMessage])
     self.assertEqual(len(list(msg_iter)), 3)
Exemplo n.º 5
0
    def test_iter_intersection_no_path_param(self):
        specs = [bt2.ComponentSpec('text', 'dmesg', {'read-from-stdin': True})]

        with self.assertRaises(bt2.Error):
            notif_iter = bt2.TraceCollectionNotificationIterator(
                specs,
                stream_intersection_mode=True,
                notification_types=[bt2.EventNotification])
Exemplo n.º 6
0
    def test_iter_intersection_no_path_param(self):
        specs = [bt2.ComponentSpec('text', 'dmesg', {'read-from-stdin': True})]

        with self.assertRaises(bt2.Error):
            msg_iter = bt2.TraceCollectionMessageIterator(
                specs,
                stream_intersection_mode=True,
                message_types=[bt2.EventMessage])
Exemplo n.º 7
0
 def _get_trace_notifs(self):
     del self._cc
     del self._sc
     del self._ec
     del self._stream
     del self._writer
     specs = [bt2.ComponentSpec('ctf', 'fs', self._trace_path)]
     notif_iter = bt2.TraceCollectionNotificationIterator(specs)
     return list(notif_iter)
 def test_debug_info(self):
     debug_info_data_dir = os.environ['DEBUG_INFO_DATA_DIR']
     trace_path = os.path.join(debug_info_data_dir, 'trace')
     target_prefix = os.path.join(debug_info_data_dir, '..', '..')
     src = bt2.ComponentSpec('ctf', 'fs', trace_path)
     flt = bt2.ComponentSpec('lttng-utils', 'debug-info', {
         'target-prefix': target_prefix,
     })
     it = bt2.TraceCollectionNotificationIterator(src, flt,
                                                  [bt2.EventNotification])
     notifs = list(it)
     debug_info = notifs[2].event['debug_info']
     self.assertEqual(debug_info['bin'], 'libhello_so+0x14d4')
     self.assertEqual(debug_info['func'], 'foo+0xa9')
     self.assertEqual(debug_info['src'], 'libhello.c:7')
     debug_info = notifs[3].event['debug_info']
     self.assertEqual(debug_info['bin'], 'libhello_so+0x15a6')
     self.assertEqual(debug_info['func'], 'bar+0xa9')
     self.assertEqual(debug_info['src'], 'libhello.c:13')
    def _get_event_declarations(self):
        notif_iter = bt2.TraceCollectionNotificationIterator(
            [bt2.ComponentSpec('ctf', 'fs', self._path)])

        # raises if the trace contains no streams
        first_notif = next(notif_iter)
        assert (type(first_notif) is bt2.StreamBeginningNotification)
        trace = first_notif.stream.stream_class.trace
        ec_iters = [sc.values() for sc in trace.values()]
        return map(reader_event_declaration._create_event_declaration,
                   itertools.chain(*ec_iters))
    def _gen_events(self, begin_s=None, end_s=None):
        specs = [
            bt2.ComponentSpec('ctf', 'fs', th.path)
            for th in self._trace_handles
        ]

        try:
            iter_cls = bt2.TraceCollectionNotificationIterator
            tc_iter = iter_cls(specs,
                               stream_intersection_mode=self._intersect_mode,
                               begin=begin_s,
                               end=end_s,
                               notification_types=[bt2.EventNotification])
            return map(reader_event._create_event, tc_iter)
        except:
            raise ValueError
Exemplo n.º 11
0
 def test_create_source_from_user(self):
     spec = bt2.ComponentSpec(_SomeSource)
     self.assertEqual(spec.component_class.name, '_SomeSource')
Exemplo n.º 12
0
 def test_create_wrong_log_level_type(self):
     with self.assertRaisesRegex(TypeError, "'str' is not an 'int' object"):
         bt2.ComponentSpec(self._dmesg_cc, logging_level='banane')
Exemplo n.º 13
0
 def test_create_source_from_plugin(self):
     spec = bt2.ComponentSpec(self._dmesg_cc)
     self.assertEqual(spec.component_class.name, 'dmesg')
Exemplo n.º 14
0
 def test_create_wrong_comp_class_type(self):
     with self.assertRaisesRegex(
             TypeError, "'int' is not a source or filter component class"):
         bt2.ComponentSpec(18)
Exemplo n.º 15
0
 def test_create_wrong_params_type(self):
     with self.assertRaisesRegex(
             TypeError,
             "cannot create value object from 'datetime' object"):
         bt2.ComponentSpec(self._dmesg_cc, params=datetime.datetime.now())
Exemplo n.º 16
0
    def test_create_wrong_end_type(self):
        specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]

        with self.assertRaises(TypeError):
            notif_iter = bt2.TraceCollectionNotificationIterator(specs,
                                                                 begin='lel')
Exemplo n.º 17
0
 def test_create_from_object_with_path_params(self):
     spec = spec = bt2.ComponentSpec(self._dmesg_cc, 'a path')
     self.assertEqual(spec.params['inputs'], ['a path'])
Exemplo n.º 18
0
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
# Iterate the trace messages.
for msg in msg_it:
    # `bt2._EventMessageConst` is the Python type of an event message.
Exemplo n.º 19
0
 def test_create_sink_from_object(self):
     with self.assertRaisesRegex(
             TypeError,
             "'_SinkComponentClassConst' is not a source or filter component class",
     ):
         bt2.ComponentSpec(self._pretty_cc)
Exemplo n.º 20
0
 def test_create_wrong_plugin_name_type(self):
     with self.assertRaises(TypeError):
         spec = bt2.ComponentSpec(23, 'compcls')
Exemplo n.º 21
0
 def test_iter_specs_not_list(self):
     spec = bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)
     notif_iter = bt2.TraceCollectionNotificationIterator(
         spec, notification_types=[bt2.EventNotification])
     self.assertEqual(len(list(notif_iter)), 8)
Exemplo n.º 22
0
 def test_create_wrong_component_class_name_type(self):
     with self.assertRaises(TypeError):
         spec = bt2.ComponentSpec('plugin', 190)
Exemplo n.º 23
0
 def test_create_begin_s(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     notif_iter = bt2.TraceCollectionNotificationIterator(
         specs, begin=19457.918232)
Exemplo n.º 24
0
    def test_create_no_such_plugin(self):
        specs = [bt2.ComponentSpec('77', '101', _3EVENTS_INTERSECT_TRACE_PATH)]

        with self.assertRaises(bt2.Error):
            notif_iter = bt2.TraceCollectionNotificationIterator(specs)
Exemplo n.º 25
0
 def test_create_filter_from_object(self):
     spec = bt2.ComponentSpec(self._muxer_cc)
     self.assertEqual(spec.component_class.name, 'muxer')
Exemplo n.º 26
0
 def test_create_from_object_with_params(self):
     spec = bt2.ComponentSpec(self._dmesg_cc, {'salut': 23})
     self.assertEqual(spec.params['salut'], 23)
Exemplo n.º 27
0
 def test_create_end_datetime(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     notif_iter = bt2.TraceCollectionNotificationIterator(
         specs, end=datetime.datetime.now())
Exemplo n.º 28
0
 def test_create_wrong_params_type(self):
     with self.assertRaises(TypeError):
         spec = bt2.ComponentSpec('dwdw', 'compcls',
                                  datetime.datetime.now())
Exemplo n.º 29
0
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)
Exemplo n.º 30
0
 def test_iter_no_intersection(self):
     specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
     notif_iter = bt2.TraceCollectionNotificationIterator(specs)
     self.assertEqual(len(list(notif_iter)), 28)