ottertune/client/driver/userDefinedMetrics/user_defined_metrics.py

57 lines
1.7 KiB
Python
Raw Permalink Normal View History

2020-04-27 17:14:18 -07:00
import json
import sys
import copy
import argparse
import os
sys.path.append("../../../")
2020-04-27 21:21:04 -07:00
sys.path.append("../")
2020-04-27 17:14:18 -07:00
from server.website.website.types import VarType # pylint: disable=import-error,wrong-import-position,line-too-long # noqa: E402
2020-04-27 21:21:04 -07:00
from driver_config import OLTPBENCH_HOME # pylint: disable=import-error,wrong-import-position # noqa: E402
2020-04-27 17:14:18 -07:00
parser = argparse.ArgumentParser() # pylint: disable=invalid-name
parser.add_argument("result_dir")
args = parser.parse_args() # pylint: disable=invalid-name
USER_DEINFED_METRICS = {
2020-05-05 00:26:06 -07:00
"throughput": {
"unit": "transaction / second",
"short_unit": "txn/s",
"type": VarType.INTEGER
2020-04-27 17:14:18 -07:00
},
2020-05-05 00:26:06 -07:00
"latency_99": {
"unit": "microseconds",
"short_unit": "us",
"type": VarType.INTEGER
},
"latency_95": {
"unit": "microseconds",
"short_unit": "us",
"type": VarType.INTEGER
2020-04-27 17:14:18 -07:00
}
}
def get_udm():
2020-04-27 21:21:04 -07:00
summary_path = OLTPBENCH_HOME + '/results/outputfile.summary'
with open(summary_path, 'r') as f:
2020-04-27 17:14:18 -07:00
info = json.load(f)
metrics = copy.deepcopy(USER_DEINFED_METRICS)
2020-05-05 00:26:06 -07:00
metrics["throughput"]["value"] = info["Throughput (requests/second)"]
metrics["latency_99"]["value"] =\
2020-04-27 17:14:18 -07:00
info["Latency Distribution"]["99th Percentile Latency (microseconds)"]
2020-05-05 00:26:06 -07:00
metrics["latency_95"]["value"] =\
2020-04-27 17:14:18 -07:00
info["Latency Distribution"]["95th Percentile Latency (microseconds)"]
return metrics
def write_udm():
metrics = get_udm()
result_dir = args.result_dir
path = os.path.join(result_dir, 'user_defined_metrics.json')
with open(path, 'w') as f:
json.dump(metrics, f, indent=4)
if __name__ == "__main__":
write_udm()