Group the counters by the suffix of their name. Since the same code-level counter (for instance "X") can result in several variables in the binary counters file that differ only by a two-character prefix (for instance "c:X" and "t:X") counters are grouped by suffix and then displaye
(self)
| 178 | self.RebuildMainWindow(counters) |
| 179 | |
| 180 | def ComputeCounters(self): |
| 181 | """Group the counters by the suffix of their name. |
| 182 | |
| 183 | Since the same code-level counter (for instance "X") can result in |
| 184 | several variables in the binary counters file that differ only by a |
| 185 | two-character prefix (for instance "c:X" and "t:X") counters are |
| 186 | grouped by suffix and then displayed with custom formatting |
| 187 | depending on their prefix. |
| 188 | |
| 189 | Returns: |
| 190 | A mapping from suffixes to a list of counters with that suffix, |
| 191 | sorted by prefix. |
| 192 | """ |
| 193 | names = {} |
| 194 | for i in range(self.data.CountersInUse()): |
| 195 | counter = self.data.Counter(i) |
| 196 | name = counter.Name() |
| 197 | names[name] = counter |
| 198 | |
| 199 | # By sorting the keys we ensure that the prefixes always come in the |
| 200 | # same order ("c:" before "t:") which looks more consistent in the |
| 201 | # ui. |
| 202 | sorted_keys = names.keys() |
| 203 | sorted_keys.sort() |
| 204 | |
| 205 | # Group together the names whose suffix after a ':' are the same. |
| 206 | groups = {} |
| 207 | for name in sorted_keys: |
| 208 | counter = names[name] |
| 209 | if ":" in name: |
| 210 | name = name[name.find(":")+1:] |
| 211 | if not name in groups: |
| 212 | groups[name] = [] |
| 213 | groups[name].append(counter) |
| 214 | |
| 215 | return groups |
| 216 | |
| 217 | def RebuildMainWindow(self, groups): |
| 218 | """Tear down and rebuild the main window. |
no test coverage detected