diff --git a/austin/format/mojo.py b/austin/format/mojo.py index 01bc3d5..523cbec 100644 --- a/austin/format/mojo.py +++ b/austin/format/mojo.py @@ -333,9 +333,11 @@ def read_string(self) -> str: def _emit_metrics(self) -> t.Generator[t.Union[MojoEvent, int], None, None]: """Emit metrics.""" if self._metrics: - yield MojoFullMetrics( - self._metrics - ) if self._full_mode else self._metrics.pop() + yield ( + MojoFullMetrics(self._metrics) + if self._full_mode + else self._metrics.pop() + ) self._metrics.clear() @handles(MojoEvents.METADATA) diff --git a/austin/format/speedscope.py b/austin/format/speedscope.py index 28a6f5e..75944ca 100644 --- a/austin/format/speedscope.py +++ b/austin/format/speedscope.py @@ -22,6 +22,7 @@ # along with this program. If not, see . import json +import time from dataclasses import asdict from dataclasses import dataclass from dataclasses import field @@ -207,25 +208,47 @@ def main() -> None: args = arg_parser.parse_args() + start_time = time.monotonic() try: with AustinFileReader(args.input) as fin: mode = fin.metadata["mode"] + size_bytes = fin.file_size_bytes() speedscope = Speedscope(os.path.basename(args.input), mode, args.indent) + print( + f"Reading Austin samples from: {args.input} ({size_bytes / 1024 / 1024:,.1f} MB) ..." + ) + lines_processed = 0 + bytes_processed = 0 for line in fin: + lines_processed += 1 + bytes_processed += len(line) + if lines_processed % 1000 == 0: + # Show some progress because this can take a long time for huge traces + progress = bytes_processed / size_bytes * 100.0 + print(f"\r{progress:.1f}%", end="", flush=True) try: speedscope.add_samples( Sample.parse(line, MetricType.from_mode(mode)) ) except InvalidSample: continue + print( + "" + ) # newline after progress so that subsequent output is on its own line except FileNotFoundError: print(f"No such input file: {args.input}") exit(1) + print(f"Writing Speedscope JSON to: {args.output} ...") with open(args.output, "w") as fout: speedscope.dump(fout) + print( + "Conversion complete - total duration: %s" + % time.strftime("%Hh %Mm %Ss", time.gmtime(time.monotonic() - start_time)) + ) + if __name__ == "__main__": main() diff --git a/austin/stats.py b/austin/stats.py index 06cf469..0688327 100644 --- a/austin/stats.py +++ b/austin/stats.py @@ -22,6 +22,7 @@ # along with this program. If not, see . import dataclasses +import os.path import re from copy import deepcopy from dataclasses import dataclass @@ -411,6 +412,9 @@ def _read_meta(self) -> None: break self.metadata.add(line) + def file_size_bytes(self) -> int: + return os.path.getsize(self.file) + def __enter__(self) -> "AustinFileReader": """Open the Austin file and read the metadata.""" self._stream = open(self.file, "r")