From 2bca0d6f2ec866bc9636a4d3113b9673b69a1092 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:24:11 +0000 Subject: [PATCH 1/4] 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. --- austin/stats.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/austin/stats.py b/austin/stats.py index 06cf469..9954fe2 100644 --- a/austin/stats.py +++ b/austin/stats.py @@ -149,10 +149,10 @@ def parse(metrics: str, metric_type: Optional[MetricType] = None) -> List["Metri ms = [int(_) for _ in metrics.split(",")] if len(ms) == 3: return [ - Metric(MetricType.TIME, ms[0] if ms[1] == 0 else 0), - Metric(MetricType.TIME, ms[0]), - Metric(MetricType.MEMORY, ms[2] if ms[2] >= 0 else 0), - Metric(MetricType.MEMORY, -ms[2] if ms[2] < 0 else 0), + Metric(MetricType.TIME, ms[0] if ms[1] == 0 else 0), # cpu time + Metric(MetricType.TIME, ms[0]), # wall time + Metric(MetricType.MEMORY, ms[2] if ms[2] >= 0 else 0), # memory allocation + Metric(MetricType.MEMORY, -ms[2] if ms[2] < 0 else 0), # memory deallocation ] elif len(ms) != 1: raise ValueError() @@ -260,14 +260,13 @@ def parse(sample: str, metric_type: Optional[MetricType] = None) -> List["Sample try: ms = Metric.parse(metrics, metric_type) + frames = [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, ) for metric in ms ] From ca93bd3ec492af22cb44559736b82c46daf3cea0 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:44:39 +0000 Subject: [PATCH 2/4] Avoid changing the type of existing variable `frames` --- austin/stats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/austin/stats.py b/austin/stats.py index 9954fe2..9f24b01 100644 --- a/austin/stats.py +++ b/austin/stats.py @@ -260,13 +260,13 @@ def parse(sample: str, metric_type: Optional[MetricType] = None) -> List["Sample try: ms = Metric.parse(metrics, metric_type) - frames = [Frame.parse(frame) for frame in frames.split(";")] if frames else [] + frames_parsed = [Frame.parse(frame) for frame in frames.split(";")] if frames else [] return [ Sample( pid=int(pid), thread=thread, metric=metric, - frames=frames, + frames=frames_parsed, ) for metric in ms ] From 533694fb33668ae402d3686b38426418e67e775c Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:28:31 +0000 Subject: [PATCH 3/4] Code formatting --- austin/stats.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/austin/stats.py b/austin/stats.py index 9f24b01..89d45d1 100644 --- a/austin/stats.py +++ b/austin/stats.py @@ -149,10 +149,14 @@ def parse(metrics: str, metric_type: Optional[MetricType] = None) -> List["Metri ms = [int(_) for _ in metrics.split(",")] if len(ms) == 3: return [ - Metric(MetricType.TIME, ms[0] if ms[1] == 0 else 0), # cpu time - Metric(MetricType.TIME, ms[0]), # wall time - Metric(MetricType.MEMORY, ms[2] if ms[2] >= 0 else 0), # memory allocation - Metric(MetricType.MEMORY, -ms[2] if ms[2] < 0 else 0), # memory deallocation + # 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: raise ValueError() From 88ca0849dbdf8fa22193271b94409d4fb835803f Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:26:41 +0000 Subject: [PATCH 4/4] Moar black --- austin/stats.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/austin/stats.py b/austin/stats.py index c11c2c8..ca71d68 100644 --- a/austin/stats.py +++ b/austin/stats.py @@ -264,7 +264,9 @@ 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 [] + frames_parsed = ( + [Frame.parse(frame) for frame in frames.split(";")] if frames else [] + ) return [ Sample( pid=int(pid),