Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Bimba Shrestha | eb76f78 | 2020-01-06 14:19:11 -0800 | [diff] [blame] | 2 | # THIS BENCHMARK IS BEING REPLACED BY automated-bencmarking.py |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 3 | |
Yann Collet | b0cb081 | 2017-08-31 12:20:50 -0700 | [diff] [blame] | 4 | # ################################################################ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 5 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 6 | # All rights reserved. |
| 7 | # |
Yann Collet | b0cb081 | 2017-08-31 12:20:50 -0700 | [diff] [blame] | 8 | # 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 Terrell | ac58c8d | 2020-03-26 15:19:05 -0700 | [diff] [blame] | 11 | # You may select, at your option, one of the above-listed licenses. |
Yann Collet | b0cb081 | 2017-08-31 12:20:50 -0700 | [diff] [blame] | 12 | # ########################################################################## |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 13 | |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 14 | # Limitations: |
| 15 | # - doesn't support filenames with spaces |
| 16 | # - dir1/zstd and dir2/zstd will be merged in a single results file |
| 17 | |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 18 | import argparse |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 19 | import os # getloadavg |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 20 | import string |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 21 | import subprocess |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 22 | import time # strftime |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 23 | import traceback |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 24 | import hashlib |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 25 | import platform # system |
Yann Collet | b752298 | 2016-07-22 05:02:27 +0200 | [diff] [blame] | 26 | |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 27 | script_version = 'v1.1.2 (2017-03-26)' |
Yann Collet | 33a0465 | 2016-09-02 22:11:49 -0700 | [diff] [blame] | 28 | default_repo_url = 'https://github.com/facebook/zstd.git' |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 29 | working_dir_name = 'speedTest' |
Yann Collet | b752298 | 2016-07-22 05:02:27 +0200 | [diff] [blame] | 30 | working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest |
| 31 | clone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 32 | email_header = 'ZSTD_speedTest' |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 33 | pid = str(os.getpid()) |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 34 | verbose = False |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 35 | clang_version = "unknown" |
| 36 | gcc_version = "unknown" |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 37 | args = None |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 38 | |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 39 | |
| 40 | def 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 | |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 47 | def log(text): |
inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 48 | print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 49 | |
inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 50 | |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 51 | def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True): |
| 52 | if print_command: |
| 53 | log("> " + command) |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 54 | 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") |
inikep | 2d9272f | 2016-06-21 19:28:51 +0200 | [diff] [blame] | 58 | if print_output: |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 59 | if stdout_lines: |
| 60 | print(stdout_lines) |
| 61 | if stderr_lines: |
| 62 | print(stderr_lines) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 63 | if popen.returncode is not None and popen.returncode != 0: |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 64 | 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() |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 68 | execute.cwd = None |
| 69 | |
| 70 | |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 71 | def does_command_exist(command): |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 72 | try: |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 73 | execute(command, verbose, False, False) |
| 74 | except Exception: |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 75 | return False |
| 76 | return True |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 77 | |
| 78 | |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 79 | def send_email(emails, topic, text, have_mutt, have_mail): |
| 80 | logFileName = working_path + '/' + 'tmpEmailContent' |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 81 | with open(logFileName, "w") as myfile: |
| 82 | myfile.writelines(text) |
| 83 | myfile.close() |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 84 | if have_mutt: |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 85 | execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 86 | elif have_mail: |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 87 | execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose) |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 88 | else: |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 89 | log("e-mail cannot be sent (mail or mutt not found)") |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 90 | |
| 91 | |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 92 | def send_email_with_attachments(branch, commit, last_commit, args, text, results_files, |
| 93 | logFileName, have_mutt, have_mail): |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 94 | with open(logFileName, "w") as myfile: |
| 95 | myfile.writelines(text) |
| 96 | myfile.close() |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 97 | email_topic = '[%s:%s] Warning for %s:%s last_commit=%s speed<%s ratio<%s' \ |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 98 | % (email_header, pid, branch, commit, last_commit, |
| 99 | args.lowerLimit, args.ratioLimit) |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 100 | if have_mutt: |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 101 | execute('mutt -s "' + email_topic + '" ' + args.emails + ' -a ' + results_files |
| 102 | + ' < ' + logFileName) |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 103 | elif have_mail: |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 104 | execute('mail -s "' + email_topic + '" ' + args.emails + ' < ' + logFileName) |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 105 | else: |
| 106 | log("e-mail cannot be sent (mail or mutt not found)") |
| 107 | |
| 108 | |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 109 | def git_get_branches(): |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 110 | execute('git fetch -p', verbose) |
| 111 | branches = execute('git branch -rl', verbose) |
inikep | 6e5beea | 2016-07-19 13:09:00 +0200 | [diff] [blame] | 112 | 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 |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 117 | |
| 118 | |
inikep | f2f59d7 | 2016-06-22 15:42:26 +0200 | [diff] [blame] | 119 | def git_get_changes(branch, commit, last_commit): |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 120 | 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)) |
inikep | f2f59d7 | 2016-06-22 15:42:26 +0200 | [diff] [blame] | 125 | 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] | 126 | |
| 127 | |
inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 128 | def get_last_results(resultsFileName): |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 129 | if not os.path.isfile(resultsFileName): |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 130 | return None, None, None, None |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 131 | commit = None |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 132 | csize = [] |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 133 | cspeed = [] |
| 134 | dspeed = [] |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 135 | with open(resultsFileName, 'r') as f: |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 136 | for line in f: |
| 137 | words = line.split() |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 138 | if len(words) <= 4: # branch + commit + compilerVer + md5 |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 139 | commit = words[1] |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 140 | csize = [] |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 141 | cspeed = [] |
| 142 | dspeed = [] |
inikep | d28afac | 2016-09-15 19:56:04 +0200 | [diff] [blame] | 143 | if (len(words) == 8) or (len(words) == 9): # results: "filename" or "XX files" |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 144 | csize.append(int(words[1])) |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 145 | cspeed.append(float(words[3])) |
| 146 | dspeed.append(float(words[5])) |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 147 | return commit, csize, cspeed, dspeed |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 148 | |
| 149 | |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 150 | def benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 151 | testFilePath, fileName, last_csize, last_cspeed, last_dspeed): |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 152 | sleepTime = 30 |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 153 | while os.getloadavg()[0] > args.maxLoadAvg: |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 154 | log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" |
| 155 | % (os.getloadavg()[0], args.maxLoadAvg, sleepTime)) |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 156 | time.sleep(sleepTime) |
| 157 | start_load = str(os.getloadavg()) |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 158 | osType = platform.system() |
| 159 | if osType == 'Linux': |
| 160 | cpuSelector = "taskset --cpu-list 0" |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 161 | else: |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 162 | 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) |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 167 | end_load = str(os.getloadavg()) |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 168 | linesExpected = args.lastCLevel + 1 |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 169 | 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: |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 172 | myfile.write('%s %s %s md5=%s\n' % (branch, commit, compilerVersion, md5sum)) |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 173 | 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 "" |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 178 | commit, csize, cspeed, dspeed = get_last_results(resultsFileName) |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 179 | text = "" |
| 180 | for i in range(0, min(len(cspeed), len(last_cspeed))): |
inikep | 164ce99 | 2016-07-25 10:35:53 +0200 | [diff] [blame] | 181 | 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] | 182 | if (cspeed[i]/last_cspeed[i] < args.lowerLimit): |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 183 | 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] | 184 | if (dspeed[i]/last_dspeed[i] < args.lowerLimit): |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 185 | 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] | 186 | if (float(last_csize[i])/csize[i] < args.ratioLimit): |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 187 | 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] | 188 | if text: |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 189 | 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 |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 190 | return text |
| 191 | |
| 192 | |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 193 | def update_config_file(branch, commit): |
| 194 | last_commit = None |
| 195 | commitFileName = working_path + "/commit_" + branch.replace("/", "_") + ".txt" |
| 196 | if os.path.isfile(commitFileName): |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 197 | with open(commitFileName, 'r') as infile: |
| 198 | last_commit = infile.read() |
| 199 | with open(commitFileName, 'w') as outfile: |
| 200 | outfile.write(commit) |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 201 | return last_commit |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 202 | |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 203 | |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 204 | def double_check(branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName): |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 205 | last_commit, csize, cspeed, dspeed = get_last_results(resultsFileName) |
| 206 | if not args.dry_run: |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 207 | text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed) |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 208 | if text: |
| 209 | log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 210 | text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed) |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 211 | return text |
| 212 | |
| 213 | |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 214 | def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail): |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 215 | local_branch = branch.split('/')[1] |
inikep | 82babfc | 2016-06-22 20:06:42 +0200 | [diff] [blame] | 216 | version = local_branch.rpartition('-')[2] + '_' + commit |
| 217 | if not args.dry_run: |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 218 | 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 && ' + |
inikep | d28afac | 2016-09-15 19:56:04 +0200 | [diff] [blame] | 220 | 'make -C programs clean zstd zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 221 | 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') |
inikep | b62e696 | 2016-08-23 13:54:37 +0200 | [diff] [blame] | 224 | print("md5(zstd)=%s\nmd5(zstd32)=%s\nmd5(zstd_clang)=%s" % (md5_zstd, md5_zstd32, md5_zstd_clang)) |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 225 | print("gcc_version=%s clang_version=%s" % (gcc_version, clang_version)) |
| 226 | |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 227 | logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt" |
| 228 | text_to_send = [] |
| 229 | results_files = "" |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 230 | if args.dictionary: |
| 231 | dictName = args.dictionary.rpartition('/')[2] |
| 232 | else: |
| 233 | dictName = None |
| 234 | |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 235 | for filePath in testFilePaths: |
| 236 | fileName = filePath.rpartition('/')[2] |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 237 | 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" |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 241 | text = double_check(branch, commit, args, 'zstd', md5_zstd, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName) |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 242 | if text: |
| 243 | text_to_send.append(text) |
| 244 | results_files += resultsFileName + " " |
| 245 | resultsFileName = working_path + "/results32_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 246 | text = double_check(branch, commit, args, 'zstd32', md5_zstd32, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName) |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 247 | if text: |
| 248 | text_to_send.append(text) |
| 249 | results_files += resultsFileName + " " |
| 250 | resultsFileName = working_path + "/resultsClang_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 251 | text = double_check(branch, commit, args, 'zstd_clang', md5_zstd_clang, 'clang_version='+clang_version, resultsFileName, filePath, fileName) |
inikep | 2214e46 | 2016-07-26 13:05:01 +0200 | [diff] [blame] | 252 | if text: |
| 253 | text_to_send.append(text) |
| 254 | results_files += resultsFileName + " " |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 255 | if text_to_send: |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 256 | 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] | 257 | |
| 258 | |
| 259 | if __name__ == '__main__': |
| 260 | parser = argparse.ArgumentParser() |
inikep | dd8905b | 2016-09-15 20:41:37 +0200 | [diff] [blame] | 261 | parser.add_argument('testFileNames', help='file or directory names list for speed benchmark') |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 262 | parser.add_argument('emails', help='list of e-mail addresses to send warnings') |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 263 | 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="") |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 265 | parser.add_argument('--repoURL', help='changes default repository URL', default=default_repo_url) |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 266 | 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) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 268 | 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) |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 270 | parser.add_argument('--sleepTime', '-s', type=int, help='frequency of repository checking in seconds', default=300) |
Przemyslaw Skibinski | 81c334b | 2016-10-28 20:40:21 +0200 | [diff] [blame] | 271 | parser.add_argument('--timeout', '-t', type=int, help='timeout for executing shell commands', default=1800) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 272 | parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='not build', default=False) |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 273 | parser.add_argument('--verbose', '-v', action='store_true', help='more verbose logs', default=False) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 274 | args = parser.parse_args() |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 275 | verbose = args.verbose |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 276 | |
| 277 | # check if test files are accessible |
| 278 | testFileNames = args.testFileNames.split() |
| 279 | testFilePaths = [] |
| 280 | for fileName in testFileNames: |
inikep | 4702067 | 2016-06-22 17:11:01 +0200 | [diff] [blame] | 281 | fileName = os.path.expanduser(fileName) |
inikep | d28afac | 2016-09-15 19:56:04 +0200 | [diff] [blame] | 282 | if os.path.isfile(fileName) or os.path.isdir(fileName): |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 283 | testFilePaths.append(os.path.abspath(fileName)) |
| 284 | else: |
inikep | d28afac | 2016-09-15 19:56:04 +0200 | [diff] [blame] | 285 | log("ERROR: File/directory not found: " + fileName) |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 286 | exit(1) |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 287 | |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 288 | # 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 | |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 295 | # check availability of e-mail senders |
Yann Collet | 8cebfd1 | 2016-07-31 01:59:23 +0200 | [diff] [blame] | 296 | have_mutt = does_command_exist("mutt -h") |
| 297 | have_mail = does_command_exist("mail -V") |
inikep | f169029 | 2016-06-10 13:59:08 +0200 | [diff] [blame] | 298 | if not have_mutt and not have_mail: |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 299 | log("ERROR: e-mail senders 'mail' or 'mutt' not found") |
| 300 | exit(1) |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 301 | |
Yann Collet | 41fefd5 | 2017-03-26 23:52:19 -0700 | [diff] [blame] | 302 | 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]; |
inikep | 0dad121 | 2016-09-12 14:17:47 +0200 | [diff] [blame] | 303 | gcc_version = execute("gcc -dumpversion", verbose)[0]; |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 304 | |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 305 | 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) |
inikep | ed0ea8d | 2016-09-15 20:31:29 +0200 | [diff] [blame] | 312 | print("dictionary=%s" % args.dictionary) |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 313 | print("maxLoadAvg=%s" % args.maxLoadAvg) |
| 314 | print("lowerLimit=%s" % args.lowerLimit) |
inikep | a4847eb | 2016-07-19 17:59:53 +0200 | [diff] [blame] | 315 | print("ratioLimit=%s" % args.ratioLimit) |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 316 | print("lastCLevel=%s" % args.lastCLevel) |
| 317 | print("sleepTime=%s" % args.sleepTime) |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 318 | print("timeout=%s" % args.timeout) |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 319 | 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)) |
inikep | c1b154a | 2016-06-10 12:53:12 +0200 | [diff] [blame] | 322 | |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 323 | # clone ZSTD repo if needed |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 324 | if not os.path.isdir(working_path): |
| 325 | os.mkdir(working_path) |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 326 | if not os.path.isdir(clone_path): |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 327 | execute.cwd = working_path |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 328 | 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 |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 335 | pidfile = "./speedTest.pid" |
| 336 | if os.path.isfile(pidfile): |
| 337 | log("ERROR: %s already exists, exiting" % pidfile) |
| 338 | exit(1) |
| 339 | |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 340 | 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 Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 341 | with open(pidfile, 'w') as the_file: |
| 342 | the_file.write(pid) |
inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 343 | |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 344 | branch = "" |
| 345 | commit = "" |
| 346 | first_time = True |
inikep | 9470b87 | 2016-06-09 12:54:06 +0200 | [diff] [blame] | 347 | while True: |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 348 | try: |
Przemyslaw Skibinski | 53e7f5c | 2016-10-28 19:24:16 +0200 | [diff] [blame] | 349 | if first_time: |
| 350 | first_time = False |
| 351 | else: |
| 352 | time.sleep(args.sleepTime) |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 353 | loadavg = os.getloadavg()[0] |
| 354 | if (loadavg <= args.maxLoadAvg): |
inikep | bcb9aad | 2016-06-22 13:07:58 +0200 | [diff] [blame] | 355 | branches = git_get_branches() |
inikep | 95da743 | 2016-06-22 12:12:35 +0200 | [diff] [blame] | 356 | for branch in branches: |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 357 | commit = execute('git show -s --format=%h ' + branch, verbose)[0] |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 358 | 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)) |
inikep | 82babfc | 2016-06-22 20:06:42 +0200 | [diff] [blame] | 363 | execute('git checkout -- . && git checkout ' + branch) |
| 364 | print(git_get_changes(branch, commit, last_commit)) |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 365 | test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail) |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 366 | else: |
| 367 | log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg)) |
inikep | 8c53ad5 | 2016-07-19 15:49:14 +0200 | [diff] [blame] | 368 | if verbose: |
| 369 | log("sleep for %s seconds" % args.sleepTime) |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 370 | except Exception as e: |
| 371 | stack = traceback.format_exc() |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 372 | email_topic = '[%s:%s] ERROR in %s:%s' % (email_header, pid, branch, commit) |
inikep | 116128c | 2016-06-22 18:12:57 +0200 | [diff] [blame] | 373 | send_email(args.emails, email_topic, stack, have_mutt, have_mail) |
| 374 | print(stack) |
inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 375 | except KeyboardInterrupt: |
inikep | d731de8 | 2016-06-21 11:26:17 +0200 | [diff] [blame] | 376 | os.unlink(pidfile) |
inikep | 2aeb932 | 2016-08-10 14:14:01 +0200 | [diff] [blame] | 377 | 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) |
inikep | c364ee7 | 2016-06-22 14:01:53 +0200 | [diff] [blame] | 378 | exit(0) |