1*3117ece4Schristos#! /usr/bin/env python3 2*3117ece4Schristos# THIS BENCHMARK IS BEING REPLACED BY automated-bencmarking.py 3*3117ece4Schristos 4*3117ece4Schristos# ################################################################ 5*3117ece4Schristos# Copyright (c) Meta Platforms, Inc. and affiliates. 6*3117ece4Schristos# All rights reserved. 7*3117ece4Schristos# 8*3117ece4Schristos# This source code is licensed under both the BSD-style license (found in the 9*3117ece4Schristos# LICENSE file in the root directory of this source tree) and the GPLv2 (found 10*3117ece4Schristos# in the COPYING file in the root directory of this source tree). 11*3117ece4Schristos# You may select, at your option, one of the above-listed licenses. 12*3117ece4Schristos# ########################################################################## 13*3117ece4Schristos 14*3117ece4Schristos# Limitations: 15*3117ece4Schristos# - doesn't support filenames with spaces 16*3117ece4Schristos# - dir1/zstd and dir2/zstd will be merged in a single results file 17*3117ece4Schristos 18*3117ece4Schristosimport argparse 19*3117ece4Schristosimport os # getloadavg 20*3117ece4Schristosimport string 21*3117ece4Schristosimport subprocess 22*3117ece4Schristosimport time # strftime 23*3117ece4Schristosimport traceback 24*3117ece4Schristosimport hashlib 25*3117ece4Schristosimport platform # system 26*3117ece4Schristos 27*3117ece4Schristosscript_version = 'v1.1.2 (2017-03-26)' 28*3117ece4Schristosdefault_repo_url = 'https://github.com/facebook/zstd.git' 29*3117ece4Schristosworking_dir_name = 'speedTest' 30*3117ece4Schristosworking_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest 31*3117ece4Schristosclone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd 32*3117ece4Schristosemail_header = 'ZSTD_speedTest' 33*3117ece4Schristospid = str(os.getpid()) 34*3117ece4Schristosverbose = False 35*3117ece4Schristosclang_version = "unknown" 36*3117ece4Schristosgcc_version = "unknown" 37*3117ece4Schristosargs = None 38*3117ece4Schristos 39*3117ece4Schristos 40*3117ece4Schristosdef hashfile(hasher, fname, blocksize=65536): 41*3117ece4Schristos with open(fname, "rb") as f: 42*3117ece4Schristos for chunk in iter(lambda: f.read(blocksize), b""): 43*3117ece4Schristos hasher.update(chunk) 44*3117ece4Schristos return hasher.hexdigest() 45*3117ece4Schristos 46*3117ece4Schristos 47*3117ece4Schristosdef log(text): 48*3117ece4Schristos print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) 49*3117ece4Schristos 50*3117ece4Schristos 51*3117ece4Schristosdef execute(command, print_command=True, print_output=False, print_error=True, param_shell=True): 52*3117ece4Schristos if print_command: 53*3117ece4Schristos log("> " + command) 54*3117ece4Schristos popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=param_shell, cwd=execute.cwd) 55*3117ece4Schristos stdout_lines, stderr_lines = popen.communicate(timeout=args.timeout) 56*3117ece4Schristos stderr_lines = stderr_lines.decode("utf-8") 57*3117ece4Schristos stdout_lines = stdout_lines.decode("utf-8") 58*3117ece4Schristos if print_output: 59*3117ece4Schristos if stdout_lines: 60*3117ece4Schristos print(stdout_lines) 61*3117ece4Schristos if stderr_lines: 62*3117ece4Schristos print(stderr_lines) 63*3117ece4Schristos if popen.returncode is not None and popen.returncode != 0: 64*3117ece4Schristos if stderr_lines and not print_output and print_error: 65*3117ece4Schristos print(stderr_lines) 66*3117ece4Schristos raise RuntimeError(stdout_lines + stderr_lines) 67*3117ece4Schristos return (stdout_lines + stderr_lines).splitlines() 68*3117ece4Schristosexecute.cwd = None 69*3117ece4Schristos 70*3117ece4Schristos 71*3117ece4Schristosdef does_command_exist(command): 72*3117ece4Schristos try: 73*3117ece4Schristos execute(command, verbose, False, False) 74*3117ece4Schristos except Exception: 75*3117ece4Schristos return False 76*3117ece4Schristos return True 77*3117ece4Schristos 78*3117ece4Schristos 79*3117ece4Schristosdef send_email(emails, topic, text, have_mutt, have_mail): 80*3117ece4Schristos logFileName = working_path + '/' + 'tmpEmailContent' 81*3117ece4Schristos with open(logFileName, "w") as myfile: 82*3117ece4Schristos myfile.writelines(text) 83*3117ece4Schristos myfile.close() 84*3117ece4Schristos if have_mutt: 85*3117ece4Schristos execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) 86*3117ece4Schristos elif have_mail: 87*3117ece4Schristos execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) 88*3117ece4Schristos else: 89*3117ece4Schristos log("e-mail cannot be sent (mail or mutt not found)") 90*3117ece4Schristos 91*3117ece4Schristos 92*3117ece4Schristosdef send_email_with_attachments(branch, commit, last_commit, args, text, results_files, 93*3117ece4Schristos logFileName, have_mutt, have_mail): 94*3117ece4Schristos with open(logFileName, "w") as myfile: 95*3117ece4Schristos myfile.writelines(text) 96*3117ece4Schristos myfile.close() 97*3117ece4Schristos email_topic = '[%s:%s] Warning for %s:%s last_commit=%s speed<%s ratio<%s' \ 98*3117ece4Schristos % (email_header, pid, branch, commit, last_commit, 99*3117ece4Schristos args.lowerLimit, args.ratioLimit) 100*3117ece4Schristos if have_mutt: 101*3117ece4Schristos execute('mutt -s "' + email_topic + '" ' + args.emails + ' -a ' + results_files 102*3117ece4Schristos + ' < ' + logFileName) 103*3117ece4Schristos elif have_mail: 104*3117ece4Schristos execute('mail -s "' + email_topic + '" ' + args.emails + ' < ' + logFileName) 105*3117ece4Schristos else: 106*3117ece4Schristos log("e-mail cannot be sent (mail or mutt not found)") 107*3117ece4Schristos 108*3117ece4Schristos 109*3117ece4Schristosdef git_get_branches(): 110*3117ece4Schristos execute('git fetch -p', verbose) 111*3117ece4Schristos branches = execute('git branch -rl', verbose) 112*3117ece4Schristos output = [] 113*3117ece4Schristos for line in branches: 114*3117ece4Schristos if ("HEAD" not in line) and ("coverity_scan" not in line) and ("gh-pages" not in line): 115*3117ece4Schristos output.append(line.strip()) 116*3117ece4Schristos return output 117*3117ece4Schristos 118*3117ece4Schristos 119*3117ece4Schristosdef git_get_changes(branch, commit, last_commit): 120*3117ece4Schristos fmt = '--format="%h: (%an) %s, %ar"' 121*3117ece4Schristos if last_commit is None: 122*3117ece4Schristos commits = execute('git log -n 10 %s %s' % (fmt, commit)) 123*3117ece4Schristos else: 124*3117ece4Schristos commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) 125*3117ece4Schristos return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits) 126*3117ece4Schristos 127*3117ece4Schristos 128*3117ece4Schristosdef get_last_results(resultsFileName): 129*3117ece4Schristos if not os.path.isfile(resultsFileName): 130*3117ece4Schristos return None, None, None, None 131*3117ece4Schristos commit = None 132*3117ece4Schristos csize = [] 133*3117ece4Schristos cspeed = [] 134*3117ece4Schristos dspeed = [] 135*3117ece4Schristos with open(resultsFileName, 'r') as f: 136*3117ece4Schristos for line in f: 137*3117ece4Schristos words = line.split() 138*3117ece4Schristos if len(words) <= 4: # branch + commit + compilerVer + md5 139*3117ece4Schristos commit = words[1] 140*3117ece4Schristos csize = [] 141*3117ece4Schristos cspeed = [] 142*3117ece4Schristos dspeed = [] 143*3117ece4Schristos if (len(words) == 8) or (len(words) == 9): # results: "filename" or "XX files" 144*3117ece4Schristos csize.append(int(words[1])) 145*3117ece4Schristos cspeed.append(float(words[3])) 146*3117ece4Schristos dspeed.append(float(words[5])) 147*3117ece4Schristos return commit, csize, cspeed, dspeed 148*3117ece4Schristos 149*3117ece4Schristos 150*3117ece4Schristosdef benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, 151*3117ece4Schristos testFilePath, fileName, last_csize, last_cspeed, last_dspeed): 152*3117ece4Schristos sleepTime = 30 153*3117ece4Schristos while os.getloadavg()[0] > args.maxLoadAvg: 154*3117ece4Schristos log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" 155*3117ece4Schristos % (os.getloadavg()[0], args.maxLoadAvg, sleepTime)) 156*3117ece4Schristos time.sleep(sleepTime) 157*3117ece4Schristos start_load = str(os.getloadavg()) 158*3117ece4Schristos osType = platform.system() 159*3117ece4Schristos if osType == 'Linux': 160*3117ece4Schristos cpuSelector = "taskset --cpu-list 0" 161*3117ece4Schristos else: 162*3117ece4Schristos cpuSelector = "" 163*3117ece4Schristos if args.dictionary: 164*3117ece4Schristos result = execute('%s programs/%s -rqi5b1e%s -D %s %s' % (cpuSelector, executableName, args.lastCLevel, args.dictionary, testFilePath), print_output=True) 165*3117ece4Schristos else: 166*3117ece4Schristos result = execute('%s programs/%s -rqi5b1e%s %s' % (cpuSelector, executableName, args.lastCLevel, testFilePath), print_output=True) 167*3117ece4Schristos end_load = str(os.getloadavg()) 168*3117ece4Schristos linesExpected = args.lastCLevel + 1 169*3117ece4Schristos if len(result) != linesExpected: 170*3117ece4Schristos raise RuntimeError("ERROR: number of result lines=%d is different that expected %d\n%s" % (len(result), linesExpected, '\n'.join(result))) 171*3117ece4Schristos with open(resultsFileName, "a") as myfile: 172*3117ece4Schristos myfile.write('%s %s %s md5=%s\n' % (branch, commit, compilerVersion, md5sum)) 173*3117ece4Schristos myfile.write('\n'.join(result) + '\n') 174*3117ece4Schristos myfile.close() 175*3117ece4Schristos if (last_cspeed == None): 176*3117ece4Schristos log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) 177*3117ece4Schristos return "" 178*3117ece4Schristos commit, csize, cspeed, dspeed = get_last_results(resultsFileName) 179*3117ece4Schristos text = "" 180*3117ece4Schristos for i in range(0, min(len(cspeed), len(last_cspeed))): 181*3117ece4Schristos print("%s:%s -%d cSpeed=%6.2f cLast=%6.2f cDiff=%1.4f dSpeed=%6.2f dLast=%6.2f dDiff=%1.4f ratioDiff=%1.4f %s" % (branch, commit, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], float(last_csize[i])/csize[i], fileName)) 182*3117ece4Schristos if (cspeed[i]/last_cspeed[i] < args.lowerLimit): 183*3117ece4Schristos text += "WARNING: %s -%d cSpeed=%.2f cLast=%.2f cDiff=%.4f %s\n" % (executableName, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], fileName) 184*3117ece4Schristos if (dspeed[i]/last_dspeed[i] < args.lowerLimit): 185*3117ece4Schristos text += "WARNING: %s -%d dSpeed=%.2f dLast=%.2f dDiff=%.4f %s\n" % (executableName, i+1, dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], fileName) 186*3117ece4Schristos if (float(last_csize[i])/csize[i] < args.ratioLimit): 187*3117ece4Schristos text += "WARNING: %s -%d cSize=%d last_cSize=%d diff=%.4f %s\n" % (executableName, i+1, csize[i], last_csize[i], float(last_csize[i])/csize[i], fileName) 188*3117ece4Schristos if text: 189*3117ece4Schristos text = args.message + ("\nmaxLoadAvg=%s load average at start=%s end=%s\n%s last_commit=%s md5=%s\n" % (args.maxLoadAvg, start_load, end_load, compilerVersion, last_commit, md5sum)) + text 190*3117ece4Schristos return text 191*3117ece4Schristos 192*3117ece4Schristos 193*3117ece4Schristosdef update_config_file(branch, commit): 194*3117ece4Schristos last_commit = None 195*3117ece4Schristos commitFileName = working_path + "/commit_" + branch.replace("/", "_") + ".txt" 196*3117ece4Schristos if os.path.isfile(commitFileName): 197*3117ece4Schristos with open(commitFileName, 'r') as infile: 198*3117ece4Schristos last_commit = infile.read() 199*3117ece4Schristos with open(commitFileName, 'w') as outfile: 200*3117ece4Schristos outfile.write(commit) 201*3117ece4Schristos return last_commit 202*3117ece4Schristos 203*3117ece4Schristos 204*3117ece4Schristosdef double_check(branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName): 205*3117ece4Schristos last_commit, csize, cspeed, dspeed = get_last_results(resultsFileName) 206*3117ece4Schristos if not args.dry_run: 207*3117ece4Schristos text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed) 208*3117ece4Schristos if text: 209*3117ece4Schristos log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) 210*3117ece4Schristos text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed) 211*3117ece4Schristos return text 212*3117ece4Schristos 213*3117ece4Schristos 214*3117ece4Schristosdef test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail): 215*3117ece4Schristos local_branch = branch.split('/')[1] 216*3117ece4Schristos version = local_branch.rpartition('-')[2] + '_' + commit 217*3117ece4Schristos if not args.dry_run: 218*3117ece4Schristos execute('make -C programs clean zstd CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -DZSTD_GIT_COMMIT=%s" && ' % version + 219*3117ece4Schristos 'mv programs/zstd programs/zstd_clang && ' + 220*3117ece4Schristos 'make -C programs clean zstd zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) 221*3117ece4Schristos md5_zstd = hashfile(hashlib.md5(), clone_path + '/programs/zstd') 222*3117ece4Schristos md5_zstd32 = hashfile(hashlib.md5(), clone_path + '/programs/zstd32') 223*3117ece4Schristos md5_zstd_clang = hashfile(hashlib.md5(), clone_path + '/programs/zstd_clang') 224*3117ece4Schristos print("md5(zstd)=%s\nmd5(zstd32)=%s\nmd5(zstd_clang)=%s" % (md5_zstd, md5_zstd32, md5_zstd_clang)) 225*3117ece4Schristos print("gcc_version=%s clang_version=%s" % (gcc_version, clang_version)) 226*3117ece4Schristos 227*3117ece4Schristos logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt" 228*3117ece4Schristos text_to_send = [] 229*3117ece4Schristos results_files = "" 230*3117ece4Schristos if args.dictionary: 231*3117ece4Schristos dictName = args.dictionary.rpartition('/')[2] 232*3117ece4Schristos else: 233*3117ece4Schristos dictName = None 234*3117ece4Schristos 235*3117ece4Schristos for filePath in testFilePaths: 236*3117ece4Schristos fileName = filePath.rpartition('/')[2] 237*3117ece4Schristos if dictName: 238*3117ece4Schristos resultsFileName = working_path + "/" + dictName.replace(".", "_") + "_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" 239*3117ece4Schristos else: 240*3117ece4Schristos resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" 241*3117ece4Schristos text = double_check(branch, commit, args, 'zstd', md5_zstd, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName) 242*3117ece4Schristos if text: 243*3117ece4Schristos text_to_send.append(text) 244*3117ece4Schristos results_files += resultsFileName + " " 245*3117ece4Schristos resultsFileName = working_path + "/results32_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" 246*3117ece4Schristos text = double_check(branch, commit, args, 'zstd32', md5_zstd32, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName) 247*3117ece4Schristos if text: 248*3117ece4Schristos text_to_send.append(text) 249*3117ece4Schristos results_files += resultsFileName + " " 250*3117ece4Schristos resultsFileName = working_path + "/resultsClang_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" 251*3117ece4Schristos text = double_check(branch, commit, args, 'zstd_clang', md5_zstd_clang, 'clang_version='+clang_version, resultsFileName, filePath, fileName) 252*3117ece4Schristos if text: 253*3117ece4Schristos text_to_send.append(text) 254*3117ece4Schristos results_files += resultsFileName + " " 255*3117ece4Schristos if text_to_send: 256*3117ece4Schristos send_email_with_attachments(branch, commit, last_commit, args, text_to_send, results_files, logFileName, have_mutt, have_mail) 257*3117ece4Schristos 258*3117ece4Schristos 259*3117ece4Schristosif __name__ == '__main__': 260*3117ece4Schristos parser = argparse.ArgumentParser() 261*3117ece4Schristos parser.add_argument('testFileNames', help='file or directory names list for speed benchmark') 262*3117ece4Schristos parser.add_argument('emails', help='list of e-mail addresses to send warnings') 263*3117ece4Schristos parser.add_argument('--dictionary', '-D', help='path to the dictionary') 264*3117ece4Schristos parser.add_argument('--message', '-m', help='attach an additional message to e-mail', default="") 265*3117ece4Schristos parser.add_argument('--repoURL', help='changes default repository URL', default=default_repo_url) 266*3117ece4Schristos parser.add_argument('--lowerLimit', '-l', type=float, help='send email if speed is lower than given limit', default=0.98) 267*3117ece4Schristos parser.add_argument('--ratioLimit', '-r', type=float, help='send email if ratio is lower than given limit', default=0.999) 268*3117ece4Schristos parser.add_argument('--maxLoadAvg', type=float, help='maximum load average to start testing', default=0.75) 269*3117ece4Schristos parser.add_argument('--lastCLevel', type=int, help='last compression level for testing', default=5) 270*3117ece4Schristos parser.add_argument('--sleepTime', '-s', type=int, help='frequency of repository checking in seconds', default=300) 271*3117ece4Schristos parser.add_argument('--timeout', '-t', type=int, help='timeout for executing shell commands', default=1800) 272*3117ece4Schristos parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='not build', default=False) 273*3117ece4Schristos parser.add_argument('--verbose', '-v', action='store_true', help='more verbose logs', default=False) 274*3117ece4Schristos args = parser.parse_args() 275*3117ece4Schristos verbose = args.verbose 276*3117ece4Schristos 277*3117ece4Schristos # check if test files are accessible 278*3117ece4Schristos testFileNames = args.testFileNames.split() 279*3117ece4Schristos testFilePaths = [] 280*3117ece4Schristos for fileName in testFileNames: 281*3117ece4Schristos fileName = os.path.expanduser(fileName) 282*3117ece4Schristos if os.path.isfile(fileName) or os.path.isdir(fileName): 283*3117ece4Schristos testFilePaths.append(os.path.abspath(fileName)) 284*3117ece4Schristos else: 285*3117ece4Schristos log("ERROR: File/directory not found: " + fileName) 286*3117ece4Schristos exit(1) 287*3117ece4Schristos 288*3117ece4Schristos # check if dictionary is accessible 289*3117ece4Schristos if args.dictionary: 290*3117ece4Schristos args.dictionary = os.path.abspath(os.path.expanduser(args.dictionary)) 291*3117ece4Schristos if not os.path.isfile(args.dictionary): 292*3117ece4Schristos log("ERROR: Dictionary not found: " + args.dictionary) 293*3117ece4Schristos exit(1) 294*3117ece4Schristos 295*3117ece4Schristos # check availability of e-mail senders 296*3117ece4Schristos have_mutt = does_command_exist("mutt -h") 297*3117ece4Schristos have_mail = does_command_exist("mail -V") 298*3117ece4Schristos if not have_mutt and not have_mail: 299*3117ece4Schristos log("ERROR: e-mail senders 'mail' or 'mutt' not found") 300*3117ece4Schristos exit(1) 301*3117ece4Schristos 302*3117ece4Schristos clang_version = execute("clang -v 2>&1 | grep ' version ' | sed -e 's:.*version \\([0-9.]*\\).*:\\1:' -e 's:\\.\\([0-9][0-9]\\):\\1:g'", verbose)[0]; 303*3117ece4Schristos gcc_version = execute("gcc -dumpversion", verbose)[0]; 304*3117ece4Schristos 305*3117ece4Schristos if verbose: 306*3117ece4Schristos print("PARAMETERS:\nrepoURL=%s" % args.repoURL) 307*3117ece4Schristos print("working_path=%s" % working_path) 308*3117ece4Schristos print("clone_path=%s" % clone_path) 309*3117ece4Schristos print("testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths)) 310*3117ece4Schristos print("message=%s" % args.message) 311*3117ece4Schristos print("emails=%s" % args.emails) 312*3117ece4Schristos print("dictionary=%s" % args.dictionary) 313*3117ece4Schristos print("maxLoadAvg=%s" % args.maxLoadAvg) 314*3117ece4Schristos print("lowerLimit=%s" % args.lowerLimit) 315*3117ece4Schristos print("ratioLimit=%s" % args.ratioLimit) 316*3117ece4Schristos print("lastCLevel=%s" % args.lastCLevel) 317*3117ece4Schristos print("sleepTime=%s" % args.sleepTime) 318*3117ece4Schristos print("timeout=%s" % args.timeout) 319*3117ece4Schristos print("dry_run=%s" % args.dry_run) 320*3117ece4Schristos print("verbose=%s" % args.verbose) 321*3117ece4Schristos print("have_mutt=%s have_mail=%s" % (have_mutt, have_mail)) 322*3117ece4Schristos 323*3117ece4Schristos # clone ZSTD repo if needed 324*3117ece4Schristos if not os.path.isdir(working_path): 325*3117ece4Schristos os.mkdir(working_path) 326*3117ece4Schristos if not os.path.isdir(clone_path): 327*3117ece4Schristos execute.cwd = working_path 328*3117ece4Schristos execute('git clone ' + args.repoURL) 329*3117ece4Schristos if not os.path.isdir(clone_path): 330*3117ece4Schristos log("ERROR: ZSTD clone not found: " + clone_path) 331*3117ece4Schristos exit(1) 332*3117ece4Schristos execute.cwd = clone_path 333*3117ece4Schristos 334*3117ece4Schristos # check if speedTest.pid already exists 335*3117ece4Schristos pidfile = "./speedTest.pid" 336*3117ece4Schristos if os.path.isfile(pidfile): 337*3117ece4Schristos log("ERROR: %s already exists, exiting" % pidfile) 338*3117ece4Schristos exit(1) 339*3117ece4Schristos 340*3117ece4Schristos send_email(args.emails, '[%s:%s] test-zstd-speed.py %s has been started' % (email_header, pid, script_version), args.message, have_mutt, have_mail) 341*3117ece4Schristos with open(pidfile, 'w') as the_file: 342*3117ece4Schristos the_file.write(pid) 343*3117ece4Schristos 344*3117ece4Schristos branch = "" 345*3117ece4Schristos commit = "" 346*3117ece4Schristos first_time = True 347*3117ece4Schristos while True: 348*3117ece4Schristos try: 349*3117ece4Schristos if first_time: 350*3117ece4Schristos first_time = False 351*3117ece4Schristos else: 352*3117ece4Schristos time.sleep(args.sleepTime) 353*3117ece4Schristos loadavg = os.getloadavg()[0] 354*3117ece4Schristos if (loadavg <= args.maxLoadAvg): 355*3117ece4Schristos branches = git_get_branches() 356*3117ece4Schristos for branch in branches: 357*3117ece4Schristos commit = execute('git show -s --format=%h ' + branch, verbose)[0] 358*3117ece4Schristos last_commit = update_config_file(branch, commit) 359*3117ece4Schristos if commit == last_commit: 360*3117ece4Schristos log("skipping branch %s: head %s already processed" % (branch, commit)) 361*3117ece4Schristos else: 362*3117ece4Schristos log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) 363*3117ece4Schristos execute('git checkout -- . && git checkout ' + branch) 364*3117ece4Schristos print(git_get_changes(branch, commit, last_commit)) 365*3117ece4Schristos test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail) 366*3117ece4Schristos else: 367*3117ece4Schristos log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg)) 368*3117ece4Schristos if verbose: 369*3117ece4Schristos log("sleep for %s seconds" % args.sleepTime) 370*3117ece4Schristos except Exception as e: 371*3117ece4Schristos stack = traceback.format_exc() 372*3117ece4Schristos email_topic = '[%s:%s] ERROR in %s:%s' % (email_header, pid, branch, commit) 373*3117ece4Schristos send_email(args.emails, email_topic, stack, have_mutt, have_mail) 374*3117ece4Schristos print(stack) 375*3117ece4Schristos except KeyboardInterrupt: 376*3117ece4Schristos os.unlink(pidfile) 377*3117ece4Schristos send_email(args.emails, '[%s:%s] test-zstd-speed.py %s has been stopped' % (email_header, pid, script_version), args.message, have_mutt, have_mail) 378*3117ece4Schristos exit(0) 379