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