From ad062dbdeba901c5b5f90a083a4aa53aa7636fa6 Mon Sep 17 00:00:00 2001 From: Rahul Huilgol Date: Mon, 24 Jul 2017 17:48:09 -0700 Subject: [PATCH] add python script to track warnings --- warn.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 warn.py diff --git a/warn.py b/warn.py new file mode 100644 index 000000000000..368819cc9882 --- /dev/null +++ b/warn.py @@ -0,0 +1,47 @@ +import re +import sys +import operator +from subprocess import check_output, STDOUT, CalledProcessError + +def process_output(command_output): + warnings = {} + regex = r"(.*):\swarning:\s(.*)" + lines = command_output.split("\n") + for line in lines[:-3]: + matches = re.finditer(regex, line) + for matchNum, match in enumerate(matches): + try: + warnings[match.group()] +=1 + except KeyError: + warnings[match.group()] =1 + time = lines[-3].split('\t')[1] + return time, warnings + +def generate_stats(warnings): + total_count = sum(warnings.values()) + sorted_warnings = sorted(warnings.items(), key=operator.itemgetter(1), reverse=True) + return sorted_warnings, total_count + +def print_summary(time, warnings): + sorted_warnings, total_count = generate_stats(warnings) + print "START - Compilation warnings count" + print total_count + print "END - Compilation warnings count" + print 'START - Compilation warnings summary' + print 'Time taken to compile:', time + print 'Total number of warnings:', total_count, '\n' + print 'Given below is the list of unique warnings and the number of occurences of that warning' + for warning, count in sorted_warnings: + print count, ': ', warning + print 'END - Compilation warnings summary' + +try: + check_output(['make','clean'], stderr=STDOUT, shell=True) + command_output = check_output(['time','make','-j8'], stderr=STDOUT, shell=True) + time, warnings = process_output(command_output) + print_summary(time, warnings) +except CalledProcessError as ex: + if ex.returncode > 1: + print 'Compilation failed' + print ex.output + sys.exit(ex.returncode)