Skip to content
Merged
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
5 changes: 4 additions & 1 deletion austin/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ def update(self, sample: AustinSample) -> None:
by using :func:`Sample.parse` on a sample string passed by Austin to
the sample callback.
"""
if self.stats_type in {AustinStatsType.WALL, AustinStatsType.CPU}:
if self.stats_type is AustinStatsType.WALL:
metric = sample.metrics.time
elif self.stats_type is AustinStatsType.CPU:
# In full mode, idle samples contribute wall time but no CPU time
metric = None if sample.idle else sample.metrics.time
elif (
self.stats_type is AustinStatsType.MEMORY_ALLOC
and sample.metrics.memory is not None
Expand Down
37 changes: 37 additions & 0 deletions test/stats/test_austin_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from copy import deepcopy

from austin.events import AustinFrame
from austin.events import AustinMetadata
from austin.events import AustinMetrics
from austin.events import AustinSample
from austin.format.collapsed_stack import AustinFileReader
Expand Down Expand Up @@ -348,3 +349,39 @@ def test_deepcopy():
cloned_stats = deepcopy(stats)
assert cloned_stats == stats
assert cloned_stats is not stats


def test_load_full_mode_cpu_excludes_idle():
frames = (AustinFrame("foo_module.py", "foo", 10),)
stats = AustinStats.load(
iter(
[
AustinMetadata("mode", "full"),
AustinSample(
pid=42,
iid=0,
thread="0x7f45645646",
metrics=AustinMetrics(time=100, memory=10),
frames=frames,
idle=False,
),
AustinSample(
pid=42,
iid=0,
thread="0x7f45645646",
metrics=AustinMetrics(time=900, memory=-5),
frames=frames,
idle=True,
),
]
)
)

def total(stats_type: AustinStatsType) -> int:
thread_info = ThreadInfo("0x7f45645646", 0)
return stats[stats_type].processes[42].threads[thread_info].total

assert total(AustinStatsType.CPU) == 100
assert total(AustinStatsType.WALL) == 1000
assert total(AustinStatsType.MEMORY_ALLOC) == 10
assert total(AustinStatsType.MEMORY_DEALLOC) == 5
Loading