0

How would you convert the BabelTrace ClockSnapshot into something printable in Python?

For example in:

@bt2.plugin_component_class
class MyFirstSink(bt2._UserSinkComponent):
    def __init__(self, config, params, obj):
        self._port = self._add_input_port("some-name")

    def _user_graph_is_configured(self):
        self._it = self._create_message_iterator(self._port)

    def _user_consume(self):
        # Consume one message and print it.
        msg = next(self._it)

        if type(msg) is bt2._StreamBeginningMessageConst:
            print("Stream beginning")
        elif type(msg) is bt2._PacketBeginningMessageConst:
            print("Packet beginning")
        elif type(msg) is bt2._EventMessageConst:
            ts = msg.default_clock_snapshot.value
            # These variants will not give correct time:
            # ts0 = ts / 1000000000
            # ts1 = datetime.datetime.fromtimestamp(ts0).strftime('%Y-%m-%d %H:%M:%S.%f')
            # ts2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ts0))

1 Answers1

0

I should use: msg.default_clock_snapshot.ns_from_origin instead of msg.default_clock_snapshot.value