Skip to content

Commit

Permalink
tests: Exercise AllocationLifetimeAggregator
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and pablogsal committed Feb 24, 2023
1 parent d9b7695 commit 6686568
Show file tree
Hide file tree
Showing 3 changed files with 660 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/memray/_memray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,17 @@ class HighWaterMarkAggregatorTestHarness:
) -> None: ...
def get_current_heap_size(self) -> int: ...
def get_allocations(self) -> list[dict[str, int]]: ...

class AllocationLifetimeAggregatorTestHarness:
def add_allocation(
self,
tid: int,
address: int,
size: int,
allocator: int,
native_frame_id: int,
frame_index: int,
native_segment_generation: int,
) -> None: ...
def capture_snapshot(self) -> None: ...
def get_allocations(self) -> list[TemporalAllocationRecord]: ...
35 changes: 35 additions & 0 deletions src/memray/_memray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1201,3 +1201,38 @@ cdef class HighWaterMarkAggregatorTestHarness:
)
)
return ret


cdef class AllocationLifetimeAggregatorTestHarness:
cdef AllocationLifetimeAggregator aggregator

def add_allocation(
self,
tid,
address,
size,
allocator,
native_frame_id,
frame_index,
native_segment_generation,
):
cdef _Allocation allocation
allocation.tid = tid
allocation.address = address
allocation.size = size
allocation.allocator = <Allocator><int>allocator
allocation.native_frame_id = native_frame_id
allocation.frame_index = frame_index
allocation.native_segment_generation = native_segment_generation
allocation.n_allocations = 1
self.aggregator.addAllocation(allocation)

def capture_snapshot(self):
return self.aggregator.captureSnapshot()

def get_allocations(self):
cdef shared_ptr[RecordReader] reader
return [
create_temporal_allocation_record(lifetime, False, reader)
for lifetime in self.aggregator.generateIndex()
]
Loading

0 comments on commit 6686568

Please sign in to comment.