[PATCH] D120716: [Dexter] Collate penalties of the same type into a single line for each

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 05:23:40 PST 2022


StephenTozer created this revision.
StephenTozer added reviewers: Orlando, jmorse.
StephenTozer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently in Dexter, every step at which a DexExpectWatchValue/Type does
not have the correct value is printed on a separate line. This patch
reduces the size of the text output by instead printing each incorrect
result (i.e. each incorrect value seen, 'Variable optimized out', and so
on) on its own line, alongside a list of the steps at which that result
was seen. This makes for much less spam in the output when watches are
missing or wrong for many steps.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120716

Files:
  cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
  cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp


Index: cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
===================================================================
--- cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
+++ cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
@@ -30,8 +30,8 @@
 // CHECK-NEXT: address 'x_2' (0x[[X2_VAL]])
 // CHECK-NEXT: address 'y' (0x[[Y_VAL]])
 // CHECK: misordered result:
-// CHECK-NEXT: step 4 (0x[[Y_VAL]])
-// CHECK-NEXT: step 5 (0x[[X2_VAL]])
+// CHECK-NEXT: (0x[[Y_VAL]]): step 4
+// CHECK-NEXT: (0x[[X2_VAL]]): step 5
 
 int main() {
     int *x = new int(5);
Index: cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
===================================================================
--- cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
+++ cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
@@ -98,6 +98,32 @@
         metavar='<int>')
 
 
+class PenaltyLineRanges:
+    def __init__(self, first_step, penalty):
+        self.ranges = [(first_step, first_step)]
+        self.penalty = penalty
+
+    def add_step(self, next_step, penalty):
+        last_range = self.ranges[-1]
+        last_step = last_range[1]
+        if (next_step == last_step + 1):
+            self.ranges[-1] = (last_range[0], next_step)
+        else:
+            self.ranges.append((next_step, next_step))
+        self.penalty += penalty
+
+    def __str__(self):
+        range_to_str = lambda r: str(r[0]) if r[0] == r[1] else f'{r[0]}-{r[1]}'
+        if self.ranges[0][0] == self.ranges[-1][1]:
+            text = f'step {self.ranges[0][0]}'
+        else:
+            step_list = ', '.join([range_to_str(r) for r in self.ranges])
+            text = f'steps [{step_list}]'
+        if self.penalty:
+            text += ' <r>[-{}]</>'.format(self.penalty)
+        return text
+
+
 class Heuristic(object):
     def __init__(self, context, steps):
         self.context = context
@@ -456,11 +482,23 @@
             for category in sorted(pen_cmd.pen_dict):
                 lines.append('    <r>{}</>:\n'.format(category))
 
+                step_value_results = {}
+                for result, penalty in pen_cmd.pen_dict[category]:
+                    if not isinstance(result, StepValueInfo):
+                        continue
+                    if result.expected_value not in step_value_results:
+                        step_value_results[result.expected_value] = PenaltyLineRanges(result.step_index, penalty)
+                    else:
+                        step_value_results[result.expected_value].add_step(result.step_index, penalty)
+
+                for value, penalty_line_range in step_value_results.items():
+                    text = f'({value}): {penalty_line_range}'
+                    total_penalty += penalty_line_range.penalty
+                    lines.append('      {}\n'.format(text))
+
                 for result, penalty in pen_cmd.pen_dict[category]:
                     if isinstance(result, StepValueInfo):
-                        text = 'step {}'.format(result.step_index)
-                        if result.expected_value:
-                            text += ' ({})'.format(result.expected_value)
+                        continue
                     else:
                         text = str(result)
                     if penalty:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120716.412064.patch
Type: text/x-patch
Size: 3525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220301/38ed5411/attachment.bin>


More information about the llvm-commits mailing list