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

Show progress in austin2speedscope #32

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions austin/format/mojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions austin/format/speedscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import json
import time
from dataclasses import asdict
from dataclasses import dataclass
from dataclasses import field
Expand Down Expand Up @@ -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()
4 changes: 4 additions & 0 deletions austin/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import dataclasses
import os.path
import re
from copy import deepcopy
from dataclasses import dataclass
Expand Down Expand Up @@ -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")
Expand Down
Loading