Created
December 19, 2017 08:13
-
-
Save rjl493456442/03d642f17b3f0fe2de8ad28c2a5f1ce2 to your computer and use it in GitHub Desktop.
go ethereum write delay analysis script
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import re | |
import numpy | |
write_delay_n = "n count" | |
write_delay_duration = "count" | |
n_statistic = {} | |
duration_statistic = {} | |
previous_n_cumulative = 0 | |
previous_duration_cumulative = 0 | |
keylist = ['rate1', 'rate5', 'rate15', 'ratemean'] | |
def analysis(filename): | |
f = open(filename, "r+") | |
lines = f.readlines() | |
for line in lines: | |
capture(matchline(line)) | |
calculate() | |
def matchline(line): | |
pattern = re.compile(r"datetime (.*) write delay (count|n count) ([0-9]*), rate1 (.*), rate5 (.*), rate15 (.*), ratemean (.*)") | |
matchline = pattern.match(line) | |
return matchline.groups() | |
def capture(match_res): | |
global previous_duration_cumulative | |
global previous_n_cumulative | |
if match_res[1] == write_delay_duration: | |
collection = duration_statistic | |
previous = previous_duration_cumulative | |
elif match_res[1] == write_delay_n: | |
collection = n_statistic | |
previous = previous_n_cumulative | |
else: | |
return | |
if int(match_res[2]) == 0 or int(float(match_res[3])) == 0: | |
# ignore empty statistic | |
return | |
if "cumulative" in collection: | |
collection['cumulative'].append(int(match_res[2]) - previous) | |
else: | |
collection['cumulative'] = [int(match_res[2])] | |
# update previous | |
if match_res[1] == write_delay_duration: | |
previous_duration_cumulative = int(match_res[2]) | |
elif match_res[1] == write_delay_n: | |
previous_n_cumulative = int(match_res[2]) | |
# update others | |
for i in range(len(keylist)): | |
if keylist[i] in collection: | |
collection[keylist[i]].append(float(match_res[3+i])) | |
else: | |
collection[keylist[i]] = [float(match_res[3+i])] | |
def calculate(): | |
global duration_statistic | |
global n_statistic | |
print numpy.percentile(numpy.array(duration_statistic['rate1']), 90) | |
print numpy.percentile(numpy.array(n_statistic['rate1']), 90) | |
if __name__ == "__main__": | |
analysis("writedelay") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment