Skip to content

Commit

Permalink
Fix reporting of "Own Memory" in TUI reporters
Browse files Browse the repository at this point in the history
The `live` and `summary` reporters include a column for the number of
bytes directly allocated by a particular function (called "Own Bytes" or
"Own Memory", with a corresponding column for the percentage of memory
directly allocated by that function).

A bug in our summation led to us undercounting and misreporting these
columns.

Signed-off-by: Matt Wozniski <[email protected]>
  • Loading branch information
godlygeek authored and pablogsal committed May 29, 2024
1 parent 0e3673d commit 667983c
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 304 deletions.
1 change: 1 addition & 0 deletions news/617.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix reporting of "Own Memory" in the ``live`` and ``summary`` reporters. A bug in our summation caused us to undercount functions' direct allocations.
14 changes: 4 additions & 10 deletions src/memray/reporters/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,17 @@ def aggregate_allocations(
frame.n_allocations += allocation.n_allocations
frame.thread_ids.add(allocation.tid)
continue
(function, file_name, _), *caller_frames = stack_trace
location = Location(function=function, file=file_name)
processed_allocations[location] = AllocationEntry(
own_memory=allocation.size,
total_memory=allocation.size,
n_allocations=allocation.n_allocations,
thread_ids={allocation.tid},
)

# Walk upwards and sum totals
visited = {location}
for function, file_name, _ in caller_frames:
visited = set()
for i, (function, file_name, _) in enumerate(stack_trace):
location = Location(function=function, file=file_name)
frame = processed_allocations[location]
if location in visited:
continue
visited.add(location)
if i == 0:
frame.own_memory += allocation.size
frame.total_memory += allocation.size
frame.n_allocations += allocation.n_allocations
frame.thread_ids.add(allocation.tid)
Expand Down
Loading

0 comments on commit 667983c

Please sign in to comment.