Skip to content

Commit

Permalink
perf: avoid repeatedly re-parsing frames (#27)
Browse files Browse the repository at this point in the history
* Avoid repeatedly re-parsing frames

This should reduce the effort on parsing frames by a factor of 4 when operating on a `--full` trace.

In that case `ms` will be a list of 4 metrics but we only need to parse the frames once because they are the same in all cases.

Also add a couple of comments which weren't obvious to me on first reading.

* Avoid changing the type of existing variable `frames`

* Code formatting

* Moar black

---------

Co-authored-by: Gabriele N. Tornetta <[email protected]>
  • Loading branch information
sparrowt and P403n1x87 authored Nov 20, 2023
1 parent 44f1c4a commit 15efbf5
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit 15efbf5

Please sign in to comment.