aboutsummaryrefslogtreecommitdiff
path: root/scripts/thr_hist.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/thr_hist.py')
-rw-r--r--scripts/thr_hist.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/scripts/thr_hist.py b/scripts/thr_hist.py
index c5f2a72..6f385e5 100644
--- a/scripts/thr_hist.py
+++ b/scripts/thr_hist.py
@@ -1,8 +1,24 @@
import sys
import re
import argparse
+import numpy as np
from datetime import datetime, timedelta
+def remove_outliers(x, outlierConstant = 1.5):
+ a = np.array(x)
+ upper_quartile = np.percentile(a, 75)
+ lower_quartile = np.percentile(a, 25)
+ IQR = (upper_quartile - lower_quartile) * outlierConstant
+ quartileSet = (lower_quartile - IQR, upper_quartile + IQR)
+ resultList = []
+ removedList = []
+ for y in a.tolist():
+ if y >= quartileSet[0] and y <= quartileSet[1]:
+ resultList.append(y)
+ else:
+ removedList.append(y)
+ return (resultList, removedList)
+
def str2datetime(s):
parts = s.split('.')
dt = datetime.strptime(parts[0], "%Y-%m-%d %H:%M:%S")
@@ -23,20 +39,21 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--interval', type=float, default=1, required=False)
parser.add_argument('--output', type=str, default="hist.png", required=False)
+ parser.add_argument('--plot', action='store_true')
args = parser.parse_args()
- commit_pat = re.compile('([^[].*) \[hotstuff info\] ([0-9.]*) [0-9.]*$')
+ commit_pat = re.compile('([^[].*) \[hotstuff info\] ([0-9.]*)$')
interval = args.interval
begin_time = None
next_begin_time = None
cnt = 0
- lat = 0
+ lats = []
timestamps = []
values = []
for line in sys.stdin:
m = commit_pat.match(line)
if m:
timestamps.append(str2datetime(m.group(1)))
- lat += float(m.group(2))
+ lats.append(float(m.group(2)))
timestamps.sort()
for timestamp in timestamps:
if begin_time and timestamp < next_begin_time:
@@ -49,5 +66,8 @@ if __name__ == '__main__':
cnt = 1
values.append(cnt)
print(values)
- print("lat = {:.3f}ms".format(lat / len(timestamps) * 1e3))
- plot_thr(args.output)
+ print("lat = {:.3f}ms".format(sum(lats) / len(lats) * 1e3))
+ lats, _ = remove_outliers(lats)
+ print("lat = {:.3f}ms".format(sum(lats) / len(lats) * 1e3))
+ if args.plot:
+ plot_thr(args.output)