(self, arch, options)
| 150 | self.callee_ticks[callee] += 1 |
| 151 | |
| 152 | def PrintAnnotated(self, arch, options): |
| 153 | if self.self_ticks_map is None: |
| 154 | ticks_map = [] |
| 155 | else: |
| 156 | ticks_map = self.self_ticks_map.items() |
| 157 | # Convert the ticks map to offsets and counts arrays so that later |
| 158 | # we can do binary search in the offsets array. |
| 159 | ticks_map.sort(key=lambda t: t[0]) |
| 160 | ticks_offsets = [t[0] for t in ticks_map] |
| 161 | ticks_counts = [t[1] for t in ticks_map] |
| 162 | # Get a list of disassembled lines and their addresses. |
| 163 | lines = self._GetDisasmLines(arch, options) |
| 164 | if len(lines) == 0: |
| 165 | return |
| 166 | # Print annotated lines. |
| 167 | address = lines[0][0] |
| 168 | total_count = 0 |
| 169 | for i in range(len(lines)): |
| 170 | start_offset = lines[i][0] - address |
| 171 | if i == len(lines) - 1: |
| 172 | end_offset = self.end_address - self.start_address |
| 173 | else: |
| 174 | end_offset = lines[i + 1][0] - address |
| 175 | # Ticks (reported pc values) are not always precise, i.e. not |
| 176 | # necessarily point at instruction starts. So we have to search |
| 177 | # for ticks that touch the current instruction line. |
| 178 | j = bisect.bisect_left(ticks_offsets, end_offset) |
| 179 | count = 0 |
| 180 | for offset, cnt in reversed(zip(ticks_offsets[:j], ticks_counts[:j])): |
| 181 | if offset < start_offset: |
| 182 | break |
| 183 | count += cnt |
| 184 | total_count += count |
| 185 | percent = 100.0 * count / self.self_ticks |
| 186 | offset = lines[i][0] |
| 187 | if percent >= 0.01: |
| 188 | # 5 spaces for tick count |
| 189 | # 1 space following |
| 190 | # 1 for '|' |
| 191 | # 1 space following |
| 192 | # 6 for the percentage number, incl. the '.' |
| 193 | # 1 for the '%' sign |
| 194 | # => 15 |
| 195 | print("%5d | %6.2f%% %x(%d): %s" % (count, percent, offset, offset, lines[i][1])) |
| 196 | else: |
| 197 | print("%s %x(%d): %s" % (" " * 15, offset, offset, lines[i][1])) |
| 198 | print() |
| 199 | assert total_count == self.self_ticks, \ |
| 200 | "Lost ticks (%d != %d) in %s" % (total_count, self.self_ticks, self) |
| 201 | |
| 202 | def __str__(self): |
| 203 | return "%s [0x%x, 0x%x) size: %d origin: %s" % ( |
no test coverage detected