From 0ff93fe3766f0b16d909ae5aa6e113998c51984e Mon Sep 17 00:00:00 2001 From: "Gabriele N. Tornetta" Date: Sun, 10 Sep 2023 11:45:49 +0100 Subject: [PATCH] feat(format): add support for MOJO v3 We add support for the version 3 of the MOJO binary spec, which adds support for sub-interpreter identification. --- austin/format/mojo.py | 13 +++++++++++-- test/format/test_mojo.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/austin/format/mojo.py b/austin/format/mojo.py index 2695b1d..a9925a3 100644 --- a/austin/format/mojo.py +++ b/austin/format/mojo.py @@ -135,11 +135,18 @@ class MojoStack(MojoEvent): """MOJO stack.""" pid: int + iid: int tid: str def to_austin(self) -> str: """Convert the event to Austin format.""" - return f"P{self.pid};T{int(self.tid, 16)}" + try: + tid = int(self.tid, 16) + except ValueError: + tid = self.tid + return ( + f"P{self.pid};T{self.iid}:{tid}" if self.iid >= 0 else f"P{self.pid};T{tid}" + ) @dataclass(frozen=True, eq=True) @@ -325,7 +332,9 @@ def parse_stack(self) -> t.Generator[t.Union[MojoEvent, int], None, None]: yield from self._emit_metrics() self._pid = pid = self.read_int() - yield MojoStack(pid, self.read_string()) + iid = self.read_int() if self.mojo_version >= 3 else -1 + + yield MojoStack(pid, iid, self.read_string()) def _lookup_string(self) -> MojoString: n = self.read_int() diff --git a/test/format/test_mojo.py b/test/format/test_mojo.py index af3c301..cf47bed 100644 --- a/test/format/test_mojo.py +++ b/test/format/test_mojo.py @@ -29,7 +29,11 @@ import pytest -from austin.format.mojo import MojoFile, MojoFrame, MojoString, MojoStringReference +from austin.format.mojo import MojoFile +from austin.format.mojo import MojoFrame +from austin.format.mojo import MojoStack +from austin.format.mojo import MojoString +from austin.format.mojo import MojoStringReference from austin.format.mojo import main from austin.format.mojo import to_varint @@ -158,3 +162,8 @@ def test_mojo_column_info(): column_end=17, ), } + + +def test_mojo_stack(): + assert MojoStack(1, -1, "noiid").to_austin() == "P1;Tnoiid" + assert MojoStack(1, 2, "iid").to_austin() == "P1;T2:iid"