Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(format): add support for MOJO v3 #18

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading