| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 1 | #! /usr/bin/env python |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 2 | |
| 3 | import argparse |
| 4 | import os |
| 5 | import string |
| 6 | import time |
| 7 | import traceback |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 8 | import subprocess |
| inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 9 | import signal |
| Yann Collet | b752298 | 2016-07-22 05:02:27 +0200 | [diff] [blame] | 10 | |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 11 | |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 12 | default_repo_url = 'https://github.com/Cyan4973/zstd.git' |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 13 | working_dir_name = 'speedTest' |
| Yann Collet | b752298 | 2016-07-22 05:02:27 +0200 | [diff] [blame] | 14 | working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest |
| 15 | clone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 16 | email_header = '[ZSTD_speedTest]' |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 17 | pid = str(os.getpid()) |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 18 | verbose = False |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 19 | |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 20 | |
| 21 | def log(text): |
| inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 22 | print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 23 | |
| inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 24 | |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 25 | def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True): |
| 26 | if print_command: |
| 27 | log("> " + command) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 28 | popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=param_shell, cwd=execute.cwd) |
| 29 | stdout = popen.communicate()[0] |
| 30 | stdout_lines = stdout.splitlines() |
| inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 31 | if print_output: |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 32 | print('\n'.join(stdout_lines)) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 33 | if popen.returncode is not None and popen.returncode != 0: |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 34 | if not print_output and print_error: |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 35 | print('\n'.join(stdout_lines)) |
| 36 | raise RuntimeError('\n'.join(stdout_lines)) |
| 37 | return stdout_lines |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 38 | execute.cwd = None |
| 39 | |
| 40 | |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 41 | def does_command_exist(command): |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 42 | try: |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 43 | execute(command, verbose, False, False); |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 44 | except Exception as e: |
| 45 | return False |
| 46 | return True |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 47 | |
| 48 | |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 49 | def send_email(emails, topic, text, have_mutt, have_mail): |
| 50 | logFileName = working_path + '/' + 'tmpEmailContent' |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 51 | with open(logFileName, "w") as myfile: |
| 52 | myfile.writelines(text) |
| 53 | myfile.close() |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 54 | if have_mutt: |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 55 | execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 56 | elif have_mail: |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 57 | execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 58 | else: |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 59 | log("e-mail cannot be sent (mail or mutt not found)") |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 60 | |
| 61 | |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 62 | def send_email_with_attachments(branch, commit, last_commit, args, text, results_files, logFileName, have_mutt, have_mail): |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 63 | with open(logFileName, "w") as myfile: |
| 64 | myfile.writelines(text) |
| 65 | myfile.close() |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 66 | email_topic = '%s:%s Warning for %s:%s last_commit=%s speed<%s ratio<%s' % (email_header, pid, branch, commit, last_commit, args.lowerLimit, args.ratioLimit) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 67 | if have_mutt: |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 68 | execute('mutt -s "' + email_topic + '" ' + args.emails + ' -a ' + results_files + ' < ' + logFileName) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 69 | elif have_mail: |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 70 | execute('mail -s "' + email_topic + '" ' + args.emails + ' < ' + logFileName) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 71 | else: |
| 72 | log("e-mail cannot be sent (mail or mutt not found)") |
| 73 | |
| 74 | |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 75 | def git_get_branches(): |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 76 | execute('git fetch -p', verbose) |
| 77 | branches = execute('git branch -rl', verbose) |
| inikep | 6e5beea | 2016-07-19 13:09:00 +0200 | [diff] [blame] | 78 | output = [] |
| 79 | for line in branches: |
| 80 | if ("HEAD" not in line) and ("coverity_scan" not in line) and ("gh-pages" not in line): |
| 81 | output.append(line.strip()) |
| 82 | return output |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 83 | |
| 84 | |
| inikep | f2f59d7 | 2016-06-22 15:42:26 +0200 | [diff] [blame] | 85 | def git_get_changes(branch, commit, last_commit): |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 86 | fmt = '--format="%h: (%an) %s, %ar"' |
| 87 | if last_commit is None: |
| 88 | commits = execute('git log -n 10 %s %s' % (fmt, commit)) |
| 89 | else: |
| 90 | commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) |
| inikep | f2f59d7 | 2016-06-22 15:42:26 +0200 | [diff] [blame] | 91 | return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 92 | |
| 93 | |
| inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 94 | def get_last_results(resultsFileName): |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 95 | if not os.path.isfile(resultsFileName): |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 96 | return None, None, None, None |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 97 | commit = None |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 98 | csize = [] |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 99 | cspeed = [] |
| 100 | dspeed = [] |
| 101 | with open(resultsFileName,'r') as f: |
| 102 | for line in f: |
| 103 | words = line.split() |
| 104 | if len(words) == 2: # branch + commit |
| 105 | commit = words[1]; |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 106 | csize = [] |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 107 | cspeed = [] |
| 108 | dspeed = [] |
| 109 | if (len(words) == 8): # results |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 110 | csize.append(int(words[1])) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 111 | cspeed.append(float(words[3])) |
| 112 | dspeed.append(float(words[5])) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 113 | return commit, csize, cspeed, dspeed |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 114 | |
| 115 | |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 116 | def benchmark_and_compare(branch, commit, last_commit, args, executableName, resultsFileName, testFilePath, fileName, last_csize, last_cspeed, last_dspeed): |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 117 | sleepTime = 30 |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 118 | while os.getloadavg()[0] > args.maxLoadAvg: |
| 119 | log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], args.maxLoadAvg, sleepTime)) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 120 | time.sleep(sleepTime) |
| 121 | start_load = str(os.getloadavg()) |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 122 | result = execute('programs/%s -qi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), print_output=True) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 123 | end_load = str(os.getloadavg()) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 124 | linesExpected = args.lastCLevel + 2; |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 125 | if len(result) != linesExpected: |
| 126 | raise RuntimeError("ERROR: number of result lines=%d is different that expected %d\n%s" % (len(result), linesExpected, '\n'.join(result))) |
| 127 | with open(resultsFileName, "a") as myfile: |
| 128 | myfile.write(branch + " " + commit + "\n") |
| 129 | myfile.write('\n'.join(result) + '\n') |
| 130 | myfile.close() |
| 131 | if (last_cspeed == None): |
| 132 | log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) |
| 133 | return "" |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 134 | commit, csize, cspeed, dspeed = get_last_results(resultsFileName) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 135 | text = "" |
| 136 | for i in range(0, min(len(cspeed), len(last_cspeed))): |
| inikep | 164ce99 | 2016-07-25 10:35:53 +0200 | [diff] [blame] | 137 | 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)) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 138 | if (cspeed[i]/last_cspeed[i] < args.lowerLimit): |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 139 | 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) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 140 | if (dspeed[i]/last_dspeed[i] < args.lowerLimit): |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 141 | 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) |
| inikep | 164ce99 | 2016-07-25 10:35:53 +0200 | [diff] [blame] | 142 | if (float(last_csize[i])/csize[i] < args.ratioLimit): |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 143 | 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) |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 144 | if text: |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 145 | text = args.message + ("\nmaxLoadAvg=%s load average at start=%s end=%s last_commit=%s\n" % (args.maxLoadAvg, start_load, end_load, last_commit)) + text |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 146 | return text |
| 147 | |
| 148 | |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 149 | def update_config_file(branch, commit): |
| 150 | last_commit = None |
| 151 | commitFileName = working_path + "/commit_" + branch.replace("/", "_") + ".txt" |
| 152 | if os.path.isfile(commitFileName): |
| 153 | last_commit = file(commitFileName, 'r').read() |
| 154 | file(commitFileName, 'w').write(commit) |
| 155 | return last_commit |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 156 | |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 157 | |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 158 | def double_check(branch, commit, args, executableName, resultsFileName, filePath, fileName): |
| 159 | last_commit, csize, cspeed, dspeed = get_last_results(resultsFileName) |
| 160 | if not args.dry_run: |
| 161 | text = benchmark_and_compare(branch, commit, last_commit, args, executableName, resultsFileName, filePath, fileName, csize, cspeed, dspeed) |
| 162 | if text: |
| 163 | log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) |
| 164 | text = benchmark_and_compare(branch, commit, last_commit, args, executableName, resultsFileName, filePath, fileName, csize, cspeed, dspeed) |
| 165 | return text |
| 166 | |
| 167 | |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 168 | def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail): |
| inikep | 82babfc | 2016-06-22 20:06:42 +0200 | [diff] [blame] | 169 | local_branch = string.split(branch, '/')[1] |
| 170 | version = local_branch.rpartition('-')[2] + '_' + commit |
| 171 | if not args.dry_run: |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 172 | execute('make -C programs clean zstd zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 173 | logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt" |
| 174 | text_to_send = [] |
| 175 | results_files = "" |
| 176 | for filePath in testFilePaths: |
| 177 | fileName = filePath.rpartition('/')[2] |
| 178 | resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" |
| inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame^] | 179 | text = double_check(branch, commit, args, 'zstd', resultsFileName, filePath, fileName) |
| 180 | if text: |
| 181 | text_to_send.append(text) |
| 182 | results_files += resultsFileName + " " |
| 183 | resultsFileName = working_path + "/results32_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" |
| 184 | text = double_check(branch, commit, args, 'zstd32', resultsFileName, filePath, fileName) |
| 185 | if text: |
| 186 | text_to_send.append(text) |
| 187 | results_files += resultsFileName + " " |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 188 | if text_to_send: |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 189 | send_email_with_attachments(branch, commit, last_commit, args, text_to_send, results_files, logFileName, have_mutt, have_mail) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 190 | |
| 191 | |
| 192 | if __name__ == '__main__': |
| 193 | parser = argparse.ArgumentParser() |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 194 | parser.add_argument('testFileNames', help='file names list for speed benchmark') |
| 195 | parser.add_argument('emails', help='list of e-mail addresses to send warnings') |
| inikep | 1e375f1 | 2016-06-13 10:50:09 +0200 | [diff] [blame] | 196 | parser.add_argument('--message', help='attach an additional message to e-mail', default="") |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 197 | parser.add_argument('--repoURL', help='changes default repository URL', default=default_repo_url) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 198 | parser.add_argument('--lowerLimit', type=float, help='send email if speed is lower than given limit', default=0.98) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 199 | parser.add_argument('--ratioLimit', type=float, help='send email if ratio is lower than given limit', default=0.999) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 200 | parser.add_argument('--maxLoadAvg', type=float, help='maximum load average to start testing', default=0.75) |
| 201 | parser.add_argument('--lastCLevel', type=int, help='last compression level for testing', default=5) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 202 | parser.add_argument('--sleepTime', type=int, help='frequency of repository checking in seconds', default=300) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 203 | parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='not build', default=False) |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 204 | parser.add_argument('--verbose', action='store_true', help='more verbose logs', default=False) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 205 | args = parser.parse_args() |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 206 | verbose = args.verbose |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 207 | |
| 208 | # check if test files are accessible |
| 209 | testFileNames = args.testFileNames.split() |
| 210 | testFilePaths = [] |
| 211 | for fileName in testFileNames: |
| inikep | 4702067 | 2016-06-22 17:11:01 +0200 | [diff] [blame] | 212 | fileName = os.path.expanduser(fileName) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 213 | if os.path.isfile(fileName): |
| 214 | testFilePaths.append(os.path.abspath(fileName)) |
| 215 | else: |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 216 | log("ERROR: File not found: " + fileName) |
| 217 | exit(1) |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 218 | |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 219 | # check availability of e-mail senders |
| inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 220 | have_mutt = does_command_exist("mutt -h"); |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 221 | have_mail = does_command_exist("mail -V"); |
| inikep | f169029 | 2016-06-10 13:59:08 +0200 | [diff] [blame] | 222 | if not have_mutt and not have_mail: |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 223 | log("ERROR: e-mail senders 'mail' or 'mutt' not found") |
| 224 | exit(1) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 225 | |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 226 | if verbose: |
| 227 | print("PARAMETERS:\nrepoURL=%s" % args.repoURL) |
| 228 | print("working_path=%s" % working_path) |
| 229 | print("clone_path=%s" % clone_path) |
| 230 | print("testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths)) |
| 231 | print("message=%s" % args.message) |
| 232 | print("emails=%s" % args.emails) |
| 233 | print("maxLoadAvg=%s" % args.maxLoadAvg) |
| 234 | print("lowerLimit=%s" % args.lowerLimit) |
| inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 235 | print("ratioLimit=%s" % args.ratioLimit) |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 236 | print("lastCLevel=%s" % args.lastCLevel) |
| 237 | print("sleepTime=%s" % args.sleepTime) |
| 238 | print("dry_run=%s" % args.dry_run) |
| 239 | print("verbose=%s" % args.verbose) |
| 240 | print("have_mutt=%s have_mail=%s" % (have_mutt, have_mail)) |
| inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 241 | |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 242 | # clone ZSTD repo if needed |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 243 | if not os.path.isdir(working_path): |
| 244 | os.mkdir(working_path) |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 245 | if not os.path.isdir(clone_path): |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 246 | execute.cwd = working_path |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 247 | execute('git clone ' + args.repoURL) |
| 248 | if not os.path.isdir(clone_path): |
| 249 | log("ERROR: ZSTD clone not found: " + clone_path) |
| 250 | exit(1) |
| 251 | execute.cwd = clone_path |
| 252 | |
| 253 | # check if speedTest.pid already exists |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 254 | pidfile = "./speedTest.pid" |
| 255 | if os.path.isfile(pidfile): |
| 256 | log("ERROR: %s already exists, exiting" % pidfile) |
| 257 | exit(1) |
| 258 | |
| inikep | 4702067 | 2016-06-22 17:11:01 +0200 | [diff] [blame] | 259 | send_email(args.emails, email_header + ':%s test-zstd-speed.py has been started' % pid, args.message, have_mutt, have_mail) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 260 | file(pidfile, 'w').write(pid) |
| inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 261 | |
| inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 262 | while True: |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 263 | try: |
| 264 | loadavg = os.getloadavg()[0] |
| 265 | if (loadavg <= args.maxLoadAvg): |
| inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 266 | branches = git_get_branches() |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 267 | for branch in branches: |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 268 | commit = execute('git show -s --format=%h ' + branch, verbose)[0] |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 269 | last_commit = update_config_file(branch, commit) |
| 270 | if commit == last_commit: |
| 271 | log("skipping branch %s: head %s already processed" % (branch, commit)) |
| 272 | else: |
| 273 | log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) |
| inikep | 82babfc | 2016-06-22 20:06:42 +0200 | [diff] [blame] | 274 | execute('git checkout -- . && git checkout ' + branch) |
| 275 | print(git_get_changes(branch, commit, last_commit)) |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 276 | test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail) |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 277 | else: |
| 278 | log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg)) |
| inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 279 | if verbose: |
| 280 | log("sleep for %s seconds" % args.sleepTime) |
| inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 281 | time.sleep(args.sleepTime) |
| inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 282 | except Exception as e: |
| 283 | stack = traceback.format_exc() |
| 284 | email_topic = '%s:%s ERROR in %s:%s' % (email_header, pid, branch, commit) |
| 285 | send_email(args.emails, email_topic, stack, have_mutt, have_mail) |
| 286 | print(stack) |
| inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 287 | except KeyboardInterrupt: |
| inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 288 | os.unlink(pidfile) |
| inikep | 4702067 | 2016-06-22 17:11:01 +0200 | [diff] [blame] | 289 | send_email(args.emails, email_header + ':%s test-zstd-speed.py has been stopped' % pid, args.message, have_mutt, have_mail) |
| inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 290 | exit(0) |