瀏覽代碼

profile cumulative time for all NACs

Joeri Exelmans 1 年之前
父節點
當前提交
b6a654580c
共有 1 個文件被更改,包括 30 次插入32 次删除
  1. 30 32
      transformation/rule.py

+ 30 - 32
transformation/rule.py

@@ -50,38 +50,36 @@ class RuleMatcherRewriter:
 
                     nac_matched = False
 
-                    try:
-                        for i_nac, nac in enumerate(nacs):
-                            # For every LHS-match, we see if there is a NAC-match:
-                            nac_matcher = match_od(self.state,
-                                host_m=m,
-                                host_mm=self.mm,
-                                pattern_m=nac,
-                                pattern_mm=self.mm_ramified,
-                                pivot=lhs_match) # try to "grow" LHS-match with NAC-match
-
-                            try:
-                                # for nac_match in nac_matcher:
-                                while True:
-                                    try:
-                                        with Timer(f"MATCH NAC{i_nac} {rule_name}"):
-                                            nac_match = nac_matcher.__next__()
-
-                                        raise _NAC_MATCHED()
-                                    except StopIteration:
-                                        break # no more nac-matches
-
-                                    # The NAC has at least one match
-                                    # (there could be more, but we know enough, so let's not waste CPU/MEM resources and proceed to next LHS match)
-                                    nac_matched = True
-                                    break
-                            except Exception as e:
-                                # The exception may originate from eval'ed condition-code in LHS or NAC
-                                # Decorate exception with some context, to help with debugging
-                                e.add_note(f"while matching NAC of '{rule_name}'")
-                                raise
-                    except _NAC_MATCHED:
-                        continue # continue with next LHS-match
+                    with Timer(f"MATCH NACs {rule_name}"):
+                        try:
+                            for i_nac, nac in enumerate(nacs):
+                                # For every LHS-match, we see if there is a NAC-match:
+                                nac_matcher = match_od(self.state,
+                                    host_m=m,
+                                    host_mm=self.mm,
+                                    pattern_m=nac,
+                                    pattern_mm=self.mm_ramified,
+                                    pivot=lhs_match) # try to "grow" LHS-match with NAC-match
+
+                                try:
+                                    # for nac_match in nac_matcher:
+                                    while True:
+                                        try:
+                                            with Timer(f"MATCH NAC{i_nac} {rule_name}"):
+                                                nac_match = nac_matcher.__next__()
+                                            # The NAC has at least one match
+                                            # (there could be more, but we know enough, so let's not waste CPU/MEM resources and proceed to next LHS match)
+                                            raise _NAC_MATCHED()
+                                        except StopIteration:
+                                            break # no more nac-matches
+
+                                except Exception as e:
+                                    # The exception may originate from eval'ed condition-code in LHS or NAC
+                                    # Decorate exception with some context, to help with debugging
+                                    e.add_note(f"while matching NAC of '{rule_name}'")
+                                    raise
+                        except _NAC_MATCHED:
+                            continue # continue with next LHS-match
 
                     # There were no NAC matches -> yield LHS-match!
                     yield lhs_match