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

perf: avoid repeatedly re-parsing frames #27

Merged
merged 5 commits into from
Nov 20, 2023
Merged
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
11 changes: 8 additions & 3 deletions austin/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ def parse(metrics: str, metric_type: Optional[MetricType] = None) -> List["Metri
ms = [int(_) for _ in metrics.split(",")]
if len(ms) == 3:
return [
# CPU time
Metric(MetricType.TIME, ms[0] if ms[1] == 0 else 0),
# Wall time
Metric(MetricType.TIME, ms[0]),
# Memory allocation
Metric(MetricType.MEMORY, ms[2] if ms[2] >= 0 else 0),
# Memory deallocation
Metric(MetricType.MEMORY, -ms[2] if ms[2] < 0 else 0),
]
elif len(ms) != 1:
Expand Down Expand Up @@ -260,14 +264,15 @@ def parse(sample: str, metric_type: Optional[MetricType] = None) -> List["Sample

try:
ms = Metric.parse(metrics, metric_type)
frames_parsed = (
[Frame.parse(frame) for frame in frames.split(";")] if frames else []
)
return [
Sample(
pid=int(pid),
thread=thread,
metric=metric,
frames=[Frame.parse(frame) for frame in frames.split(";")]
if frames
else [],
frames=frames_parsed,
)
for metric in ms
]
Expand Down
Loading