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

Handle more memray allocation types #578

Merged
merged 1 commit into from
Sep 19, 2024
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
15 changes: 13 additions & 2 deletions cubed/diagnostics/memray.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@


class AllocationType(Enum):
# integer values match memray AllocatorType
MALLOC = 1
FREE = 2
CALLOC = 3
REALLOC = 4
MMAP = 10
MUNMAP = 11


@dataclass()
Expand Down Expand Up @@ -75,6 +78,8 @@ def get_allocations_over_threshold(result_file, mem_threshold):
allocation_type = AllocationType.CALLOC
elif a.allocator == memray.AllocatorType.REALLOC:
allocation_type = AllocationType.REALLOC
elif a.allocator == memray.AllocatorType.MMAP:
allocation_type = AllocationType.MMAP
else:
raise ValueError(f"Unsupported memray.AllocatorType {a.allocator}")
allocation = Allocation(
Expand All @@ -88,13 +93,19 @@ def get_allocations_over_threshold(result_file, mem_threshold):
address_to_allocation[a.address] = allocation
yield allocation
elif (
a.allocator == memray.AllocatorType.FREE
a.allocator in (memray.AllocatorType.FREE, memray.AllocatorType.MUNMAP)
and a.address in address_to_allocation
):
if a.allocator == memray.AllocatorType.FREE:
allocation_type = AllocationType.FREE
elif a.allocator == memray.AllocatorType.MUNMAP:
allocation_type = AllocationType.MUNMAP
else:
raise ValueError(f"Unsupported memray.AllocatorType {a.allocator}")
allocation = address_to_allocation.pop(a.address)
yield Allocation(
allocation.object_id,
AllocationType.FREE,
allocation_type,
allocation.memory,
address=a.address,
)
Loading