Skip to content

Commit

Permalink
feat(format): add support for MOJO v3
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 committed Sep 10, 2023
1 parent 36871cc commit 0ff93fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 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
11 changes: 10 additions & 1 deletion test/format/test_mojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 0ff93fe

Please sign in to comment.