Created
December 17, 2018 13:51
-
-
Save aravindavk/40ce7b68f26587b4442851ca45942e2d to your computer and use it in GitHub Desktop.
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
import sys | |
from datetime import datetime | |
first_ts = None | |
FMT = "%Y-%m-%d %H:%M:%S" | |
class Result(object): | |
def __init__(self): | |
self.start_ts = None | |
self.total = 0 | |
self.pending = 0 | |
self.bound = 0 | |
self.max_rate_per_min = 0 | |
self.min_rate_per_min = 0 | |
self.avg_rate_per_min = 0 | |
self.duration = 0 | |
self._num_iterations = 0 | |
self._total_rate = 0 | |
self._rate = 0 | |
def isComplete(self): | |
if self.total > 0 and self.pending == 0 and self.total == self.bound: | |
return True | |
return False | |
def set_min_rate(self): | |
if self.max_rate_per_min < self._rate: | |
self.max_rate_per_min = self._rate | |
def set_max_rate(self): | |
if self.min_rate_per_min == 0 or self.min_rate_per_min > self._rate: | |
self.min_rate_per_min = self._rate | |
def set_avg_rate(self): | |
if self._rate > 0: | |
self._total_rate += rate | |
self._num_iterations += 1 | |
self.avg_rate_per_min = int(self._total_rate / self._num_iterations) | |
avg_time_data = {} | |
result = Result() | |
with open(sys.argv[1]) as f: | |
for line in f: | |
if line.startswith("Summary: "): | |
data = line.strip().replace("Summary: ", "").split("\t") | |
outdata = {} | |
for d in data: | |
k, v = d.split("=") | |
try: | |
outdata[k.lower()] = int(v) | |
except ValueError: | |
outdata[k.lower()] = v | |
result.total = outdata.get("total", 0) | |
result.pending = outdata.get("pending", 0) | |
result.bound = outdata.get("bound", 0) | |
rate = 0.0 | |
if result.start_ts is None and outdata.get("total", 0) > 0: | |
result.start_ts = datetime.strptime(outdata["ts"], FMT) | |
if result.start_ts is not None: | |
tdelta = datetime.strptime(outdata["ts"], FMT) - result.start_ts | |
result.duration = tdelta | |
if tdelta.total_seconds() > 0: | |
rate = int(outdata.get("bound", "0"))*60 / tdelta.total_seconds() | |
result._rate = int(rate) | |
result.set_min_rate() | |
result.set_max_rate() | |
result.set_avg_rate() | |
if result.isComplete(): | |
break | |
# Non summary line | |
else: | |
parts = line.split(",") | |
pvname = parts[1] | |
dte = parts[0] | |
status = parts[2] | |
if avg_time_data.get(pvname, None) is None: | |
avg_time_data[pvname] = [None, None] | |
# Update First date when a pv found as Pending | |
if status == "Pending" and avg_time_data[pvname][0] is None: | |
avg_time_data[pvname][0] = dte | |
# Update first bound time observed | |
if status == "Bound" and avg_time_data[pvname][1] is None: | |
avg_time_data[pvname][1] = dte | |
total_dur = 0 | |
for k, v in avg_time_data.items(): | |
dur = datetime.strptime(v[1], FMT) - datetime.strptime(v[0], FMT) | |
total_dur += dur.total_seconds() | |
print("PV: %s Time: %s" % (k, dur.total_seconds())) | |
print("Average Time to create a PV: %s seconds(%s minutes)" % (total_dur / result.bound, total_dur / (60*result.bound))) | |
print("Number of Claims : %s" % result.total) | |
print("Number of PVs bound : %s" % result.bound) | |
print("Number of PVs pending : %s" % result.pending) | |
print("Max PV create rate : %s pvs/min" % result.max_rate_per_min) | |
print("Min PV create rate : %s pvs/min" % result.min_rate_per_min) | |
print("Avg PV create rate : %s pvs/min" % result.avg_rate_per_min) | |
print("Duration : %s minutes (%s pvcs)" % (int(result.duration.total_seconds()/60), result.bound)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment