From 2d9272f1dd6a912e3953e87ef45580eb5077e610 Mon Sep 17 00:00:00 2001 From: inikep Date: Tue, 21 Jun 2016 19:28:51 +0200 Subject: [PATCH 1/6] test-zstd-speed.py: improved formatting --- tests/test-zstd-speed.py | 72 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 5cc07fb37..2c13fd386 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -13,44 +13,41 @@ test_dir_name = 'speedTest' email_header = '[ZSTD_speedTest]' def log(text): - print time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text + print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) -def execute(command, print_output=False, print_error=True): + +def execute(command, print_output=False, print_error=True, param_shell=True): log("> " + command) - popen = Popen(command, stdout=PIPE, stderr=PIPE, shell=True, cwd=execute.cwd) + popen = Popen(command, stdout=PIPE, stderr=PIPE, shell=param_shell, cwd=execute.cwd) itout = iter(popen.stdout.readline, b"") iterr = iter(popen.stderr.readline, b"") stdout_lines = list(itout) - if print_output: - print ''.join(stdout_lines) stderr_lines = list(iterr) - if print_output: - print ''.join(stderr_lines) popen.communicate() + if print_output: + print(''.join(stdout_lines)) + print(''.join(stderr_lines)) if popen.returncode is not None and popen.returncode != 0: if not print_output and print_error: - print ''.join(stderr_lines) - raise RuntimeError(''.join(stderr_lines)) - return stdout_lines + stderr_lines + print(''.join(stderr_lines)) + return popen.returncode, stdout_lines, stderr_lines execute.cwd = None def does_command_exist(command): - try: - execute(command, False, False); - except Exception as e: - return False - return True + result, stdoutdata, stderrdata = execute(command, False, False); + return result == 0 def fetch(): execute('git fetch -p') - output = execute('git branch -rl') + returncode, output, stderrdata = execute('git branch -rl') for line in output: if "HEAD" in line: - output.remove(line) # remove "origin/HEAD -> origin/dev" + output.remove(line) # remove "origin/HEAD -> origin/dev" branches = map(lambda l: l.strip(), output) - return map(lambda b: (b, execute('git show -s --format=%h ' + b)[0].strip()), branches) + print("branches=%s" % branches) + return map(lambda b: (b, execute('git show -s --format=%h ' + b)[1][0].strip()), branches) def notify(branch, commit, last_commit): @@ -58,14 +55,13 @@ def notify(branch, commit, last_commit): branch = branch.split('/')[1] fmt = '--format="%h: (%an) %s, %ar"' if last_commit is None: - commits = execute('git log -n 10 %s %s' % (fmt, commit)) + returncode, commits, stderrdata = execute('git log -n 10 %s %s' % (fmt, commit)) else: - commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - + returncode, commits, stderrdata = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) text = text_tmpl.substitute({'last_commit': last_commit, 'commits': ''.join(commits)}) - print str("commits for %s: %s" % (commit, text)) - + print(str("commits for %s: %s" % (commit, text))) + def compile(branch, commit, dry_run): local_branch = string.split(branch, '/')[1] version = local_branch.rpartition('-')[2] @@ -102,7 +98,7 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], maxLoadAvg, sleepTime)) time.sleep(sleepTime) start_load = str(os.getloadavg()) - result = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath) + returncode, result, stderrdata = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath) end_load = str(os.getloadavg()) linesExpected = lastCLevel + 2; if len(result) != linesExpected: @@ -184,7 +180,7 @@ def check_branches(args, test_path, testFilePaths, have_mutt, have_mail): except Exception as e: stack = traceback.format_exc() log("ERROR: build %s, error %s" % (branch, str(e)) ) - print stack + print(stack) if __name__ == '__main__': @@ -214,24 +210,24 @@ if __name__ == '__main__': clone_path = test_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd # check availability of e-mail senders - have_mutt = does_command_exist("mutt --help"); + have_mutt = does_command_exist("mutt -h"); have_mail = does_command_exist("mail -V"); if not have_mutt and not have_mail: log("ERROR: e-mail senders 'mail' or 'mutt' not found") exit(1) - print "PARAMETERS:\nrepoURL=%s" % args.repoURL - print "test_path=%s" % test_path - print "clone_path=%s" % clone_path - print "testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths) - print "message=%s" % args.message - print "emails=%s" % args.emails - print "maxLoadAvg=%s" % args.maxLoadAvg - print "lowerLimit=%s" % args.lowerLimit - print "lastCLevel=%s" % args.lastCLevel - print "sleepTime=%s" % args.sleepTime - print "dry_run=%s" % args.dry_run - print "have_mutt=%s have_mail=%s" % (have_mutt, have_mail) + print("PARAMETERS:\nrepoURL=%s" % args.repoURL) + print("test_path=%s" % test_path) + print("clone_path=%s" % clone_path) + print("testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths)) + print("message=%s" % args.message) + print("emails=%s" % args.emails) + print("maxLoadAvg=%s" % args.maxLoadAvg) + print("lowerLimit=%s" % args.lowerLimit) + print("lastCLevel=%s" % args.lastCLevel) + print("sleepTime=%s" % args.sleepTime) + print("dry_run=%s" % args.dry_run) + print("have_mutt=%s have_mail=%s" % (have_mutt, have_mail)) # clone ZSTD repo if needed if not os.path.isdir(test_path): From 95da743a56cc0744569bd6467932e68c632e213a Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 22 Jun 2016 12:12:35 +0200 Subject: [PATCH 2/6] test-zstd-speed.py: send e-mail in case of error --- tests/test-zstd-speed.py | 130 +++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 2c13fd386..c693b2188 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -1,16 +1,19 @@ #! /usr/bin/env python -# execute(), fetch(), notify() are based on https://github.com/getlantern/build-automation/blob/master/build.py import argparse import os import string import time import traceback -from subprocess import Popen, PIPE +import subprocess default_repo_url = 'https://github.com/Cyan4973/zstd.git' -test_dir_name = 'speedTest' +working_dir_name = 'speedTest' +working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest +clone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd email_header = '[ZSTD_speedTest]' +pid = str(os.getpid()) + def log(text): print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) @@ -18,36 +21,34 @@ def log(text): def execute(command, print_output=False, print_error=True, param_shell=True): log("> " + command) - popen = Popen(command, stdout=PIPE, stderr=PIPE, shell=param_shell, cwd=execute.cwd) - itout = iter(popen.stdout.readline, b"") - iterr = iter(popen.stderr.readline, b"") - stdout_lines = list(itout) - stderr_lines = list(iterr) - popen.communicate() + popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=param_shell, cwd=execute.cwd) + stdout = popen.communicate()[0] + stdout_lines = stdout.splitlines() if print_output: - print(''.join(stdout_lines)) - print(''.join(stderr_lines)) + print('\n'.join(stdout_lines)) if popen.returncode is not None and popen.returncode != 0: if not print_output and print_error: - print(''.join(stderr_lines)) - return popen.returncode, stdout_lines, stderr_lines + print('\n'.join(stdout_lines)) + raise RuntimeError('\n'.join(stdout_lines)) + return stdout_lines execute.cwd = None def does_command_exist(command): - result, stdoutdata, stderrdata = execute(command, False, False); - return result == 0 + try: + execute(command, False, False); + except Exception as e: + return False + return True -def fetch(): +def get_branches(): execute('git fetch -p') - returncode, output, stderrdata = execute('git branch -rl') + output = execute('git branch -rl') for line in output: if "HEAD" in line: output.remove(line) # remove "origin/HEAD -> origin/dev" - branches = map(lambda l: l.strip(), output) - print("branches=%s" % branches) - return map(lambda b: (b, execute('git show -s --format=%h ' + b)[1][0].strip()), branches) + return map(lambda l: l.strip(), output) def notify(branch, commit, last_commit): @@ -55,10 +56,10 @@ def notify(branch, commit, last_commit): branch = branch.split('/')[1] fmt = '--format="%h: (%an) %s, %ar"' if last_commit is None: - returncode, commits, stderrdata = execute('git log -n 10 %s %s' % (fmt, commit)) + commits = execute('git log -n 10 %s %s' % (fmt, commit)) else: - returncode, commits, stderrdata = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - text = text_tmpl.substitute({'last_commit': last_commit, 'commits': ''.join(commits)}) + commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) + text = text_tmpl.substitute({'last_commit': last_commit, 'commits': '\n'.join(commits)}) print(str("commits for %s: %s" % (commit, text))) @@ -98,21 +99,22 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], maxLoadAvg, sleepTime)) time.sleep(sleepTime) start_load = str(os.getloadavg()) - returncode, result, stderrdata = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath) + result = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath, print_output=True) end_load = str(os.getloadavg()) linesExpected = lastCLevel + 2; if len(result) != linesExpected: - log("ERROR: number of result lines=%d is different that expected %d" % (len(result), linesExpected)) - return "" + raise RuntimeError("ERROR: number of result lines=%d is different that expected %d" % (len(result), linesExpected)) with open(resultsFileName, "a") as myfile: myfile.write(branch + " " + commit + "\n") - myfile.writelines(result) + myfile.write('\n'.join(result) + '\n') myfile.close() if (last_cspeed == None): + log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) return "" commit, cspeed, dspeed = get_last_commit(resultsFileName) text = "" for i in range(0, min(len(cspeed), len(last_cspeed))): + print("%s: -%d cspeed=%6.2f clast=%6.2f cdiff=%1.4f dspeed=%6.2f dlast=%6.2f ddiff=%1.4f %s" % (branch, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], fileName)) if (cspeed[i]/last_cspeed[i] < lower_limit): text += "WARNING: File=%s level=%d cspeed=%s last=%s diff=%s\n" % (fileName, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i]) if (dspeed[i]/last_dspeed[i] < lower_limit): @@ -122,31 +124,37 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP return text -def send_simple_email(emails, email_topic, have_mutt, have_mail): - if have_mutt: - execute('mutt -s "' + email_header + ' ' + email_topic + '" ' + emails + ' Date: Wed, 22 Jun 2016 13:07:58 +0200 Subject: [PATCH 3/6] test-zstd-speed.py: improved log and e-mail formatting --- tests/test-zstd-speed.py | 169 +++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 87 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index c693b2188..f3fb32607 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -42,88 +42,6 @@ def does_command_exist(command): return True -def get_branches(): - execute('git fetch -p') - output = execute('git branch -rl') - for line in output: - if "HEAD" in line: - output.remove(line) # remove "origin/HEAD -> origin/dev" - return map(lambda l: l.strip(), output) - - -def notify(branch, commit, last_commit): - text_tmpl = string.Template('Changes since $last_commit:\r\n$commits') - branch = branch.split('/')[1] - fmt = '--format="%h: (%an) %s, %ar"' - if last_commit is None: - commits = execute('git log -n 10 %s %s' % (fmt, commit)) - else: - commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - text = text_tmpl.substitute({'last_commit': last_commit, 'commits': '\n'.join(commits)}) - print(str("commits for %s: %s" % (commit, text))) - - -def compile(branch, commit, dry_run): - local_branch = string.split(branch, '/')[1] - version = local_branch.rpartition('-')[2] - version = version + '_' + commit - execute('git checkout -- . && git checkout ' + branch) - if not dry_run: - execute('VERSION=' + version + '; make clean zstdprogram') - - -def get_last_commit(resultsFileName): - if not os.path.isfile(resultsFileName): - return None, None, None - commit = None - cspeed = [] - dspeed = [] - with open(resultsFileName,'r') as f: - for line in f: - words = line.split() - if len(words) == 2: # branch + commit - commit = words[1]; - cspeed = [] - dspeed = [] - if (len(words) == 8): - cspeed.append(float(words[3])) - dspeed.append(float(words[5])) - #if commit != None: - # print "commit=%s cspeed=%s dspeed=%s" % (commit, cspeed, dspeed) - return commit, cspeed, dspeed - - -def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFilePath, fileName, last_cspeed, last_dspeed, lower_limit, maxLoadAvg, message): - sleepTime = 30 - while os.getloadavg()[0] > maxLoadAvg: - log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], maxLoadAvg, sleepTime)) - time.sleep(sleepTime) - start_load = str(os.getloadavg()) - result = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath, print_output=True) - end_load = str(os.getloadavg()) - linesExpected = lastCLevel + 2; - if len(result) != linesExpected: - raise RuntimeError("ERROR: number of result lines=%d is different that expected %d" % (len(result), linesExpected)) - with open(resultsFileName, "a") as myfile: - myfile.write(branch + " " + commit + "\n") - myfile.write('\n'.join(result) + '\n') - myfile.close() - if (last_cspeed == None): - log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) - return "" - commit, cspeed, dspeed = get_last_commit(resultsFileName) - text = "" - for i in range(0, min(len(cspeed), len(last_cspeed))): - print("%s: -%d cspeed=%6.2f clast=%6.2f cdiff=%1.4f dspeed=%6.2f dlast=%6.2f ddiff=%1.4f %s" % (branch, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], fileName)) - if (cspeed[i]/last_cspeed[i] < lower_limit): - text += "WARNING: File=%s level=%d cspeed=%s last=%s diff=%s\n" % (fileName, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i]) - if (dspeed[i]/last_dspeed[i] < lower_limit): - text += "WARNING: File=%s level=%d dspeed=%s last=%s diff=%s\n" % (fileName, i+1, dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i]) - if text: - text = message + ("\nmaxLoadAvg=%s load average at start=%s end=%s\n" % (maxLoadAvg, start_load, end_load)) + text - return text - - def send_email(emails, topic, text, have_mutt, have_mail): logFileName = working_path + '/' + 'tmpEmailContent' with open(logFileName, "w") as myfile: @@ -141,7 +59,7 @@ def send_email_with_attachments(branch, commit, last_commit, emails, text, resul with open(logFileName, "w") as myfile: myfile.writelines(text) myfile.close() - email_topic = '%s:%s Warning for branch=%s commit=%s last_commit=%s speed<%s' % (email_header, pid, branch, commit, last_commit, lower_limit) + email_topic = '%s:%s Warning for %s:%s last_commit=%s speed<%s' % (email_header, pid, branch, commit, last_commit, lower_limit) if have_mutt: execute('mutt -s "' + email_topic + '" ' + emails + ' -a ' + results_files + ' < ' + logFileName) elif have_mail: @@ -150,6 +68,84 @@ def send_email_with_attachments(branch, commit, last_commit, emails, text, resul log("e-mail cannot be sent (mail or mutt not found)") +def git_get_branches(): + execute('git fetch -p') + output = execute('git branch -rl') + for line in output: + if "HEAD" in line: + output.remove(line) # remove "origin/HEAD -> origin/dev" + return map(lambda l: l.strip(), output) + + +def git_get_changes(commit, last_commit): + fmt = '--format="%h: (%an) %s, %ar"' + if last_commit is None: + commits = execute('git log -n 10 %s %s' % (fmt, commit)) + else: + commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) + return str('Changes since %s:' % (last_commit)) + '\n'.join(commits) + + +def compile(branch, commit, last_commit, dry_run): + local_branch = string.split(branch, '/')[1] + version = local_branch.rpartition('-')[2] + version = version + '_' + commit + execute('git checkout -- . && git checkout ' + branch) + print(git_get_changes(commit, last_commit)) + if not dry_run: + execute('VERSION=' + version + '; make clean zstdprogram') + + +def get_last_commit(resultsFileName): + if not os.path.isfile(resultsFileName): + return None, None, None + commit = None + cspeed = [] + dspeed = [] + with open(resultsFileName,'r') as f: + for line in f: + words = line.split() + if len(words) == 2: # branch + commit + commit = words[1]; + cspeed = [] + dspeed = [] + if (len(words) == 8): # results + cspeed.append(float(words[3])) + dspeed.append(float(words[5])) + return commit, cspeed, dspeed + + +def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFilePath, fileName, last_cspeed, last_dspeed, lower_limit, maxLoadAvg, message): + sleepTime = 30 + while os.getloadavg()[0] > maxLoadAvg: + log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], maxLoadAvg, sleepTime)) + time.sleep(sleepTime) + start_load = str(os.getloadavg()) + result = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath, print_output=True) + end_load = str(os.getloadavg()) + linesExpected = lastCLevel + 2; + if len(result) != linesExpected: + raise RuntimeError("ERROR: number of result lines=%d is different that expected %d\n%s" % (len(result), linesExpected, '\n'.join(result))) + with open(resultsFileName, "a") as myfile: + myfile.write(branch + " " + commit + "\n") + myfile.write('\n'.join(result) + '\n') + myfile.close() + if (last_cspeed == None): + log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) + return "" + commit, cspeed, dspeed = get_last_commit(resultsFileName) + text = "" + for i in range(0, min(len(cspeed), len(last_cspeed))): + print("%s:%s -%d cspeed=%6.2f clast=%6.2f cdiff=%1.4f dspeed=%6.2f dlast=%6.2f ddiff=%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], fileName)) + if (cspeed[i]/last_cspeed[i] < lower_limit): + text += "WARNING: -%d cspeed=%.2f clast=%.2f cdiff=%.4f %s\n" % (i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], fileName) + if (dspeed[i]/last_dspeed[i] < lower_limit): + text += "WARNING: -%d dspeed=%.2f dlast=%.2f ddiff=%.4f %s\n" % (i+1, dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], fileName) + if text: + text = message + ("\nmaxLoadAvg=%s load average at start=%s end=%s\n" % (maxLoadAvg, start_load, end_load)) + text + return text + + def check_branch(branch, args, testFilePaths, have_mutt, have_mail): commits = execute('git show -s --format=%h ' + branch)[0] for commit in [commits]: @@ -165,7 +161,7 @@ def check_branch(branch, args, testFilePaths, have_mutt, have_mail): log("skipping branch %s: head %s already processed" % (branch, commit)) else: log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) - compile(branch, commit, args.dry_run) + compile(branch, commit, last_commit, args.dry_run) logFileName = working_path + "/log_" + branch.replace("/", "_") text_to_send = [] @@ -185,10 +181,9 @@ def check_branch(branch, args, testFilePaths, have_mutt, have_mail): results_files += resultsFileName + " " if text_to_send: send_email_with_attachments(branch, commit, last_commit, args.emails, text_to_send, results_files, logFileName, args.lowerLimit, have_mutt, have_mail) - notify(branch, commit, last_commit) except Exception as e: stack = traceback.format_exc() - email_topic = '%s:%s ERROR in branch=%s commit=%s' % (email_header, pid, branch, commit) + email_topic = '%s:%s ERROR in %s:%s' % (email_header, pid, branch, commit) send_email(args.emails, email_topic, stack, have_mutt, have_mail) print(stack) @@ -260,7 +255,7 @@ if __name__ == '__main__': try: loadavg = os.getloadavg()[0] if (loadavg <= args.maxLoadAvg): - branches = get_branches() + branches = git_get_branches() for branch in branches: check_branch(branch, args, testFilePaths, have_mutt, have_mail) else: From c364ee786731a7a6309522b9e577d95262d76856 Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 22 Jun 2016 14:01:53 +0200 Subject: [PATCH 4/6] test-zstd-speed.py: sent e-mail after KeyboardInterrupt --- tests/test-zstd-speed.py | 59 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index f3fb32607..7e0234106 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -6,6 +6,8 @@ import string import time import traceback import subprocess +import signal + default_repo_url = 'https://github.com/Cyan4973/zstd.git' working_dir_name = 'speedTest' @@ -83,7 +85,7 @@ def git_get_changes(commit, last_commit): commits = execute('git log -n 10 %s %s' % (fmt, commit)) else: commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - return str('Changes since %s:' % (last_commit)) + '\n'.join(commits) + return str('Changes since %s:\n' % (last_commit)) + '\n'.join(commits) def compile(branch, commit, last_commit, dry_run): @@ -96,7 +98,7 @@ def compile(branch, commit, last_commit, dry_run): execute('VERSION=' + version + '; make clean zstdprogram') -def get_last_commit(resultsFileName): +def get_last_results(resultsFileName): if not os.path.isfile(resultsFileName): return None, None, None commit = None @@ -133,7 +135,7 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP if (last_cspeed == None): log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) return "" - commit, cspeed, dspeed = get_last_commit(resultsFileName) + commit, cspeed, dspeed = get_last_results(resultsFileName) text = "" for i in range(0, min(len(cspeed), len(last_cspeed))): print("%s:%s -%d cspeed=%6.2f clast=%6.2f cdiff=%1.4f dspeed=%6.2f dlast=%6.2f ddiff=%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], fileName)) @@ -150,41 +152,41 @@ def check_branch(branch, args, testFilePaths, have_mutt, have_mail): commits = execute('git show -s --format=%h ' + branch)[0] for commit in [commits]: try: + last_commit = None commitFileName = working_path + "/commit_" + branch.replace("/", "_") if os.path.isfile(commitFileName): last_commit = file(commitFileName, 'r').read() - else: - last_commit = None file(commitFileName, 'w').write(commit) if commit == last_commit: log("skipping branch %s: head %s already processed" % (branch, commit)) - else: - log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) - compile(branch, commit, last_commit, args.dry_run) + continue - logFileName = working_path + "/log_" + branch.replace("/", "_") - text_to_send = [] - results_files = "" - for filePath in testFilePaths: - fileName = filePath.rpartition('/')[2] - resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName - last_commit, cspeed, dspeed = get_last_commit(resultsFileName) + log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) + compile(branch, commit, last_commit, args.dry_run) - if not args.dry_run: + logFileName = working_path + "/log_" + branch.replace("/", "_") + text_to_send = [] + results_files = "" + for filePath in testFilePaths: + fileName = filePath.rpartition('/')[2] + resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName + last_commit, cspeed, dspeed = get_last_results(resultsFileName) + + if not args.dry_run: + text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) + if text: + log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) if text: - log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) - text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) - if text: - text_to_send.append(text) - results_files += resultsFileName + " " - if text_to_send: - send_email_with_attachments(branch, commit, last_commit, args.emails, text_to_send, results_files, logFileName, args.lowerLimit, have_mutt, have_mail) + text_to_send.append(text) + results_files += resultsFileName + " " + if text_to_send: + send_email_with_attachments(branch, commit, last_commit, args.emails, text_to_send, results_files, logFileName, args.lowerLimit, have_mutt, have_mail) except Exception as e: stack = traceback.format_exc() email_topic = '%s:%s ERROR in %s:%s' % (email_header, pid, branch, commit) - send_email(args.emails, email_topic, stack, have_mutt, have_mail) + send_email(args.emails, email_topic, stack, have_mutt, have_mail) print(stack) @@ -248,9 +250,9 @@ if __name__ == '__main__': log("ERROR: %s already exists, exiting" % pidfile) exit(1) - send_email(args.emails, email_header + ':%s test-zstd-speed.py has been started' % pid, '', have_mutt, have_mail) - + send_email(args.emails, email_header + ':%s test-zstd-speed.py has been started' % pid, '', have_mutt, have_mail) file(pidfile, 'w').write(pid) + while True: try: loadavg = os.getloadavg()[0] @@ -262,6 +264,7 @@ if __name__ == '__main__': log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg)) log("sleep for %s seconds" % args.sleepTime) time.sleep(args.sleepTime) - finally: + except KeyboardInterrupt: os.unlink(pidfile) - send_email(args.emails, email_header + ':%s test-zstd-speed.py has been stopped' % pid, '', have_mutt, have_mail) + send_email(args.emails, email_header + ':%s test-zstd-speed.py has been stopped' % pid, '', have_mutt, have_mail) + exit(0) From f2f59d758eec85458b53b7ddcf7341b42309ab56 Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 22 Jun 2016 15:42:26 +0200 Subject: [PATCH 5/6] test-zstd-speed.py: added ZSTD_GIT_COMMIT --- programs/bench.c | 6 +++++- tests/test-zstd-speed.py | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/programs/bench.c b/programs/bench.c index 04f4276ce..81164e429 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -42,6 +42,10 @@ /* ************************************* * Constants ***************************************/ +#ifndef ZSTD_GIT_COMMIT +# define ZSTD_GIT_COMMIT "" +#endif + #define NBLOOPS 3 #define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */ #define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */ @@ -359,7 +363,7 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, memset(&total, 0, sizeof(total)); if (g_displayLevel == 1 && !g_additionalParam) - DISPLAY("bench %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION_STRING, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10)); + DISPLAY("bench %s %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION_STRING, ZSTD_GIT_COMMIT, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10)); if (cLevelLast < cLevel) cLevelLast = cLevel; diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 7e0234106..075dd472b 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -79,13 +79,13 @@ def git_get_branches(): return map(lambda l: l.strip(), output) -def git_get_changes(commit, last_commit): +def git_get_changes(branch, commit, last_commit): fmt = '--format="%h: (%an) %s, %ar"' if last_commit is None: commits = execute('git log -n 10 %s %s' % (fmt, commit)) else: commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - return str('Changes since %s:\n' % (last_commit)) + '\n'.join(commits) + return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits) def compile(branch, commit, last_commit, dry_run): @@ -93,9 +93,9 @@ def compile(branch, commit, last_commit, dry_run): version = local_branch.rpartition('-')[2] version = version + '_' + commit execute('git checkout -- . && git checkout ' + branch) - print(git_get_changes(commit, last_commit)) + print(git_get_changes(branch, commit, last_commit)) if not dry_run: - execute('VERSION=' + version + '; make clean zstdprogram') + execute('make clean zstdprogram MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version, print_output=True) def get_last_results(resultsFileName): From d7d251ccb52be1b2027e236aea1e572ec882f2bf Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 22 Jun 2016 16:13:25 +0200 Subject: [PATCH 6/6] bench.c: added support for ZSTD_GIT_COMMIT --- programs/bench.c | 6 ++-- tests/test-zstd-speed.py | 72 ++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/programs/bench.c b/programs/bench.c index 81164e429..a8fc7408a 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -43,7 +43,9 @@ * Constants ***************************************/ #ifndef ZSTD_GIT_COMMIT -# define ZSTD_GIT_COMMIT "" +# define ZSTD_GIT_COMMIT_STRING "" +#else +# define ZSTD_GIT_COMMIT_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_GIT_COMMIT) #endif #define NBLOOPS 3 @@ -363,7 +365,7 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, memset(&total, 0, sizeof(total)); if (g_displayLevel == 1 && !g_additionalParam) - DISPLAY("bench %s %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION_STRING, ZSTD_GIT_COMMIT, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10)); + DISPLAY("bench %s %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION_STRING, ZSTD_GIT_COMMIT_STRING, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10)); if (cLevelLast < cLevel) cLevelLast = cLevel; diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 075dd472b..2382f231e 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -95,7 +95,7 @@ def compile(branch, commit, last_commit, dry_run): execute('git checkout -- . && git checkout ' + branch) print(git_get_changes(branch, commit, last_commit)) if not dry_run: - execute('make clean zstdprogram MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version, print_output=True) + execute('make clean zstdprogram MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) def get_last_results(resultsFileName): @@ -148,46 +148,44 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP return text -def check_branch(branch, args, testFilePaths, have_mutt, have_mail): - commits = execute('git show -s --format=%h ' + branch)[0] - for commit in [commits]: - try: - last_commit = None - commitFileName = working_path + "/commit_" + branch.replace("/", "_") - if os.path.isfile(commitFileName): - last_commit = file(commitFileName, 'r').read() - file(commitFileName, 'w').write(commit) +def check_commit(branch, commit, args, testFilePaths, have_mutt, have_mail): + try: + last_commit = None + commitFileName = working_path + "/commit_" + branch.replace("/", "_") + if os.path.isfile(commitFileName): + last_commit = file(commitFileName, 'r').read() + file(commitFileName, 'w').write(commit) - if commit == last_commit: - log("skipping branch %s: head %s already processed" % (branch, commit)) - continue + if commit == last_commit: + log("skipping branch %s: head %s already processed" % (branch, commit)) + return - log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) - compile(branch, commit, last_commit, args.dry_run) + log("build branch %s: head %s is different from prev %s" % (branch, commit, last_commit)) + compile(branch, commit, last_commit, args.dry_run) - logFileName = working_path + "/log_" + branch.replace("/", "_") - text_to_send = [] - results_files = "" - for filePath in testFilePaths: - fileName = filePath.rpartition('/')[2] - resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName - last_commit, cspeed, dspeed = get_last_results(resultsFileName) + logFileName = working_path + "/log_" + branch.replace("/", "_") + text_to_send = [] + results_files = "" + for filePath in testFilePaths: + fileName = filePath.rpartition('/')[2] + resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName + last_commit, cspeed, dspeed = get_last_results(resultsFileName) - if not args.dry_run: + if not args.dry_run: + text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) + if text: + log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) if text: - log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit)) - text = benchmark_and_compare(branch, commit, resultsFileName, args.lastCLevel, filePath, fileName, cspeed, dspeed, args.lowerLimit, args.maxLoadAvg, args.message) - if text: - text_to_send.append(text) - results_files += resultsFileName + " " - if text_to_send: - send_email_with_attachments(branch, commit, last_commit, args.emails, text_to_send, results_files, logFileName, args.lowerLimit, have_mutt, have_mail) - except Exception as e: - stack = traceback.format_exc() - email_topic = '%s:%s ERROR in %s:%s' % (email_header, pid, branch, commit) - send_email(args.emails, email_topic, stack, have_mutt, have_mail) - print(stack) + text_to_send.append(text) + results_files += resultsFileName + " " + if text_to_send: + send_email_with_attachments(branch, commit, last_commit, args.emails, text_to_send, results_files, logFileName, args.lowerLimit, have_mutt, have_mail) + except Exception as e: + stack = traceback.format_exc() + email_topic = '%s:%s ERROR in %s:%s' % (email_header, pid, branch, commit) + send_email(args.emails, email_topic, stack, have_mutt, have_mail) + print(stack) if __name__ == '__main__': @@ -259,7 +257,9 @@ if __name__ == '__main__': if (loadavg <= args.maxLoadAvg): branches = git_get_branches() for branch in branches: - check_branch(branch, args, testFilePaths, have_mutt, have_mail) + commits = execute('git show -s --format=%h ' + branch)[0] + for commit in [commits]: + check_commit(branch, commit, args, testFilePaths, have_mutt, have_mail) else: log("WARNING: main loadavg=%.2f is higher than %s" % (loadavg, args.maxLoadAvg)) log("sleep for %s seconds" % args.sleepTime)