Skip to content

Commit

Permalink
feat(format): add support for MOJO v3 (#18)
Browse files Browse the repository at this point in the history
We add support for the version 3 of the MOJO binary spec, which adds
support for sub-interpreter identification.
  • Loading branch information
P403n1x87 authored Sep 11, 2023
1 parent c6867e9 commit bdee9ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions austin/format/mojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions test/format/test_mojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

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
Expand Down Expand Up @@ -161,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"

0 comments on commit bdee9ba

Please sign in to comment.