aboutsummaryrefslogtreecommitdiff
path: root/scripts/thr_hist.py
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-08-17 11:28:07 -0400
committerDeterminant <ted.sybil@gmail.com>2018-08-17 11:28:07 -0400
commit140ee49ccf0353cd29c04d0d6bd5d4da69e7d0cc (patch)
tree8b523f5d470beabea19c80d524b4fec964cea89a /scripts/thr_hist.py
parent91112940ed5f3f85c5fce6549b601b7569ab4b1a (diff)
add scripts; move scripts to a new directory
Diffstat (limited to 'scripts/thr_hist.py')
-rw-r--r--scripts/thr_hist.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/thr_hist.py b/scripts/thr_hist.py
new file mode 100644
index 0000000..6f6a43f
--- /dev/null
+++ b/scripts/thr_hist.py
@@ -0,0 +1,50 @@
+import sys
+import re
+import argparse
+from datetime import datetime, timedelta
+
+def str2datetime(s):
+ parts = s.split('.')
+ dt = datetime.strptime(parts[0], "%Y-%m-%d %H:%M:%S")
+ return dt.replace(microsecond=int(parts[1]))
+
+
+def plot_thr(fname):
+ import matplotlib.pyplot as plt
+ x = range(len(values))
+ y = values
+ plt.xlabel(r"time")
+ plt.ylabel(r"tx/sec")
+ plt.plot(x, y)
+ plt.show()
+ plt.savefig(fname)
+
+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)
+ args = parser.parse_args()
+ commit_pat = re.compile('([^[].*) \[hotstuff info\].*got <fin decision=1')
+ interval = args.interval
+ begin_time = None
+ next_begin_time = None
+ cnt = 0
+ timestamps = []
+ values = []
+ for line in sys.stdin:
+ m = commit_pat.match(line)
+ if m:
+ timestamps.append(str2datetime(m.group(1)))
+ timestamps.sort()
+ for timestamp in timestamps:
+ if begin_time and timestamp < next_begin_time:
+ cnt += 1
+ else:
+ if begin_time:
+ values.append(cnt)
+ begin_time = timestamp
+ next_begin_time = begin_time + timedelta(seconds=interval)
+ cnt = 1
+ values.append(cnt)
+ print(values)
+ plot_thr(args.output)