[e9c5db2] | 1 | #!/usr/bin/python3
|
---|
| 2 | """
|
---|
| 3 | Python Script to convert output from mutilate to rmit like output
|
---|
| 4 | """
|
---|
| 5 | import argparse
|
---|
| 6 | import json
|
---|
| 7 | import locale
|
---|
| 8 | import os
|
---|
| 9 | import re
|
---|
| 10 | import sys
|
---|
| 11 |
|
---|
| 12 | locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' )
|
---|
| 13 |
|
---|
| 14 | parser = argparse.ArgumentParser(description='Python Script to convert output from mutilate to rmit like output')
|
---|
| 15 | parser.add_argument('--out', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
|
---|
| 16 | try:
|
---|
| 17 | options = parser.parse_args()
|
---|
| 18 | except:
|
---|
| 19 | print('ERROR: invalid arguments', file=sys.stderr)
|
---|
| 20 | parser.print_help(sys.stderr)
|
---|
| 21 | sys.exit(1)
|
---|
| 22 |
|
---|
| 23 | thisdir = os.getcwd()
|
---|
| 24 | dirs = os.listdir( thisdir )
|
---|
| 25 |
|
---|
| 26 | names = ['fibre', 'forall', 'vanilla']
|
---|
| 27 | names_re = '|'.join(names)
|
---|
| 28 |
|
---|
| 29 | def precentile(line):
|
---|
| 30 | fields = line.split()
|
---|
| 31 |
|
---|
| 32 | try:
|
---|
| 33 | lat50s = fields[6]
|
---|
| 34 | lat99s = fields[9]
|
---|
| 35 | except:
|
---|
| 36 | raise Warning("Warning: \"{}\"! insufficient fields".format(line))
|
---|
| 37 |
|
---|
| 38 | try:
|
---|
| 39 | lat50 = locale.atof(lat50s)
|
---|
| 40 | lat99 = locale.atof(lat99s)
|
---|
| 41 | except:
|
---|
| 42 | raise Warning("Warning: \"{}\" \"{}\"! can't convert to float".format(lat50s, lat99s))
|
---|
| 43 |
|
---|
| 44 | return lat50, lat99
|
---|
| 45 |
|
---|
| 46 | def want0(line):
|
---|
| 47 | line = line.strip()
|
---|
| 48 | if not line.endswith("= 0 (0.0%)"):
|
---|
| 49 | raise Warning("Warning: \"{}\"! should be 0".format(line))
|
---|
| 50 |
|
---|
| 51 | def extract(filename, out):
|
---|
| 52 | with open(filename, "r") as file:
|
---|
| 53 | lines = file.readlines()
|
---|
| 54 |
|
---|
| 55 | warns = []
|
---|
| 56 |
|
---|
| 57 | for line in lines:
|
---|
| 58 | try:
|
---|
| 59 | if line.startswith("read"):
|
---|
| 60 | rlat50, rlat99 = precentile(line)
|
---|
| 61 |
|
---|
| 62 | elif line.startswith("update"):
|
---|
| 63 | ulat50, ulat99 = precentile(line)
|
---|
| 64 |
|
---|
| 65 | elif line.startswith("Total QPS"):
|
---|
| 66 | match = re.search("Total QPS = ([0-9,\.]+)", line)
|
---|
| 67 | if match:
|
---|
| 68 | try:
|
---|
| 69 | qps = locale.atof(match[1])
|
---|
| 70 | except:
|
---|
| 71 | raise Warning("Warning: \"{}\" can't convert qps to float".format(match[1]))
|
---|
| 72 | else:
|
---|
| 73 | raise Warning("Warning: \"{}\" line unreadable".format(line))
|
---|
| 74 |
|
---|
| 75 | if line.startswith("Misses") or line.startswith("Skipped TXs"):
|
---|
| 76 | want0(line)
|
---|
| 77 | except Warning as w:
|
---|
| 78 | warns.append(str(w))
|
---|
| 79 |
|
---|
| 80 | try:
|
---|
| 81 | out['Actual QPS'] = qps
|
---|
| 82 | except:
|
---|
| 83 | warns.append("Warning: No total QPS")
|
---|
| 84 |
|
---|
| 85 | try:
|
---|
| 86 | out['Median Read Latency'] = rlat50
|
---|
| 87 | out['Tail Read Latency'] = rlat99
|
---|
| 88 | except:
|
---|
| 89 | warns.append("Warning: no read latencies")
|
---|
| 90 |
|
---|
| 91 | try:
|
---|
| 92 | out['Median Update Latency'] = ulat50
|
---|
| 93 | out['Tail Update Latency'] = ulat99
|
---|
| 94 | except:
|
---|
| 95 | warns.append("Warning: no update latencies")
|
---|
| 96 |
|
---|
| 97 | return warns
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | data = []
|
---|
| 101 |
|
---|
| 102 | for filename in dirs:
|
---|
| 103 | f = os.path.join( thisdir, filename )
|
---|
| 104 | # checking if it is a file
|
---|
| 105 | if os.path.isfile(f):
|
---|
| 106 | match = re.search("({})\.([0-9]+)\.([0-9]+)".format(names_re), filename)
|
---|
| 107 | try:
|
---|
| 108 | series = match[1]
|
---|
| 109 | rate = match[2]
|
---|
| 110 | rep = match[3]
|
---|
| 111 | except:
|
---|
| 112 | continue
|
---|
| 113 |
|
---|
| 114 | d = { 'Target QPS': int(rate) }
|
---|
| 115 |
|
---|
| 116 | w = extract( f, d )
|
---|
| 117 |
|
---|
| 118 | data.append([series, "memcached {}".format(series), d])
|
---|
| 119 | if w:
|
---|
| 120 | print("{} {} {}\n{}\n".format(series, rate, rep, '\n'.join(w)))
|
---|
| 121 |
|
---|
| 122 | options.out.write(json.dumps(data))
|
---|
| 123 | options.out.flush()
|
---|
| 124 | options.out.write("\n")
|
---|