diff --git a/programs/bench.c b/programs/bench.c index 04f4276ce..a8fc7408a 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -42,6 +42,12 @@ /* ************************************* * Constants ***************************************/ +#ifndef 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 #define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */ #define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */ @@ -359,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: 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_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 5cc07fb37..2382f231e 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -1,37 +1,38 @@ #! /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 +import signal + 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 + 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) - itout = iter(popen.stdout.readline, b"") - iterr = iter(popen.stderr.readline, b"") - stdout_lines = list(itout) + 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) - stderr_lines = list(iterr) - if print_output: - print ''.join(stderr_lines) - popen.communicate() + 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) - raise RuntimeError(''.join(stderr_lines)) - return stdout_lines + stderr_lines + print('\n'.join(stdout_lines)) + raise RuntimeError('\n'.join(stdout_lines)) + return stdout_lines execute.cwd = None @@ -43,39 +44,61 @@ def does_command_exist(command): return True -def fetch(): +def send_email(emails, topic, text, have_mutt, have_mail): + logFileName = working_path + '/' + 'tmpEmailContent' + with open(logFileName, "w") as myfile: + myfile.writelines(text) + myfile.close() + if have_mutt: + execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName) + elif have_mail: + execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName) + else: + log("e-mail cannot be sent (mail or mutt not found)") + + +def send_email_with_attachments(branch, commit, last_commit, emails, text, results_files, logFileName, lower_limit, have_mutt, have_mail): + with open(logFileName, "w") as myfile: + myfile.writelines(text) + myfile.close() + 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: + execute('mail -s "' + email_topic + '" ' + emails + ' < ' + logFileName) + else: + 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" - branches = map(lambda l: l.strip(), output) - return map(lambda b: (b, execute('git show -s --format=%h ' + b)[0].strip()), branches) + 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] +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)) - - text = text_tmpl.substitute({'last_commit': last_commit, 'commits': ''.join(commits)}) - print str("commits for %s: %s" % (commit, text)) + return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits) -def compile(branch, commit, dry_run): +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(branch, commit, last_commit)) if not dry_run: - execute('VERSION=' + version + '; make clean zstdprogram') + execute('make clean zstdprogram MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) -def get_last_commit(resultsFileName): +def get_last_results(resultsFileName): if not os.path.isfile(resultsFileName): return None, None, None commit = None @@ -84,15 +107,13 @@ def get_last_commit(resultsFileName): with open(resultsFileName,'r') as f: for line in f: words = line.split() - if len(words) == 2: # branch + commit + if len(words) == 2: # branch + commit commit = words[1]; cspeed = [] dspeed = [] - if (len(words) == 8): + if (len(words) == 8): # results 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 @@ -102,89 +123,69 @@ 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) + 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\n%s" % (len(result), linesExpected, '\n'.join(result))) 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) + 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)) 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]) + 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: File=%s level=%d dspeed=%s last=%s diff=%s\n" % (fileName, i+1, dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i]) + 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 send_simple_email(emails, email_topic, have_mutt, have_mail): - if have_mutt: - execute('mutt -s "' + email_header + ' ' + email_topic + '" ' + emails + '