knative-report/benchmark/classic/data/process.py

70 lines
2.1 KiB
Python
Raw Permalink Normal View History

2019-10-14 21:25:37 +02:00
#!/usr/bin/env python3
import csv
import os
from pprint import pprint
2019-10-22 03:03:15 +02:00
# Returns array of csv files in current directory
2019-10-14 21:25:37 +02:00
def getFiles():
files = [f for f in os.listdir('.') if os.path.isfile(f)]
2019-10-22 03:03:15 +02:00
return[f for f in files if f.endswith('.csv')]
2019-10-14 21:25:37 +02:00
def processFile(fname):
2019-10-22 03:03:15 +02:00
with open(fname, 'r') as f:
lines = []
data = csv.reader(f)
fields = next(data)
responseCodes = {}
responsePerSec = {}
responseTimes = []
2019-10-14 21:25:37 +02:00
for row in data:
2019-10-22 03:03:15 +02:00
items = zip(fields, row)
item = {}
for(name, value) in items:
item[name] = value.strip()
sec = int(item['offset'].split('.')[0])
2019-10-14 21:25:37 +02:00
if sec not in responsePerSec:
2019-10-22 03:03:15 +02:00
responsePerSec[sec] = []
2019-10-14 21:25:37 +02:00
else:
responsePerSec[sec].append(item['response-time'])
2019-10-22 03:03:15 +02:00
code = item['status-code']
2019-10-14 21:25:37 +02:00
if code not in responseCodes:
2019-10-22 03:03:15 +02:00
responseCodes[code] = 1
2019-10-14 21:25:37 +02:00
else:
2019-10-22 03:03:15 +02:00
responseCodes[code] = responseCodes[code] + 1
2019-10-14 21:25:37 +02:00
responseTimes.append(item['response-time'])
2019-10-22 03:03:15 +02:00
if len(responseTimes) != 0:
maxResponse = max(responseTimes)
minResponse = min(responseTimes)
#print("Maximum response time was ", maxResponse)
#print("Minimum response time was ", minResponse)
2019-10-14 21:25:37 +02:00
else:
print("csv is empty")
2019-11-03 23:11:23 +01:00
# pprint(responseCodes)
2019-10-14 21:25:37 +02:00
for sec in responsePerSec:
2019-10-22 03:03:15 +02:00
if len(responsePerSec[sec]) != 0:
#print(sec, ":")
#print(" Maximum:", max(responsePerSec[sec]))
#print(" Minimum:", min(responsePerSec[sec]))
#print(" Num of responses:", len(responsePerSec[sec]))
print(len(responsePerSec[sec]))
2019-11-03 23:11:23 +01:00
# else:
2019-10-22 03:03:15 +02:00
#print(" empty")
def keychars(x):
return int(x.split('.')[1])
2019-10-14 21:25:37 +02:00
def processAllFiles():
2019-10-22 03:03:15 +02:00
files = sorted(getFiles(), key=keychars)
2019-10-14 21:25:37 +02:00
for f in files:
2019-10-22 03:03:15 +02:00
#print("Processing ", f)
2019-10-14 21:25:37 +02:00
processFile(f)
2019-10-22 03:03:15 +02:00
2019-10-14 21:25:37 +02:00
if __name__ == "__main__":
processAllFiles()