def check_for_basever(testlogfile, basebranch): """Checks if the base revision is present in the testlogs""" filetoopen = open(testlogfile, 'r') for line in filetoopen: templine = processLogLine(line) if templine.branch == basebranch: return True return False
def compare_rev(filename, rev1, rev2, branch1=False, branch2=False): """Compare the test results of two lines. We can specify either a revision or a branch for comparison. The first rev should be the base version and the second revision should be the later version""" #In the log file the index of the revision is 2 but the index of #the branch is 12. Alternate those depending on whether we are looking #for a specific revision or branch. firstidx = 2 secondidx = 2 if branch1 == True: firstidx = 12 if branch2 == True: secondidx = 12 rev1line = '' rev2line = '' resfile = open(filename, 'r') for line in resfile: if rev1 == line.split()[firstidx]: rev1line = line elif rev2 == line.split()[secondidx]: rev2line = line if rev1line != '' and rev2line != '': break resfile.close() if rev1line == '': raise ValueError('Revision ' + rev1 + " was not found!") if rev2line == '': raise ValueError('Revision ' + rev2 + " was not found!") logLine1 = processLogLine(rev1line) logLine2 = processLogLine(rev2line) res = Result(logLine1.testname, logLine1.real, logLine2.real,\ logLine2.revision, logLine2.branch, logLine1.revision, logLine1.branch) return res
def gather_necessary_lines(logfile, date): """Gathers the necessary lines corresponding to past dates and parses them if they exist""" #Get a dictionary of dates dates = {} dates[get_prev_days(date, 2)] = ('-2', None) dates[get_prev_days(date, 3)] = ('-3', None) dates[get_prev_days(date, 4)] = ('-4', None) dates[get_prev_days(date, 5)] = ('-5', None) dates[get_prev_days(date, 6)] = ('-6', None) dates[get_prev_days(date, 7)] = ('-7', None) dates[get_prev_days(date, 14)] = ('-14', None) dates[get_prev_days(date, 365)] = ('-365', None) openfile = open(logfile, 'r') for line in openfile: if line.split()[0] in dates.keys(): day = dates[line.split()[0]][0] dates[line.split()[0]] = (day, processLogLine(line)) openfile.close() return dates
def produce_html(path, global_config): """Produces html file for the report.""" html = '' #The table HTML for filenam in os.listdir(global_config.testlogs): #Generate html for the newest two lines #Get the lines from the config file (ll1, ll2) = getLastTwoLines(filenam, global_config.testlogs) logLine1 = processLogLine(ll1) logLine2 = processLogLine(ll2) #Generate html res1 = Result(logLine1.testname, logLine1.real, logLine2.real,\ logLine2.revision, logLine2.branch, logLine1.revision, logLine1.branch) html = html + '<tr><td>' + logLine2.date + '</td><td>' + logLine2.time + '</td><td>' +\ res1.testname + '</td><td>' + res1.revision[:10] + '</td><td>' + res1.branch + '</td><td>' +\ str(res1.current) + '</td><td>' + str(res1.previous) + '</td><td>' + res1.prevrev[:10] + '</td>' #Add fancy colours depending on the change if res1.percentage > 0.05: #If we have improvement of more than 5% html = html + '<td class="better">' + str( res1.percentage) + '</td>' elif res1.percentage < -0.05: #We have a regression of more than 5% html = html + '<td class="worse">' + str(res1.percentage) + '</td>' else: html = html + '<td class="unchanged">' + str( res1.percentage) + '</td>' #Get comparison against the base version filenam = global_config.testlogs + '/' + filenam #Get proper directory res2 = compare_rev(filenam, global_config.basebranch, res1.revision, branch1=True) html = html + '<td>' + str(res2.previous) + '</td>' #Add fancy colours depending on the change if res2.percentage > 0.05: #If we have improvement of more than 5% html = html + '<td class="better">' + str( res2.percentage) + '</td>' elif res2.percentage < -0.05: #We have a regression of more than 5% html = html + '<td class="worse">' + str(res2.percentage) + '</td>' else: html = html + '<td class="unchanged">' + str( res2.percentage) + '</td>' #Add extra dates comparison dating from the beginning of time if they exist past_dates = list(range(2, 8)) past_dates.append(14) past_dates.append(365) # Get the 1 year ago day linesdict = gather_necessary_lines(filenam, logLine2.date) for days in past_dates: act_date = get_prev_days(logLine2.date, days) if linesdict[act_date][1] is not None: logline_date = linesdict[act_date][1] restemp = Result(logline_date.testname, logline_date.real, logLine2.real,\ logLine2.revision, logLine2.branch, logline_date.revision, logline_date.branch) html = html + append_date_to_table(restemp) else: html = html + '<td>N/A</td><td>N/A</td>' html = html + '</tr>' #End row #Write out the file basebranch_info = '<text><b>Basebranch:</b> ' + res2.prevbranch + ' <b>Revision:</b> ' +\ res2.prevrev + '</text>' writeoutstr = HTML_HEADING + basebranch_info + TABLE_HEADING + html + HTML_ENDING writefile = open(path, 'w') writefile.write(writeoutstr) writefile.close()
for item in firsttime: print(bcolors.PURPLE + "First time test! " + item.testname +\ " Took: " + str(item.real) + " seconds. Revision: " +\ item.revision + bcolors.ENDC) all_files = os.listdir(LOGDIR) regressed = [] better = [] unchanged = [] firsttime = [] #Go through all log files and find which tests have performed better. for logfile in all_files: (line1, line2) = getLastTwoLines(logfile, LOGDIR) log1 = processLogLine(line1) if line2 == '\n': # Empty line, only one test ever run firsttime.append(log1) continue log2 = processLogLine(line2) res = Result(log1.testname, log1.real, log2.real, log2.revision,\ log2.branch, log1.revision, log1.branch) if res.percentage < -PERCENTAGE: regressed.append(res) elif res.change > PERCENTAGE: better.append(res) else: unchanged.append(res) printResults(regressed, better, unchanged, firsttime)
def produce_html(path, global_config): """Produces html file for the report.""" html = '' #The table HTML for filenam in os.listdir(global_config.testlogs): #Generate html for the newest two lines #Get the lines from the config file (ll1, ll2) = getLastTwoLines(filenam, global_config.testlogs) logLine1 = processLogLine(ll1) logLine2 = processLogLine(ll2) #Generate html res1 = Result(logLine1.testname, logLine1.real, logLine2.real,\ logLine2.revision, logLine2.branch, logLine1.revision, logLine1.branch) html = html + '<tr><td>' + logLine2.date + '</td><td>' + logLine2.time + '</td><td>' +\ res1.testname + '</td><td>' + res1.revision[:10] + '</td><td>' + res1.branch + '</td><td>' +\ str(res1.current) + '</td><td>' + str(res1.previous) + '</td><td>' + res1.prevrev[:10] + '</td>' #Add fancy colours depending on the change if res1.percentage > 0.05: #If we have improvement of more than 5% html = html + '<td class="better">' + str(res1.percentage) + '</td>' elif res1.percentage < -0.05: #We have a regression of more than 5% html = html + '<td class="worse">' + str(res1.percentage) + '</td>' else: html = html + '<td class="unchanged">' + str(res1.percentage) + '</td>' #Get comparison against the base version filenam = global_config.testlogs + '/' + filenam #Get proper directory res2 = compare_rev(filenam, global_config.basebranch, res1.revision, branch1=True) html = html + '<td>' + str(res2.previous) + '</td>' #Add fancy colours depending on the change if res2.percentage > 0.05: #If we have improvement of more than 5% html = html + '<td class="better">' + str(res2.percentage) + '</td>' elif res2.percentage < -0.05: #We have a regression of more than 5% html = html + '<td class="worse">' + str(res2.percentage) + '</td>' else: html = html + '<td class="unchanged">' + str(res2.percentage) + '</td>' #Add extra dates comparison dating from the beginning of time if they exist past_dates = list(range(2, 8)) past_dates.append(14) past_dates.append(365) # Get the 1 year ago day linesdict = gather_necessary_lines(filenam, logLine2.date) for days in past_dates: act_date = get_prev_days(logLine2.date, days) if linesdict[act_date][1] is not None: logline_date = linesdict[act_date][1] restemp = Result(logline_date.testname, logline_date.real, logLine2.real,\ logLine2.revision, logLine2.branch, logline_date.revision, logline_date.branch) html = html + append_date_to_table(restemp) else: html = html + '<td>N/A</td><td>N/A</td>' html = html + '</tr>' #End row #Write out the file basebranch_info = '<text><b>Basebranch:</b> ' + res2.prevbranch + ' <b>Revision:</b> ' +\ res2.prevrev + '</text>' writeoutstr = HTML_HEADING + basebranch_info + TABLE_HEADING + html + HTML_ENDING writefile = open(path, 'w') writefile.write(writeoutstr) writefile.close()