Skip to content

Commit c80e52f

Browse files
committed
compute-safer-cpp-statistics should report the number of files
https://bugs.webkit.org/show_bug.cgi?id=299572 Reviewed by Geoffrey Garen. Print out the number of files in addition to the percentage of lines covered. * Tools/Scripts/compute-safer-cpp-statistics: (gather_statistics): (print_percentage): (main): Canonical link: https://commits.webkit.org/300545@main
1 parent 8a1585e commit c80e52f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Tools/Scripts/compute-safer-cpp-statistics

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,26 @@ def gather_statistics(line_counts, checkers, file_to_expectations_map, dir_path,
113113
expected_checkers = file_to_expectations_map.get(file_key)
114114
if expected_checkers:
115115
line_counts['unsafe'] += number_of_lines
116+
line_counts['unsafeFiles'] += 1
116117
else:
117118
line_counts['safe'] += number_of_lines
119+
line_counts['safeFiles'] += 1
118120
for checker in checkers:
119121
per_checker_counts = line_counts['checkers'][checker.name()]
120122
if expected_checkers and checker.name() in expected_checkers:
121123
per_checker_counts['unsafe'] += number_of_lines
124+
per_checker_counts['unsafeFiles'] += 1
122125
else:
123126
per_checker_counts['safe'] += number_of_lines
127+
per_checker_counts['safeFiles'] += 1
124128

125129

126130
def safe_ratio(line_counts):
127131
return line_counts['safe'] / (line_counts['safe'] + line_counts['unsafe'])
128132

129133

130134
def print_percentage(label, line_counts):
131-
return print('{}: {:.2f}% safe'.format(label, safe_ratio(line_counts) * 100))
135+
return print('{}: {:.2f}% safe ({} safe files / {} unsafe files)'.format(label, safe_ratio(line_counts) * 100, line_counts['safeFiles'], line_counts['unsafeFiles']))
132136

133137

134138
def main():
@@ -139,9 +143,9 @@ def main():
139143
return
140144

141145
file_to_expectations_map = load_expectations(checkers, args.project)
142-
line_counts = {'safe': 0, 'unsafe': 0, 'checkers': {}}
146+
line_counts = {'safe': 0, 'unsafe': 0, 'safeFiles': 0, 'unsafeFiles': 0, 'checkers': {}}
143147
for checker in checkers:
144-
line_counts['checkers'][checker.name()] = {'safe': 0, 'unsafe': 0}
148+
line_counts['checkers'][checker.name()] = {'safe': 0, 'unsafe': 0, 'safeFiles': 0, 'unsafeFiles': 0}
145149

146150
project = args.project
147151
project_path = Checker.enumerate()[0].project_path(project)

0 commit comments

Comments
 (0)