Created
June 30, 2020 20:09
-
-
Save bibstha/810253670d6739ee89dee05118b34bec to your computer and use it in GitHub Desktop.
Convert a csv with one column (latency / other time metric)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# must do `pip install hdrhistogram` | |
# uses package https://github.com/HdrHistogram/HdrHistogram_py | |
# This file can be used to convert a csv with one column (latency / other time metric) | |
# into hgrm file format which can then be plotted with http://hdrhistogram.github.io/HdrHistogram/plotFiles.html | |
# | |
# Useful to download data from Splunk an generate Percentile distribution | |
from hdrh.histogram import HdrHistogram | |
import csv | |
import sys | |
def write_hgrm(): | |
if len(sys.argv) < 3: | |
print("Invalid input csv. Use: work.py /path/to/input.csv /path/to/output.hgrm") | |
return | |
input_csv = sys.argv[1] | |
output_path = sys.argv[2] | |
with open(input_csv) as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
values = [] | |
for row in csv_reader: | |
try: | |
# scale up by 10, if we have 0.Xms values | |
# this will be scaled down by 10 when writing output | |
val = float(row[0]) * 10 | |
# ignore values under 1 | |
if val < 1: | |
continue | |
values.append(int(val)) | |
except ValueError as verr: | |
continue | |
lowest = min(values) | |
highest = max(values) | |
precision = 2 | |
histogram = HdrHistogram(lowest, highest, precision) | |
for i in values: | |
histogram.record_value(i) | |
outfile = open(output_path, 'wb') | |
histogram.output_percentile_distribution(outfile, 10) | |
print(f"Output written to {output_path}") | |
outfile.close() | |
def main(): | |
write_hgrm() | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment