Rizin
unix-like reverse engineering framework and cli tools
test-lz4-speed Namespace Reference

Functions

def hashfile (hasher, fname, blocksize=65536)
 
def log (text)
 
def execute (command, print_command=True, print_output=False, print_error=True, param_shell=True)
 
def does_command_exist (command)
 
def send_email (emails, topic, text, have_mutt, have_mail)
 
def send_email_with_attachments (branch, commit, last_commit, args, text, results_files, logFileName, have_mutt, have_mail)
 
def git_get_branches ()
 
def git_get_changes (branch, commit, last_commit)
 
def get_last_results (resultsFileName)
 
def benchmark_and_compare (branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, testFilePath, fileName, last_csize, last_cspeed, last_dspeed)
 
def update_config_file (branch, commit)
 
def double_check (branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName)
 
def test_commit (branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail)
 

Variables

string script_version = 'v1.7.2 (2016-11-08)'
 
string default_repo_url = 'https://github.com/lz4/lz4.git'
 
string working_dir_name = 'speedTest'
 
string working_path = os.getcwd() + '/' + working_dir_name
 
string clone_path = working_path + '/' + 'lz4'
 
string email_header = 'lz4_speedTest'
 
 pid = str(os.getpid())
 
bool verbose = False
 
string clang_version = "unknown"
 
string gcc_version = "unknown"
 
 args = None
 
 parser = argparse.ArgumentParser()
 
 help
 
 default
 
 type
 
 float
 
 int
 
 dest
 
 action
 
 testFileNames = args.testFileNames.split()
 
list testFilePaths = []
 
 fileName = os.path.expanduser(fileName)
 
def have_mutt = does_command_exist("mutt -h")
 
def have_mail = does_command_exist("mail -V")
 
 cwd
 
string pidfile = "./speedTest.pid"
 
string branch = ""
 
string commit = ""
 
bool first_time = True
 
 loadavg = os.getloadavg()[0]
 
def branches = git_get_branches()
 
def last_commit = update_config_file(branch, commit)
 
 stack = traceback.format_exc()
 
string email_topic = '[%s:%s] ERROR in %s:%s' % (email_header, pid, branch, commit)
 

Function Documentation

◆ benchmark_and_compare()

def test-lz4-speed.benchmark_and_compare (   branch,
  commit,
  last_commit,
  args,
  executableName,
  md5sum,
  compilerVersion,
  resultsFileName,
  testFilePath,
  fileName,
  last_csize,
  last_cspeed,
  last_dspeed 
)

Definition at line 147 of file test-lz4-speed.py.

148  testFilePath, fileName, last_csize, last_cspeed, last_dspeed):
149  sleepTime = 30
150  while os.getloadavg()[0] > args.maxLoadAvg:
151  log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds"
152  % (os.getloadavg()[0], args.maxLoadAvg, sleepTime))
153  time.sleep(sleepTime)
154  start_load = str(os.getloadavg())
155  result = execute('programs/%s -rqi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), print_output=True)
156  end_load = str(os.getloadavg())
157  linesExpected = args.lastCLevel + 1
158  if len(result) != linesExpected:
159  raise RuntimeError("ERROR: number of result lines=%d is different that expected %d\n%s" % (len(result), linesExpected, '\n'.join(result)))
160  with open(resultsFileName, "a") as myfile:
161  myfile.write('%s %s %s md5=%s\n' % (branch, commit, compilerVersion, md5sum))
162  myfile.write('\n'.join(result) + '\n')
163  myfile.close()
164  if (last_cspeed == None):
165  log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName))
166  return ""
167  commit, csize, cspeed, dspeed = get_last_results(resultsFileName)
168  text = ""
169  for i in range(0, min(len(cspeed), len(last_cspeed))):
170  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))
171  if (cspeed[i]/last_cspeed[i] < args.lowerLimit):
172  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)
173  if (dspeed[i]/last_dspeed[i] < args.lowerLimit):
174  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)
175  if (float(last_csize[i])/csize[i] < args.ratioLimit):
176  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)
177  if text:
178  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
179  return text
180 
181 
size_t len
Definition: 6502dis.c:15
def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True)
def get_last_results(resultsFileName)
#define min(a, b)
Definition: qsort.h:83
Definition: gzlog.c:289

References execute(), float, get_last_results(), len, min, capstone.range, and cmd_descs_generate.str.

Referenced by double_check().

◆ does_command_exist()

def test-lz4-speed.does_command_exist (   command)

Definition at line 68 of file test-lz4-speed.py.

68 def does_command_exist(command):
69  try:
70  execute(command, verbose, False, False)
71  except Exception:
72  return False
73  return True
74 
75 
def does_command_exist(command)

References execute().

◆ double_check()

def test-lz4-speed.double_check (   branch,
  commit,
  args,
  executableName,
  md5sum,
  compilerVersion,
  resultsFileName,
  filePath,
  fileName 
)

Definition at line 193 of file test-lz4-speed.py.

193 def double_check(branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName):
194  last_commit, csize, cspeed, dspeed = get_last_results(resultsFileName)
195  if not args.dry_run:
196  text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed)
197  if text:
198  log("WARNING: redoing tests for branch %s: commit %s" % (branch, commit))
199  text = benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName, csize, cspeed, dspeed)
200  return text
201 
202 
def benchmark_and_compare(branch, commit, last_commit, args, executableName, md5sum, compilerVersion, resultsFileName, testFilePath, fileName, last_csize, last_cspeed, last_dspeed)
def double_check(branch, commit, args, executableName, md5sum, compilerVersion, resultsFileName, filePath, fileName)

References benchmark_and_compare(), and get_last_results().

Referenced by test_commit().

◆ execute()

def test-lz4-speed.execute (   command,
  print_command = True,
  print_output = False,
  print_error = True,
  param_shell = True 
)

Definition at line 48 of file test-lz4-speed.py.

48 def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True):
49  if print_command:
50  log("> " + command)
51  popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=param_shell, cwd=execute.cwd)
52  stdout_lines, stderr_lines = popen.communicate(timeout=args.timeout)
53  stderr_lines = stderr_lines.decode("utf-8")
54  stdout_lines = stdout_lines.decode("utf-8")
55  if print_output:
56  if stdout_lines:
57  print(stdout_lines)
58  if stderr_lines:
59  print(stderr_lines)
60  if popen.returncode is not None and popen.returncode != 0:
61  if stderr_lines and not print_output and print_error:
62  print(stderr_lines)
63  raise RuntimeError(stdout_lines + stderr_lines)
64  return (stdout_lines + stderr_lines).splitlines()
65 execute.cwd = None
66 
67 

Referenced by benchmark_and_compare(), does_command_exist(), git_get_branches(), git_get_changes(), send_email(), send_email_with_attachments(), and test_commit().

◆ get_last_results()

def test-lz4-speed.get_last_results (   resultsFileName)

Definition at line 125 of file test-lz4-speed.py.

125 def get_last_results(resultsFileName):
126  if not os.path.isfile(resultsFileName):
127  return None, None, None, None
128  commit = None
129  csize = []
130  cspeed = []
131  dspeed = []
132  with open(resultsFileName, 'r') as f:
133  for line in f:
134  words = line.split()
135  if len(words) <= 4: # branch + commit + compilerVer + md5
136  commit = words[1]
137  csize = []
138  cspeed = []
139  dspeed = []
140  if (len(words) == 8) or (len(words) == 9): # results: "filename" or "XX files"
141  csize.append(int(words[1]))
142  cspeed.append(float(words[3]))
143  dspeed.append(float(words[5]))
144  return commit, csize, cspeed, dspeed
145 
146 

References float, int, and len.

Referenced by benchmark_and_compare(), and double_check().

◆ git_get_branches()

def test-lz4-speed.git_get_branches ( )

Definition at line 106 of file test-lz4-speed.py.

106 def git_get_branches():
107  execute('git fetch -p', verbose)
108  branches = execute('git branch -rl', verbose)
109  output = []
110  for line in branches:
111  if ("HEAD" not in line) and ("coverity_scan" not in line) and ("gh-pages" not in line):
112  output.append(line.strip())
113  return output
114 
115 

References execute().

◆ git_get_changes()

def test-lz4-speed.git_get_changes (   branch,
  commit,
  last_commit 
)

Definition at line 116 of file test-lz4-speed.py.

116 def git_get_changes(branch, commit, last_commit):
117  fmt = '--format="%h: (%an) %s, %ar"'
118  if last_commit is None:
119  commits = execute('git log -n 10 %s %s' % (fmt, commit))
120  else:
121  commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit))
122  return str('Changes in %s since %s:\n' % (branch, last_commit)) + '\n'.join(commits)
123 
124 
def git_get_changes(branch, commit, last_commit)

References execute(), and cmd_descs_generate.str.

◆ hashfile()

def test-lz4-speed.hashfile (   hasher,
  fname,
  blocksize = 65536 
)

Definition at line 37 of file test-lz4-speed.py.

37 def hashfile(hasher, fname, blocksize=65536):
38  with open(fname, "rb") as f:
39  for chunk in iter(lambda: f.read(blocksize), b""):
40  hasher.update(chunk)
41  return hasher.hexdigest()
42 
43 
def hashfile(hasher, fname, blocksize=65536)

Referenced by test_commit().

◆ log()

def test-lz4-speed.log (   text)

Definition at line 44 of file test-lz4-speed.py.

44 def log(text):
45  print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text)
46 
47 

◆ send_email()

def test-lz4-speed.send_email (   emails,
  topic,
  text,
  have_mutt,
  have_mail 
)

Definition at line 76 of file test-lz4-speed.py.

76 def send_email(emails, topic, text, have_mutt, have_mail):
77  logFileName = working_path + '/' + 'tmpEmailContent'
78  with open(logFileName, "w") as myfile:
79  myfile.writelines(text)
80  myfile.close()
81  if have_mutt:
82  execute('mutt -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose)
83  elif have_mail:
84  execute('mail -s "' + topic + '" ' + emails + ' < ' + logFileName, verbose)
85  else:
86  log("e-mail cannot be sent (mail or mutt not found)")
87 
88 
def send_email(emails, topic, text, have_mutt, have_mail)

References execute().

◆ send_email_with_attachments()

def test-lz4-speed.send_email_with_attachments (   branch,
  commit,
  last_commit,
  args,
  text,
  results_files,
  logFileName,
  have_mutt,
  have_mail 
)

Definition at line 89 of file test-lz4-speed.py.

90  logFileName, have_mutt, have_mail):
91  with open(logFileName, "w") as myfile:
92  myfile.writelines(text)
93  myfile.close()
94  email_topic = '[%s:%s] Warning for %s:%s last_commit=%s speed<%s ratio<%s' \
95  % (email_header, pid, branch, commit, last_commit,
96  args.lowerLimit, args.ratioLimit)
97  if have_mutt:
98  execute('mutt -s "' + email_topic + '" ' + args.emails + ' -a ' + results_files
99  + ' < ' + logFileName)
100  elif have_mail:
101  execute('mail -s "' + email_topic + '" ' + args.emails + ' < ' + logFileName)
102  else:
103  log("e-mail cannot be sent (mail or mutt not found)")
104 
105 

References execute().

Referenced by test_commit().

◆ test_commit()

def test-lz4-speed.test_commit (   branch,
  commit,
  last_commit,
  args,
  testFilePaths,
  have_mutt,
  have_mail 
)

Definition at line 203 of file test-lz4-speed.py.

203 def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail):
204  local_branch = branch.split('/')[1]
205  version = local_branch.rpartition('-')[2] + '_' + commit
206  if not args.dry_run:
207  execute('make -C programs clean lz4 CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -DLZ4_GIT_COMMIT=%s" && ' % version +
208  'mv programs/lz4 programs/lz4_clang && ' +
209  'make -C programs clean lz4 lz4c32 MOREFLAGS="-DLZ4_GIT_COMMIT=%s"' % version)
210  md5_lz4 = hashfile(hashlib.md5(), clone_path + '/programs/lz4')
211  md5_lz4c32 = hashfile(hashlib.md5(), clone_path + '/programs/lz4c32')
212  md5_lz4_clang = hashfile(hashlib.md5(), clone_path + '/programs/lz4_clang')
213  print("md5(lz4)=%s\nmd5(lz4c32)=%s\nmd5(lz4_clang)=%s" % (md5_lz4, md5_lz4c32, md5_lz4_clang))
214  print("gcc_version=%s clang_version=%s" % (gcc_version, clang_version))
215 
216  logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt"
217  text_to_send = []
218  results_files = ""
219 
220  for filePath in testFilePaths:
221  fileName = filePath.rpartition('/')[2]
222  resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
223  text = double_check(branch, commit, args, 'lz4', md5_lz4, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName)
224  if text:
225  text_to_send.append(text)
226  results_files += resultsFileName + " "
227  resultsFileName = working_path + "/results32_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
228  text = double_check(branch, commit, args, 'lz4c32', md5_lz4c32, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName)
229  if text:
230  text_to_send.append(text)
231  results_files += resultsFileName + " "
232  resultsFileName = working_path + "/resultsClang_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt"
233  text = double_check(branch, commit, args, 'lz4_clang', md5_lz4_clang, 'clang_version='+clang_version, resultsFileName, filePath, fileName)
234  if text:
235  text_to_send.append(text)
236  results_files += resultsFileName + " "
237  if text_to_send:
238  send_email_with_attachments(branch, commit, last_commit, args, text_to_send, results_files, logFileName, have_mutt, have_mail)
239 
240 
def send_email_with_attachments(branch, commit, last_commit, args, text, results_files, logFileName, have_mutt, have_mail)
def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, have_mail)

References double_check(), execute(), hashfile(), and send_email_with_attachments().

◆ update_config_file()

def test-lz4-speed.update_config_file (   branch,
  commit 
)

Definition at line 182 of file test-lz4-speed.py.

182 def update_config_file(branch, commit):
183  last_commit = None
184  commitFileName = working_path + "/commit_" + branch.replace("/", "_") + ".txt"
185  if os.path.isfile(commitFileName):
186  with open(commitFileName, 'r') as infile:
187  last_commit = infile.read()
188  with open(commitFileName, 'w') as outfile:
189  outfile.write(commit)
190  return last_commit
191 
192 
def update_config_file(branch, commit)

Variable Documentation

◆ action

◆ args

test-lz4-speed.args = None

Definition at line 34 of file test-lz4-speed.py.

◆ branch

◆ branches

def test-lz4-speed.branches = git_get_branches()

Definition at line 330 of file test-lz4-speed.py.

◆ clang_version

def test-lz4-speed.clang_version = "unknown"

Definition at line 32 of file test-lz4-speed.py.

◆ clone_path

string test-lz4-speed.clone_path = working_path + '/' + 'lz4'

Definition at line 28 of file test-lz4-speed.py.

◆ commit

def test-lz4-speed.commit = ""

Definition at line 318 of file test-lz4-speed.py.

◆ cwd

◆ default

test-lz4-speed.default

◆ default_repo_url

string test-lz4-speed.default_repo_url = 'https://github.com/lz4/lz4.git'

Definition at line 25 of file test-lz4-speed.py.

◆ dest

test-lz4-speed.dest

Definition at line 253 of file test-lz4-speed.py.

◆ email_header

string test-lz4-speed.email_header = 'lz4_speedTest'

Definition at line 29 of file test-lz4-speed.py.

◆ email_topic

string test-lz4-speed.email_topic = '[%s:%s] ERROR in %s:%s' % (email_header, pid, branch, commit)

Definition at line 345 of file test-lz4-speed.py.

◆ fileName

test-lz4-speed.fileName = os.path.expanduser(fileName)

◆ first_time

bool test-lz4-speed.first_time = True

Definition at line 319 of file test-lz4-speed.py.

◆ float

◆ gcc_version

def test-lz4-speed.gcc_version = "unknown"

Definition at line 33 of file test-lz4-speed.py.

◆ have_mail

def test-lz4-speed.have_mail = does_command_exist("mail -V")

Definition at line 271 of file test-lz4-speed.py.

◆ have_mutt

def test-lz4-speed.have_mutt = does_command_exist("mutt -h")

Definition at line 270 of file test-lz4-speed.py.

◆ help

test-lz4-speed.help ( void  )

Definition at line 243 of file test-lz4-speed.py.

◆ int

test-lz4-speed.int

Definition at line 250 of file test-lz4-speed.py.

Referenced by get_last_results().

◆ last_commit

def test-lz4-speed.last_commit = update_config_file(branch, commit)

Definition at line 333 of file test-lz4-speed.py.

◆ loadavg

test-lz4-speed.loadavg = os.getloadavg()[0]

Definition at line 328 of file test-lz4-speed.py.

Referenced by uv_loadavg().

◆ parser

test-lz4-speed.parser = argparse.ArgumentParser()

Definition at line 242 of file test-lz4-speed.py.

◆ pid

test-lz4-speed.pid = str(os.getpid())

Definition at line 30 of file test-lz4-speed.py.

◆ pidfile

string test-lz4-speed.pidfile = "./speedTest.pid"

Definition at line 308 of file test-lz4-speed.py.

◆ script_version

string test-lz4-speed.script_version = 'v1.7.2 (2016-11-08)'

Definition at line 24 of file test-lz4-speed.py.

◆ stack

test-lz4-speed.stack = traceback.format_exc()

Definition at line 344 of file test-lz4-speed.py.

◆ testFileNames

test-lz4-speed.testFileNames = args.testFileNames.split()

Definition at line 259 of file test-lz4-speed.py.

◆ testFilePaths

list test-lz4-speed.testFilePaths = []

Definition at line 260 of file test-lz4-speed.py.

◆ type

test-lz4-speed.type

Definition at line 247 of file test-lz4-speed.py.

◆ verbose

bool test-lz4-speed.verbose = False

Definition at line 31 of file test-lz4-speed.py.

◆ working_dir_name

string test-lz4-speed.working_dir_name = 'speedTest'

Definition at line 26 of file test-lz4-speed.py.

◆ working_path

string test-lz4-speed.working_path = os.getcwd() + '/' + working_dir_name

Definition at line 27 of file test-lz4-speed.py.