MCPcopy Create free account
hub / github.com/Da1sypetals/SnapViewer / process_alloc_data

Function process_alloc_data

convert_snap.py:56–192  ·  view source on GitHub ↗

Processes the device trace into a structured format showing allocations over time. Args: device_trace (list): List of memory events. plot_segments (bool): Whether to consider segment-based allocations. Returns: dict: A dictionary containing memory timeline data

(device_trace)

Source from the content-addressed store, hash-verified

54
55
56def process_alloc_data(device_trace):
57 """
58 Processes the device trace into a structured format showing allocations over time.
59
60 Args:
61 device_trace (list): List of memory events.
62 plot_segments (bool): Whether to consider segment-based allocations.
63
64 Returns:
65 dict: A dictionary containing memory timeline data.
66 """
67 elements = []
68 initially_allocated = []
69 actions = []
70 addr_to_alloc = {}
71
72 # Define which actions are treated as allocations/frees
73 free_actions = {"free", "free_completed"}
74
75 logging.info("Processing events")
76 for idx, event in tqdm(enumerate(device_trace)):
77 if event["action"] == "alloc":
78 # If current action is allocation, Register allocation event
79 elements.append(event)
80 addr_to_alloc[event["addr"]] = len(elements) - 1
81 actions.append(len(elements) - 1)
82 elif event["action"] in free_actions:
83 # If current action is free
84 # Handle free events, potentially unmatched ones
85 if event["addr"] in addr_to_alloc:
86 actions.append(addr_to_alloc[event["addr"]])
87 del addr_to_alloc[event["addr"]]
88 else:
89 elements.append(event)
90 initially_allocated.append(len(elements) - 1)
91 actions.append(len(elements) - 1)
92
93 # Data structures for building the memory timeline
94 current = []
95 current_data = []
96 data = []
97 max_size = 0
98 total_mem = 0
99 total_summarized_mem = 0
100 timestep = 0
101 max_at_time = []
102
103 # Special summarized memory track
104 summarized_mem = {
105 "elem": "summarized",
106 "timesteps": [],
107 "offsets": [total_mem],
108 "size": [],
109 "color": 0,
110 }
111
112 def advance(n):
113 """Advance the timeline by `n` steps, tracking summary usage."""

Callers 1

trace_to_allocation_dataFunction · 0.85

Calls 1

advanceFunction · 0.85

Tested by

no test coverage detected