MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / timeReport

Function timeReport

tools/donate-cpu-server.py:748–855  ·  view source on GitHub ↗
(resultPath: str, show_gt: bool, query_params: dict)

Source from the content-addressed store, hash-verified

746
747# TODO: needs to dinicate that it returns 'tuple[str, str]' but that isn't supported until Python 3.9
748def timeReport(resultPath: str, show_gt: bool, query_params: dict):
749 # no need for package report support in "improved" report
750 pkgs = '' if show_gt and query_params and query_params.get('pkgs') == '1' else None
751 factor = float(query_params.get('factor')) if query_params and 'factor' in query_params else 2.0
752 if not show_gt:
753 factor = 1.0 / factor
754
755 title = 'Time report ({})'.format('regressed' if show_gt else 'improved')
756 html = '<!DOCTYPE html>\n'
757 html += '<html><head><title>{}</title></head><body>\n'.format(title)
758 html += '<h1>{}</h1>\n'.format(title)
759 html += '<pre>\n'
760 column_width = [40, 10, 10, 10, 10, 10]
761 html += '<b>'
762 html += fmt('Package', 'Date Time', OLD_VERSION, 'Head', 'Factor', link=False, column_width=column_width)
763 html += '</b>\n'
764
765 current_year = datetime.date.today().year
766
767 data = {}
768
769 total_time_base = 0.0
770 total_time_head = 0.0
771 for filename in glob.glob(resultPath + '/*'):
772 if not os.path.isfile(filename) or filename.endswith('.diff'):
773 continue
774 datestr = None
775 package_url = None
776 for line in open(filename, 'rt'):
777 line = line.strip()
778 if line.startswith('cppcheck: '):
779 if OLD_VERSION not in line:
780 # Package results seem to be too old, skip
781 break
782 # Current package, parse on
783 continue
784 if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'):
785 datestr = line
786 continue
787 if pkgs is not None and package_url is None and line.startswith('ftp://'):
788 package_url = line
789 if not line.startswith('elapsed-time:'):
790 continue
791 split_line = line.split()
792 time_base = float(split_line[2])
793 time_head = float(split_line[1])
794 if time_base < 0.0 or time_head < 0.0:
795 # ignore results with crashes / errors for the time report
796 break
797 if time_base == 0.0 and time_head == 0.0:
798 # no difference possible
799 break
800 total_time_base += time_base
801 total_time_head += time_head
802 if time_base == time_head:
803 # no difference
804 break
805 if time_base > 0.0 and time_head > 0.0:

Callers 1

runMethod · 0.85

Calls 4

fmtFunction · 0.85
strFunction · 0.85
formatMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected