Skip to content

Commit c9079c5

Browse files
committed
add OutputRecord.event_chains_at_time
1 parent 8ec6bc0 commit c9079c5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mp_reader/malloc_stats.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,22 @@ def event_chains(self) -> list[list[int]]:
551551
complete.extend(open_chains.values())
552552
return complete
553553

554+
def event_chains_at_time(self, eid_cutoff: int) -> list[list[int]]:
555+
"""Returns each chain of events: the allocation, followed by any reallocs, followed by any free (if one exists)
556+
557+
Returns only the chains that were alive at the time of the given event
558+
"""
559+
560+
def is_alive(chain: list[int]) -> bool:
561+
start_eid = chain[0]
562+
end_eid = chain[-1]
563+
is_released = self.event_table[end_eid].type == EventType.FREE
564+
return start_eid <= eid_cutoff and (
565+
(not is_released) or eid_cutoff <= end_eid
566+
)
567+
568+
return list(filter(is_alive, self.event_chains()))
569+
554570
@dataclass
555571
class ObjectTree:
556572
type_name: str

0 commit comments

Comments
 (0)