Skip to content

Commit

Permalink
fix(stats): more robust frame parsing
Browse files Browse the repository at this point in the history
The previous frame parsing logic was wrong and therefore was not
handling certain paths, especially those on Windows, correctly.
As a consequence, sample files collected on Windows would fail to
parse with the tools provided by the library, like austin2speedscope.

Fixes #6.
  • Loading branch information
P403n1x87 committed Apr 27, 2022
1 parent 0c89db1 commit d6c5de7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions austin/format/speedscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from austin.stats import MetricType
from austin.stats import Sample

__version__ = "0.2.1"

SpeedscopeJson = Dict
SpeedscopeWeight = int
ProfileName = str
Expand Down Expand Up @@ -158,7 +160,7 @@ def asdict(self) -> SpeedscopeJson:
key=lambda p: p["name"].rsplit(maxsplit=1)[-1],
),
"name": self.name,
"exporter": "Austin2Speedscope Converter 0.2.0",
"exporter": f"Austin2Speedscope Converter {__version__}",
}

def dump(self, stream: TextIO) -> None:
Expand Down Expand Up @@ -196,7 +198,7 @@ def main() -> None:
"--indent", type=int, help="Give a non-null value to prettify the JSON output."
)

arg_parser.add_argument("-V", "--version", action="version", version="0.1.0")
arg_parser.add_argument("-V", "--version", action="version", version=__version__)

args = arg_parser.parse_args()

Expand Down
2 changes: 1 addition & 1 deletion austin/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def parse(frame: str) -> "Frame":
raise InvalidFrame(frame)

try:
module, function, line = frame.rsplit(":", maxsplit=3)
module, function, line = frame.rsplit(":", maxsplit=2)
except ValueError:
raise InvalidFrame(frame) from None
return Frame(function, module, int(line))
Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"3.9",
"3.10",
]
REQUESTED_PYTHON_VERSION = os.getenv("PYTHON") or SUPPORTED_PYTHON_VERSIONS
REQUESTED_PYTHON_VERSION = os.getenv("PYTHON") or SUPPORTED_PYTHON_VERSIONS[-1]

if sys.platform == "win32":
PYTEST_OPTIONS = ["-vvvs"]
Expand Down Expand Up @@ -83,7 +83,7 @@ def mypy(session):
)


@nox.session(python="3.8")
@nox.session(python="3.9")
def coverage(session):
"""Upload coverage data."""
install_with_constraints(session, "coverage[toml]", "codecov")
Expand Down
2 changes: 1 addition & 1 deletion test/data/austin.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,5 @@
}
],
"name": "austin.out",
"exporter": "Austin2Speedscope Converter 0.2.0"
"exporter": "Austin2Speedscope Converter 0.2.1"
}
6 changes: 6 additions & 0 deletions test/stats/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ def test_frame_parser_invalid():

def test_frame_str():
assert str(Frame("foo", "foo_module", 10)) == "foo_module:foo:10"


def test_frame_win_drive():
assert Frame.parse("C:\\user\\bar.py:foo:42") == Frame(
"foo", "C:\\user\\bar.py", 42
)

0 comments on commit d6c5de7

Please sign in to comment.