(
prof_blocks: Dict[str, List[Tuple[List[ProfileData], List[MemAllocation]]]],
allocator_dict: Dict[int, str],
time_scale: TimeScale,
)
| 123 | |
| 124 | |
| 125 | def parse_prof_blocks( |
| 126 | prof_blocks: Dict[str, List[Tuple[List[ProfileData], List[MemAllocation]]]], |
| 127 | allocator_dict: Dict[int, str], |
| 128 | time_scale: TimeScale, |
| 129 | ) -> Tuple[Dict[str, List[ProfileEvent]], Dict[str, List[MemEvent]]]: |
| 130 | |
| 131 | prof_data = OrderedDict() |
| 132 | mem_prof_data = OrderedDict() |
| 133 | |
| 134 | # Iterate through all the profiling blocks data that have been grouped by name. |
| 135 | for name, data_list in prof_blocks.items(): |
| 136 | prof_data_list: List[ProfileEvent] = [] |
| 137 | mem_prof_data_list: List[MemAllocation] = [] |
| 138 | # Each entry in data_list is a tuple in which the first entry is profiling data |
| 139 | # and the second entry is memory allocation data, also each entry in data_list |
| 140 | # represents one iteration of a code block. |
| 141 | for i in range(len(data_list)): |
| 142 | for idx, event in enumerate(data_list[i][0]): |
| 143 | # If the event represented by the index idx already exists in the list |
| 144 | # then just append the new time entry to the duration list present in |
| 145 | # the event object. If it doesn't exist then create a new entry and add |
| 146 | # it to the list. |
| 147 | if idx < len(prof_data_list): |
| 148 | start_time, duration = adjust_time_scale(event, time_scale) |
| 149 | prof_data_list[idx].ts.append(start_time) |
| 150 | prof_data_list[idx].duration.append(duration) |
| 151 | else: |
| 152 | start_time, duration = adjust_time_scale(event, time_scale) |
| 153 | prof_data_list.append( |
| 154 | ProfileEvent( |
| 155 | event.name, |
| 156 | [start_time], |
| 157 | [duration], |
| 158 | event.chain_idx, |
| 159 | event.instruction_idx, |
| 160 | ) |
| 161 | ) |
| 162 | |
| 163 | # Collect all the memory allocation events of this iteration of the code block |
| 164 | for idx, event in enumerate(data_list[i][1]): |
| 165 | if idx >= len(mem_prof_data_list): |
| 166 | mem_prof_data_list.append(event) |
| 167 | |
| 168 | # Group all the memory allocation events based on the allocator they were |
| 169 | # allocated from. |
| 170 | alloc_sum_dict: OrderedDict[int, int] = OrderedDict() |
| 171 | for alloc in mem_prof_data_list: |
| 172 | alloc_sum_dict[alloc.allocator_id] = ( |
| 173 | alloc_sum_dict.get(alloc.allocator_id, 0) + alloc.allocation_size |
| 174 | ) |
| 175 | |
| 176 | mem_prof_sum_list: List[MemEvent] = [] |
| 177 | for allocator_id, allocation_size in alloc_sum_dict.items(): |
| 178 | mem_prof_sum_list.append( |
| 179 | MemEvent(allocator_dict[allocator_id], allocation_size) |
| 180 | ) |
| 181 | prof_data[name] = prof_data_list |
| 182 | mem_prof_data[name] = mem_prof_sum_list |
no test coverage detected