[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Practracker: add tolerances for exceptions
commit 6303c9aa2647365fa66de2b6ce1af109417b6603
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Jul 17 15:20:58 2019 +0200
Practracker: add tolerances for exceptions
When an exception is present, we can now violate the limit by a little
bit and only produce a warning. The strict flag overrides this
behavior.
I've given file sizes a 2% tolerances and function sizes/include
counts a 10% tolerance.
Part of 30752
---
scripts/maint/practracker/practracker.py | 14 ++++++++++++++
scripts/maint/practracker/problem.py | 16 ++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index 1b6502fe5..75cd44d22 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -36,6 +36,13 @@ MAX_FUNCTION_SIZE = 100 # lines
# Recommended number of #includes
MAX_INCLUDE_COUNT = 50
+# Map from problem type to functions that adjust for tolerance
+TOLERANCE_FNS = {
+ 'include-count': lambda n: int(n*1.1),
+ 'function-size': lambda n: int(n*1.1),
+ 'file-size': lambda n: int(n*1.02)
+}
+
#######################################################
# ProblemVault singleton
@@ -169,6 +176,8 @@ def main(argv):
help="List over-strict exceptions")
parser.add_argument("--exceptions",
help="Override the location for the exceptions file")
+ parser.add_argument("--strict", action="store_true",
+ help="Make all warnings into errors")
parser.add_argument("topdir", default=".", nargs="?",
help="Top-level directory for the tor source")
args = parser.parse_args(argv[1:])
@@ -196,6 +205,11 @@ def main(argv):
else:
ProblemVault = problem.ProblemVault(exceptions_file)
+ # 2.1) Adjust the exceptions so that we warn only about small problems,
+ # and produce errors on big ones.
+ if not (args.regen or args.list_overstrict or args.strict):
+ ProblemVault.set_tolerances(TOLERANCE_FNS)
+
# 3) Go through all the files and report problems if they are not exceptions
found_new_issues = consider_all_metrics(files_list)
diff --git a/scripts/maint/practracker/problem.py b/scripts/maint/practracker/problem.py
index 751ceb910..89a8f1234 100644
--- a/scripts/maint/practracker/problem.py
+++ b/scripts/maint/practracker/problem.py
@@ -90,6 +90,15 @@ class ProblemVault(object):
if p is None or e.is_worse_than(p):
yield (e, p)
+ def set_tolerances(self, fns):
+ """Adjust the tolerances for the exceptions in this vault. Takes
+ a map of problem type to a function that adjusts the permitted
+ function to its new maximum value."""
+ for k in self.exceptions:
+ ex = self.exceptions[k]
+ fn = fns.get(ex.problem_type)
+ if fn is not None:
+ ex.metric_value = fn(ex.metric_value)
class Problem(object):
"""
@@ -99,14 +108,21 @@ class Problem(object):
def __init__(self, problem_type, problem_location, metric_value):
self.problem_location = problem_location
self.metric_value = int(metric_value)
+ self.warning_threshold = self.metric_value
self.problem_type = problem_type
def is_worse_than(self, other_problem):
"""Return True if this is a worse problem than other_problem"""
if self.metric_value > other_problem.metric_value:
return True
+ elif self.metric_value > other_problem.warning_threshold:
+ self.warn()
return False
+ def warn(self):
+ """Warn about this problem on stderr only."""
+ print("(warning) {}".format(self), file=sys.stderr)
+
def key(self):
"""Generate a unique key that describes this problem that can be used as a dictionary key"""
# Problem location is a filesystem path, so we need to normalize this
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits