Skip to content

Instantly share code, notes, and snippets.

@bialesdaniel
Last active October 22, 2020 19:35
Show Gist options
  • Save bialesdaniel/2f510958390cf9463cd9e4a4565903df to your computer and use it in GitHub Desktop.
Save bialesdaniel/2f510958390cf9463cd9e4a4565903df to your computer and use it in GitHub Desktop.
#########################################################################
# From oltpbench/reporting/parsers/summary_parser.py
from oltpbench.reporting.utils import get_value_by_pattern
from oltpbench.reporting.constants import LATENCY_ATTRIBUTE_MAPPING
# NOTE: What we wanted to do was to reuse this function to parse the latency data
# from the res file as well.
def parse_latency_data(latency_dict):
"""
Parses the latency data from the format it is stored in the summary
file to the format we need for the API request.
Args:
latency_dict (dict): The "Latency Distribution" json object in the OLTPBench
summary file.
Returns:
latency (dict): The latency dict required to send to the performance storage
service.
"""
latency = {}
for key, pattern in LATENCY_ATTRIBUTE_MAPPING:
value = get_value_by_pattern(latency_dict, pattern, None)
latency[key] = float("{:.4}".format(value)) if value else value
return latency
#########################################################################
# From oltpbench/reporting/utils.py
def get_value_by_pattern(dict_obj, pattern, default):
"""
This is similar to .get() for a dict but it matches the
key based on a substring. This function is case insensitive.
"""
for key, value in dict_obj.items():
if pattern.lower() in key.lower():
return value
return default
#########################################################################
# From oltpbench/reporting/constants.py
# NOTE: The below array of key value pairs is the problem. It works fine
# for the summary file but the res file stores the values as lat_min,
# lat_max, lat_avg. Our solution was just to relax the search string to be
# min, max, av. If you wanted to make it more obvious you could say that
# our original search strings were 25TH_PERCENTILE or something like that.
# key = API json element name, value = oltpbench output file search string
LATENCY_ATTRIBUTE_MAPPING = [
('l_25','25'),('l_75','75'),('l_90','90'), ('l_95','95'), ('l_99','99'),
('avg','average'),('median','median'),('min','minimum'), ('max','maximum')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment