[PATCH] D81642: [analyzer] CmpRuns.py: Fix error due to statistics differences

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 11 03:37:19 PDT 2020


vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.
vsavchenko added a parent revision: D80517: [analyzer] CmpRuns.py: Refactor and add type annotations.
vsavchenko added a child revision: D81563: [analyzer] SATest: Move from csv to json project maps.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81642

Files:
  clang/utils/analyzer/CmpRuns.py


Index: clang/utils/analyzer/CmpRuns.py
===================================================================
--- clang/utils/analyzer/CmpRuns.py
+++ clang/utils/analyzer/CmpRuns.py
@@ -398,16 +398,18 @@
     stats_old = derive_stats(results_old)
     stats_new = derive_stats(results_new)
 
-    keys = sorted(stats_old.keys())
+    old_keys = set(stats_old.keys())
+    new_keys = set(stats_new.keys())
+    keys = sorted(old_keys & new_keys)
 
-    # FIXME: stats_old and stats_new are not necessarily sharing all of their
-    #        stats and can crash when stats_new doesn't have/removed some
     for key in keys:
         print(key)
 
-        for kkey in stats_old[key]:
-            val_old = float(stats_old[key][kkey])
-            val_new = float(stats_new[key][kkey])
+        nested_keys = sorted(set(stats_old[key]) & set(stats_new[key]))
+
+        for nested_key in nested_keys:
+            val_old = float(stats_old[key][nested_key])
+            val_new = float(stats_new[key][nested_key])
 
             report = f"{val_old:.3f} -> {val_new:.3f}"
 
@@ -420,7 +422,17 @@
                     elif ratio > 0.2:
                         report = Colors.RED + report + Colors.CLEAR
 
-            print(f"\t {kkey} {report}")
+            print(f"\t {nested_key} {report}")
+
+    removed_keys = old_keys - new_keys
+    if removed_keys:
+        print(f"REMOVED statistics: {removed_keys}")
+
+    added_keys = new_keys - old_keys
+    if added_keys:
+        print(f"ADDED statistics: {added_keys}")
+
+    print()
 
 
 def dump_scan_build_results_diff(dir_old: str, dir_new: str,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81642.270092.patch
Type: text/x-patch
Size: 1600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200611/04349956/attachment-0001.bin>


More information about the cfe-commits mailing list