donate-cpu-server.py: sort time report entries by factor and corrected titles (#3102)

This commit is contained in:
Oliver Stöneberg 2021-01-31 12:01:01 +01:00 committed by GitHub
parent 6a24b4f7c8
commit 1b9865be12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -3,6 +3,7 @@
# Server for 'donate-cpu.py' # Server for 'donate-cpu.py'
# Runs only under Python 3. # Runs only under Python 3.
import collections
import glob import glob
import json import json
import os import os
@ -22,7 +23,7 @@ import operator
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes) # changes)
SERVER_VERSION = "1.3.10" SERVER_VERSION = "1.3.11"
OLD_VERSION = '2.3' OLD_VERSION = '2.3'
@ -612,16 +613,18 @@ def headMessageIdTodayReport(resultPath: str, messageId: str) -> str:
return text return text
# TODO: sort the results by factor
def timeReport(resultPath: str, show_gt: bool) -> str: def timeReport(resultPath: str, show_gt: bool) -> str:
html = '<html><head><title>Time report ({})</title></head><body>\n'.format('regressed' if show_gt else 'improved') title = 'Time report ({})'.format('regressed' if show_gt else 'improved')
html += '<h1>Time report</h1>\n' html = '<html><head><title>{}</title></head><body>\n'.format(title)
html += '<h1>{}</h1>\n'.format(title)
html += '<pre>\n' html += '<pre>\n'
column_width = [40, 10, 10, 10, 10] column_width = [40, 10, 10, 10, 10]
html += '<b>' html += '<b>'
html += fmt('Package', OLD_VERSION, 'Head', 'Factor', link=False, column_width=column_width) html += fmt('Package', OLD_VERSION, 'Head', 'Factor', link=False, column_width=column_width)
html += '</b>\n' html += '</b>\n'
data = {}
total_time_base = 0.0 total_time_base = 0.0
total_time_head = 0.0 total_time_head = 0.0
for filename in glob.glob(resultPath + '/*'): for filename in glob.glob(resultPath + '/*'):
@ -655,10 +658,19 @@ def timeReport(resultPath: str, show_gt: bool) -> str:
time_factor = time_head / time_base time_factor = time_head / time_base
else: else:
time_factor = 0.0 time_factor = 0.0
html += fmt(filename[len(resultPath)+1:], split_line[2], split_line[1], pkg_name = filename[len(resultPath)+1:]
'{:.2f}'.format(time_factor), column_width=column_width) + '\n' data[pkg_name] = (split_line[2], split_line[1], time_factor)
break break
sorted_data = sorted(data.items(), key=lambda kv: kv[1][2])
if show_gt:
sorted_data.reverse()
sorted_dict = collections.OrderedDict(sorted_data)
for key in sorted_dict:
html += fmt(key, sorted_dict[key][0], sorted_dict[key][1], '{:.2f}'.format(sorted_dict[key][2]),
column_width=column_width) + '\n'
html += '\n' html += '\n'
html += '(listed above are all suspicious timings with a factor ' html += '(listed above are all suspicious timings with a factor '
if show_gt: if show_gt: