blob: 71d75b8cccecfb36ce4bd8f3775ad9d342be3bf2 [file] [log] [blame]
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +02001#! /usr/bin/env python3
Bimba Shresthaeb76f782020-01-06 14:19:11 -08002# THIS BENCHMARK IS BEING REPLACED BY automated-bencmarking.py
inikep9470b872016-06-09 12:54:06 +02003
Yann Colletb0cb0812017-08-31 12:20:50 -07004# ################################################################
Elliott Hughes44aba642023-09-12 20:18:59 +00005# Copyright (c) Meta Platforms, Inc. and affiliates.
Yann Collet4ded9e52016-08-30 10:04:33 -07006# All rights reserved.
7#
Yann Colletb0cb0812017-08-31 12:20:50 -07008# This source code is licensed under both the BSD-style license (found in the
9# LICENSE file in the root directory of this source tree) and the GPLv2 (found
10# in the COPYING file in the root directory of this source tree).
Nick Terrellac58c8d2020-03-26 15:19:05 -070011# You may select, at your option, one of the above-listed licenses.
Yann Colletb0cb0812017-08-31 12:20:50 -070012# ##########################################################################
Yann Collet4ded9e52016-08-30 10:04:33 -070013
inikeped0ea8d2016-09-15 20:31:29 +020014# Limitations:
15# - doesn't support filenames with spaces
16# - dir1/zstd and dir2/zstd will be merged in a single results file
17
inikep9470b872016-06-09 12:54:06 +020018import argparse
Yann Collet41fefd52017-03-26 23:52:19 -070019import os # getloadavg
inikep9470b872016-06-09 12:54:06 +020020import string
Yann Collet8cebfd12016-07-31 01:59:23 +020021import subprocess
Yann Collet41fefd52017-03-26 23:52:19 -070022import time # strftime
inikep9470b872016-06-09 12:54:06 +020023import traceback
inikep2aeb9322016-08-10 14:14:01 +020024import hashlib
Yann Collet41fefd52017-03-26 23:52:19 -070025import platform # system
Yann Colletb7522982016-07-22 05:02:27 +020026
Yann Collet41fefd52017-03-26 23:52:19 -070027script_version = 'v1.1.2 (2017-03-26)'
Yann Collet33a04652016-09-02 22:11:49 -070028default_repo_url = 'https://github.com/facebook/zstd.git'
inikep95da7432016-06-22 12:12:35 +020029working_dir_name = 'speedTest'
Yann Colletb7522982016-07-22 05:02:27 +020030working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest
31clone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd
inikep2aeb9322016-08-10 14:14:01 +020032email_header = 'ZSTD_speedTest'
inikep95da7432016-06-22 12:12:35 +020033pid = str(os.getpid())
inikep8c53ad52016-07-19 15:49:14 +020034verbose = False
inikep0dad1212016-09-12 14:17:47 +020035clang_version = "unknown"
36gcc_version = "unknown"
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +020037args = None
inikep9470b872016-06-09 12:54:06 +020038
inikep2aeb9322016-08-10 14:14:01 +020039
40def hashfile(hasher, fname, blocksize=65536):
41 with open(fname, "rb") as f:
42 for chunk in iter(lambda: f.read(blocksize), b""):
43 hasher.update(chunk)
44 return hasher.hexdigest()
45
46
inikep9470b872016-06-09 12:54:06 +020047def log(text):
inikep2d9272f2016-06-21 19:28:51 +020048 print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text)
inikep9470b872016-06-09 12:54:06 +020049
inikep2d9272f2016-06-21 19:28:51 +020050
inikep8c53ad52016-07-19 15:49:14 +020051def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True):
52 if print_command:
53 log("> " + command)
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +020054 popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=param_shell, cwd=execute.cwd)
55 stdout_lines, stderr_lines = popen.communicate(timeout=args.timeout)
56 stderr_lines = stderr_lines.decode("utf-8")
57 stdout_lines = stdout_lines.decode("utf-8")
inikep2d9272f2016-06-21 19:28:51 +020058 if print_output:
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +020059 if stdout_lines:
60 print(stdout_lines)
61 if stderr_lines:
62 print(stderr_lines)
inikep9470b872016-06-09 12:54:06 +020063 if popen.returncode is not None and popen.returncode != 0:
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +020064 if stderr_lines and not print_output and print_error:
65 print(stderr_lines)
66 raise RuntimeError(stdout_lines + stderr_lines)
67 return (stdout_lines + stderr_lines).splitlines()
inikep9470b872016-06-09 12:54:06 +020068execute.cwd = None
69
70
inikepc1b154a2016-06-10 12:53:12 +020071def does_command_exist(command):
inikep95da7432016-06-22 12:12:35 +020072 try:
Yann Collet8cebfd12016-07-31 01:59:23 +020073 execute(command, verbose, False, False)
74 except Exception:
inikep95da7432016-06-22 12:12:35 +020075 return False
76 return True
inikepc1b154a2016-06-10 12:53:12 +020077
78
inikep95da7432016-06-22 12:12:35 +020079def send_email(emails, topic, text, have_mutt, have_mail):
80 logFileName = working_path + '/' + 'tmpEmailContent'
inikep9470b872016-06-09 12:54:06 +020081 with open(logFileName, "w") as myfile:
82 myfile.writelines(text)
83 myfile.close()
inikepc1b154a2016-06-10 12:53:12 +020084 if have_mutt:
inikep8c53ad52016-07-19 15:49:14 +020085 execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose)
inikepc1b154a2016-06-10 12:53:12 +020086 elif have_mail:
inikep8c53ad52016-07-19 15:49:14 +020087 execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose)
inikepc1b154a2016-06-10 12:53:12 +020088 else:
inikep95da7432016-06-22 12:12:35 +020089 log("e-mail cannot be sent (mail or mutt not found)")
inikep9470b872016-06-09 12:54:06 +020090
91
Yann Collet8cebfd12016-07-31 01:59:23 +020092def send_email_with_attachments(branch, commit, last_commit, args, text, results_files,
93 logFileName, have_mutt, have_mail):
inikep95da7432016-06-22 12:12:35 +020094 with open(logFileName, "w") as myfile:
95 myfile.writelines(text)
96 myfile.close()
inikep2aeb9322016-08-10 14:14:01 +020097 email_topic = '[%s:%s] Warning for %s:%s last_commit=%s speed<%s ratio<%s' \
Yann Collet8cebfd12016-07-31 01:59:23 +020098 % (email_header, pid, branch, commit, last_commit,
99 args.lowerLimit, args.ratioLimit)
inikep95da7432016-06-22 12:12:35 +0200100 if have_mutt:
Yann Collet8cebfd12016-07-31 01:59:23 +0200101 execute('mutt -s "' + email_topic + '" ' + args.emails + ' -a ' + results_files
102 + ' < ' + logFileName)
inikep95da7432016-06-22 12:12:35 +0200103 elif have_mail:
inikepa4847eb2016-07-19 17:59:53 +0200104 execute('mail -s "' + email_topic + '" ' + args.emails + ' < ' + logFileName)
inikep95da7432016-06-22 12:12:35 +0200105 else:
106 log("e-mail cannot be sent (mail or mutt not found)")
107
108
inikepbcb9aad2016-06-22 13:07:58 +0200109def git_get_branches():
inikep8c53ad52016-07-19 15:49:14 +0200110 execute('git fetch -p', verbose)
111 branches = execute('git branch -rl', verbose)
inikep6e5beea2016-07-19 13:09:00 +0200112 output = []
113 for line in branches:
114 if ("HEAD" not in line) and ("coverity_scan" not in line) and ("gh-pages" not in line):
115 output.append(line.strip())
116 return output
inikepbcb9aad2016-06-22 13:07:58 +0200117
118
inikepf2f59d72016-06-22 15:42:26 +0200119def git_get_changes(branch, commit, last_commit):
inikepbcb9aad2016-06-22 13:07:58 +0200120 fmt = '--format="%h: (%an) %s, %ar"'
121 if last_commit is None:
122 commits = execute('git log -n 10 %s %s' % (fmt, commit))
123 else:
124 commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit))
inikepf2f59d72016-06-22 15:42:26 +0200125 return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits)
inikepbcb9aad2016-06-22 13:07:58 +0200126
127
inikepc364ee72016-06-22 14:01:53 +0200128def get_last_results(resultsFileName):
inikepbcb9aad2016-06-22 13:07:58 +0200129 if not os.path.isfile(resultsFileName):
inikepa4847eb2016-07-19 17:59:53 +0200130 return None, None, None, None
inikepbcb9aad2016-06-22 13:07:58 +0200131 commit = None
inikepa4847eb2016-07-19 17:59:53 +0200132 csize = []
inikepbcb9aad2016-06-22 13:07:58 +0200133 cspeed = []
134 dspeed = []
Yann Collet8cebfd12016-07-31 01:59:23 +0200135 with open(resultsFileName, 'r') as f:
inikepbcb9aad2016-06-22 13:07:58 +0200136 for line in f:
137 words = line.split()
inikep0dad1212016-09-12 14:17:47 +0200138 if len(words) <= 4: # branch + commit + compilerVer + md5
Yann Collet8cebfd12016-07-31 01:59:23 +0200139 commit = words[1]
inikepa4847eb2016-07-19 17:59:53 +0200140 csize = []
inikepbcb9aad2016-06-22 13:07:58 +0200141 cspeed = []
142 dspeed = []
inikepd28afac2016-09-15 19:56:04 +0200143 if (len(words) == 8) or (len(words) == 9): # results: "filename" or "XX files"
inikepa4847eb2016-07-19 17:59:53 +0200144 csize.append(int(words[1]))
inikepbcb9aad2016-06-22 13:07:58 +0200145 cspeed.append(float(words[3]))
146 dspeed.append(float(words[5]))
inikepa4847eb2016-07-19 17:59:53 +0200147 return commit, csize, cspeed, dspeed
inikepbcb9aad2016-06-22 13:07:58 +0200148
149
inikep0dad1212016-09-12 14:17:47 +0200150def benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName,
Yann Collet8cebfd12016-07-31 01:59:23 +0200151 testFilePath, fileName, last_csize, last_cspeed, last_dspeed):
inikepbcb9aad2016-06-22 13:07:58 +0200152 sleepTime = 30
inikepa4847eb2016-07-19 17:59:53 +0200153 while os.getloadavg()[0] > args.maxLoadAvg:
Yann Collet8cebfd12016-07-31 01:59:23 +0200154 log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds"
155 % (os.getloadavg()[0], args.maxLoadAvg, sleepTime))
inikepbcb9aad2016-06-22 13:07:58 +0200156 time.sleep(sleepTime)
157 start_load = str(os.getloadavg())
Yann Collet41fefd52017-03-26 23:52:19 -0700158 osType = platform.system()
159 if osType == 'Linux':
160 cpuSelector = "taskset --cpu-list 0"
inikeped0ea8d2016-09-15 20:31:29 +0200161 else:
Yann Collet41fefd52017-03-26 23:52:19 -0700162 cpuSelector = ""
163 if args.dictionary:
164 result = execute('%s programs/%s -rqi5b1e%s -D %s %s' % (cpuSelector, executableName, args.lastCLevel, args.dictionary, testFilePath), print_output=True)
165 else:
166 result = execute('%s programs/%s -rqi5b1e%s %s' % (cpuSelector, executableName, args.lastCLevel, testFilePath), print_output=True)
inikepbcb9aad2016-06-22 13:07:58 +0200167 end_load = str(os.getloadavg())
Yann Collet8cebfd12016-07-31 01:59:23 +0200168 linesExpected = args.lastCLevel + 1
inikepbcb9aad2016-06-22 13:07:58 +0200169 if len(result) != linesExpected:
170 raise RuntimeError("ERROR: number of result lines=%d is different that expected %d\n%s" % (len(result), linesExpected, '\n'.join(result)))
171 with open(resultsFileName, "a") as myfile:
inikep0dad1212016-09-12 14:17:47 +0200172 myfile.write('%s %s %s md5=%s\n' % (branch, commit, compilerVersion, md5sum))
inikepbcb9aad2016-06-22 13:07:58 +0200173 myfile.write('\n'.join(result) + '\n')
174 myfile.close()
175 if (last_cspeed == None):
176 log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName))
177 return ""
inikepa4847eb2016-07-19 17:59:53 +0200178 commit, csize, cspeed, dspeed = get_last_results(resultsFileName)
inikepbcb9aad2016-06-22 13:07:58 +0200179 text = ""
180 for i in range(0, min(len(cspeed), len(last_cspeed))):
inikep164ce992016-07-25 10:35:53 +0200181 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))
inikepa4847eb2016-07-19 17:59:53 +0200182 if (cspeed[i]/last_cspeed[i] < args.lowerLimit):
inikep2214e462016-07-26 13:05:01 +0200183 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)
inikepa4847eb2016-07-19 17:59:53 +0200184 if (dspeed[i]/last_dspeed[i] < args.lowerLimit):
inikep2214e462016-07-26 13:05:01 +0200185 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)
inikep164ce992016-07-25 10:35:53 +0200186 if (float(last_csize[i])/csize[i] < args.ratioLimit):
inikep2214e462016-07-26 13:05:01 +0200187 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)
inikepbcb9aad2016-06-22 13:07:58 +0200188 if text:
inikep0dad1212016-09-12 14:17:47 +0200189 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
inikepbcb9aad2016-06-22 13:07:58 +0200190 return text
191
192
inikep116128c2016-06-22 18:12:57 +0200193def update_config_file(branch, commit):
194 last_commit = None
195 commitFileName = working_path + "/commit_" + branch.replace("/", "_") + ".txt"
196 if os.path.isfile(commitFileName):
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200197 with open(commitFileName, 'r') as infile:
198 last_commit = infile.read()
199 with open(commitFileName, 'w') as outfile:
200 outfile.write(commit)
inikep116128c2016-06-22 18:12:57 +0200201 return last_commit
inikep9470b872016-06-09 12:54:06 +0200202
inikep9470b872016-06-09 12:54:06 +0200203
inikep0dad1212016-09-12 14:17:47 +0200204def double_check(branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName):
inikep2214e462016-07-26 13:05:01 +0200205 last_commit, csize, cspeed, dspeed = get_last_results(resultsFileName)
206 if not args.dry_run:
inikep0dad1212016-09-12 14:17:47 +0200207 text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed)
inikep2214e462016-07-26 13:05:01 +0200208 if text:
209 log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit))
inikep0dad1212016-09-12 14:17:47 +0200210 text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed)
inikep2214e462016-07-26 13:05:01 +0200211 return text
212
213
inikep116128c2016-06-22 18:12:57 +0200214def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail):
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200215 local_branch = branch.split('/')[1]
inikep82babfc2016-06-22 20:06:42 +0200216 version = local_branch.rpartition('-')[2] + '_' + commit
217 if not args.dry_run:
inikep2aeb9322016-08-10 14:14:01 +0200218 execute('make -C programs clean zstd CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -DZSTD_GIT_COMMIT=%s" && ' % version +
219 'mv programs/zstd programs/zstd_clang && ' +
inikepd28afac2016-09-15 19:56:04 +0200220 'make -C programs clean zstd zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version)
inikep2aeb9322016-08-10 14:14:01 +0200221 md5_zstd = hashfile(hashlib.md5(), clone_path + '/programs/zstd')
222 md5_zstd32 = hashfile(hashlib.md5(), clone_path + '/programs/zstd32')
223 md5_zstd_clang = hashfile(hashlib.md5(), clone_path + '/programs/zstd_clang')
inikepb62e6962016-08-23 13:54:37 +0200224 print("md5(zstd)=%s\nmd5(zstd32)=%s\nmd5(zstd_clang)=%s" % (md5_zstd, md5_zstd32, md5_zstd_clang))
inikep0dad1212016-09-12 14:17:47 +0200225 print("gcc_version=%s clang_version=%s" % (gcc_version, clang_version))
226
inikep116128c2016-06-22 18:12:57 +0200227 logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt"
228 text_to_send = []
229 results_files = ""
inikeped0ea8d2016-09-15 20:31:29 +0200230 if args.dictionary:
231 dictName = args.dictionary.rpartition('/')[2]
232 else:
233 dictName = None
234
inikep116128c2016-06-22 18:12:57 +0200235 for filePath in testFilePaths:
236 fileName = filePath.rpartition('/')[2]
inikeped0ea8d2016-09-15 20:31:29 +0200237 if dictName:
238 resultsFileName = working_path + "/" + dictName.replace(".", "_") + "_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
239 else:
240 resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
inikep0dad1212016-09-12 14:17:47 +0200241 text = double_check(branch, commit, args, 'zstd', md5_zstd, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName)
inikep2214e462016-07-26 13:05:01 +0200242 if text:
243 text_to_send.append(text)
244 results_files += resultsFileName + " "
245 resultsFileName = working_path + "/results32_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
inikep0dad1212016-09-12 14:17:47 +0200246 text = double_check(branch, commit, args, 'zstd32', md5_zstd32, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName)
inikep2aeb9322016-08-10 14:14:01 +0200247 if text:
248 text_to_send.append(text)
249 results_files += resultsFileName + " "
250 resultsFileName = working_path + "/resultsClang_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
inikep0dad1212016-09-12 14:17:47 +0200251 text = double_check(branch, commit, args, 'zstd_clang', md5_zstd_clang, 'clang_version='+clang_version, resultsFileName, filePath, fileName)
inikep2214e462016-07-26 13:05:01 +0200252 if text:
253 text_to_send.append(text)
254 results_files += resultsFileName + " "
inikep116128c2016-06-22 18:12:57 +0200255 if text_to_send:
inikepa4847eb2016-07-19 17:59:53 +0200256 send_email_with_attachments(branch, commit, last_commit, args, text_to_send, results_files, logFileName, have_mutt, have_mail)
inikep9470b872016-06-09 12:54:06 +0200257
258
259if __name__ == '__main__':
260 parser = argparse.ArgumentParser()
inikepdd8905b2016-09-15 20:41:37 +0200261 parser.add_argument('testFileNames', help='file or directory names list for speed benchmark')
inikepc1b154a2016-06-10 12:53:12 +0200262 parser.add_argument('emails', help='list of e-mail addresses to send warnings')
inikeped0ea8d2016-09-15 20:31:29 +0200263 parser.add_argument('--dictionary', '-D', help='path to the dictionary')
264 parser.add_argument('--message', '-m', help='attach an additional message to e-mail', default="")
inikepd731de82016-06-21 11:26:17 +0200265 parser.add_argument('--repoURL', help='changes default repository URL', default=default_repo_url)
inikeped0ea8d2016-09-15 20:31:29 +0200266 parser.add_argument('--lowerLimit', '-l', type=float, help='send email if speed is lower than given limit', default=0.98)
267 parser.add_argument('--ratioLimit', '-r', type=float, help='send email if ratio is lower than given limit', default=0.999)
inikep9470b872016-06-09 12:54:06 +0200268 parser.add_argument('--maxLoadAvg', type=float, help='maximum load average to start testing', default=0.75)
269 parser.add_argument('--lastCLevel', type=int, help='last compression level for testing', default=5)
inikeped0ea8d2016-09-15 20:31:29 +0200270 parser.add_argument('--sleepTime', '-s', type=int, help='frequency of repository checking in seconds', default=300)
Przemyslaw Skibinski81c334b2016-10-28 20:40:21 +0200271 parser.add_argument('--timeout', '-t', type=int, help='timeout for executing shell commands', default=1800)
inikep9470b872016-06-09 12:54:06 +0200272 parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='not build', default=False)
inikeped0ea8d2016-09-15 20:31:29 +0200273 parser.add_argument('--verbose', '-v', action='store_true', help='more verbose logs', default=False)
inikep9470b872016-06-09 12:54:06 +0200274 args = parser.parse_args()
inikep8c53ad52016-07-19 15:49:14 +0200275 verbose = args.verbose
inikep9470b872016-06-09 12:54:06 +0200276
277 # check if test files are accessible
278 testFileNames = args.testFileNames.split()
279 testFilePaths = []
280 for fileName in testFileNames:
inikep47020672016-06-22 17:11:01 +0200281 fileName = os.path.expanduser(fileName)
inikepd28afac2016-09-15 19:56:04 +0200282 if os.path.isfile(fileName) or os.path.isdir(fileName):
inikep9470b872016-06-09 12:54:06 +0200283 testFilePaths.append(os.path.abspath(fileName))
284 else:
inikepd28afac2016-09-15 19:56:04 +0200285 log("ERROR: File/directory not found: " + fileName)
inikepd731de82016-06-21 11:26:17 +0200286 exit(1)
inikep9470b872016-06-09 12:54:06 +0200287
inikeped0ea8d2016-09-15 20:31:29 +0200288 # check if dictionary is accessible
289 if args.dictionary:
290 args.dictionary = os.path.abspath(os.path.expanduser(args.dictionary))
291 if not os.path.isfile(args.dictionary):
292 log("ERROR: Dictionary not found: " + args.dictionary)
293 exit(1)
294
inikepc1b154a2016-06-10 12:53:12 +0200295 # check availability of e-mail senders
Yann Collet8cebfd12016-07-31 01:59:23 +0200296 have_mutt = does_command_exist("mutt -h")
297 have_mail = does_command_exist("mail -V")
inikepf1690292016-06-10 13:59:08 +0200298 if not have_mutt and not have_mail:
inikepd731de82016-06-21 11:26:17 +0200299 log("ERROR: e-mail senders 'mail' or 'mutt' not found")
300 exit(1)
inikepc1b154a2016-06-10 12:53:12 +0200301
Yann Collet41fefd52017-03-26 23:52:19 -0700302 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];
inikep0dad1212016-09-12 14:17:47 +0200303 gcc_version = execute("gcc -dumpversion", verbose)[0];
inikeped0ea8d2016-09-15 20:31:29 +0200304
inikep8c53ad52016-07-19 15:49:14 +0200305 if verbose:
306 print("PARAMETERS:\nrepoURL=%s" % args.repoURL)
307 print("working_path=%s" % working_path)
308 print("clone_path=%s" % clone_path)
309 print("testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths))
310 print("message=%s" % args.message)
311 print("emails=%s" % args.emails)
inikeped0ea8d2016-09-15 20:31:29 +0200312 print("dictionary=%s" % args.dictionary)
inikep8c53ad52016-07-19 15:49:14 +0200313 print("maxLoadAvg=%s" % args.maxLoadAvg)
314 print("lowerLimit=%s" % args.lowerLimit)
inikepa4847eb2016-07-19 17:59:53 +0200315 print("ratioLimit=%s" % args.ratioLimit)
inikep8c53ad52016-07-19 15:49:14 +0200316 print("lastCLevel=%s" % args.lastCLevel)
317 print("sleepTime=%s" % args.sleepTime)
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200318 print("timeout=%s" % args.timeout)
inikep8c53ad52016-07-19 15:49:14 +0200319 print("dry_run=%s" % args.dry_run)
320 print("verbose=%s" % args.verbose)
321 print("have_mutt=%s have_mail=%s" % (have_mutt, have_mail))
inikepc1b154a2016-06-10 12:53:12 +0200322
inikepd731de82016-06-21 11:26:17 +0200323 # clone ZSTD repo if needed
inikep95da7432016-06-22 12:12:35 +0200324 if not os.path.isdir(working_path):
325 os.mkdir(working_path)
inikepd731de82016-06-21 11:26:17 +0200326 if not os.path.isdir(clone_path):
inikep95da7432016-06-22 12:12:35 +0200327 execute.cwd = working_path
inikepd731de82016-06-21 11:26:17 +0200328 execute('git clone ' + args.repoURL)
329 if not os.path.isdir(clone_path):
330 log("ERROR: ZSTD clone not found: " + clone_path)
331 exit(1)
332 execute.cwd = clone_path
333
334 # check if speedTest.pid already exists
inikepd731de82016-06-21 11:26:17 +0200335 pidfile = "./speedTest.pid"
336 if os.path.isfile(pidfile):
337 log("ERROR: %s already exists, exiting" % pidfile)
338 exit(1)
339
inikep2aeb9322016-08-10 14:14:01 +0200340 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)
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200341 with open(pidfile, 'w') as the_file:
342 the_file.write(pid)
inikepc364ee72016-06-22 14:01:53 +0200343
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200344 branch = ""
345 commit = ""
346 first_time = True
inikep9470b872016-06-09 12:54:06 +0200347 while True:
inikepd731de82016-06-21 11:26:17 +0200348 try:
Przemyslaw Skibinski53e7f5c2016-10-28 19:24:16 +0200349 if first_time:
350 first_time = False
351 else:
352 time.sleep(args.sleepTime)
inikepd731de82016-06-21 11:26:17 +0200353 loadavg = os.getloadavg()[0]
354 if (loadavg <= args.maxLoadAvg):
inikepbcb9aad2016-06-22 13:07:58 +0200355 branches = git_get_branches()
inikep95da7432016-06-22 12:12:35 +0200356 for branch in branches:
inikep8c53ad52016-07-19 15:49:14 +0200357 commit = execute('git show -s --format=%h ' + branch, verbose)[0]
inikep116128c2016-06-22 18:12:57 +0200358 last_commit = update_config_file(branch, commit)
359 if commit == last_commit:
360 log("skipping branch %s: head %s already processed" % (branch, commit))
361 else:
362 log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit))
inikep82babfc2016-06-22 20:06:42 +0200363 execute('git checkout -- . && git checkout ' + branch)
364 print(git_get_changes(branch, commit, last_commit))
inikep116128c2016-06-22 18:12:57 +0200365 test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail)
inikepd731de82016-06-21 11:26:17 +0200366 else:
367 log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg))
inikep8c53ad52016-07-19 15:49:14 +0200368 if verbose:
369 log("sleep for %s seconds" % args.sleepTime)
inikep116128c2016-06-22 18:12:57 +0200370 except Exception as e:
371 stack = traceback.format_exc()
inikep2aeb9322016-08-10 14:14:01 +0200372 email_topic = '[%s:%s] ERROR in %s:%s' % (email_header, pid, branch, commit)
inikep116128c2016-06-22 18:12:57 +0200373 send_email(args.emails, email_topic, stack, have_mutt, have_mail)
374 print(stack)
inikepc364ee72016-06-22 14:01:53 +0200375 except KeyboardInterrupt:
inikepd731de82016-06-21 11:26:17 +0200376 os.unlink(pidfile)
inikep2aeb9322016-08-10 14:14:01 +0200377 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)
inikepc364ee72016-06-22 14:01:53 +0200378 exit(0)