-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data.py
79 lines (63 loc) · 2.64 KB
/
generate_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import marshal
import numpy as np
import pickle
from six import iteritems
LOW_RPS_FOLDER = "/var/lib/werkzeug_floder/uwsgi_10"
LOW_RPS_DATA = "werkzeug_low_rps.pickle"
MEDIUM_RPS_FOLDER = "/var/lib/werkzeug_floder/uwsgi_60"
MEDIUM_RPS_DATA = 'werkzeug_medium_rps.pickle'
HIGH_RPS_FOLDER = "/var/lib/werkzeug_floder/uwsgi_111"
HIGH_RPS_DATA = 'werkzeug_high_rps.pickle'
class Pstat:
def __init__(self, outp_dir):
self.outp_dir = outp_dir
self.func_dict = {}
def fill_fulldict(self, stats):
for func, (cc, nc, tt, ct, callers) in iteritems(stats):
if not func in self.func_dict:
self.func_dict[func] = {}
self.func_dict[func]["cumtime_values"] = []
self.func_dict[func]["call_values"] = []
self.func_dict[func]["percall_values"] = []
self.func_dict[func]["percall_values"].append(float(ct)/float(cc))
self.func_dict[func]["cumtime_values"].append(ct)
self.func_dict[func]["call_values"].append(cc)
def read_stat(self, fname):
with open("%s/%s" % (self.outp_dir, fname), "rb") as f:
data = marshal.load(f)
return data
def load_profiler_data(self):
flist = os.listdir(self.outp_dir)
if not self.func_dict:
for file_ in flist:
if os.path.exists("%s/%s" % (self.outp_dir, file_)):
marshal_data = self.read_stat(file_)
self.fill_fulldict(marshal_data)
def count_avg(self):
avg_dict = {}
for fpath in self.func_dict:
cumtime_list = self.func_dict[fpath]["cumtime_values"]
percall_list = self.func_dict[fpath]["percall_values"]
cc_list = self.func_dict[fpath]["call_values"]
avg_dict[fpath] = { "avg_cumtime": np.average(cumtime_list),
"avg_percall": np.average(percall_list),
"number_of_calls": sum(cc_list)
}
return avg_dict
if __name__ == "__main__":
first_test = Pstat(LOW_RPS_FOLDER)
first_test.load_profiler_data()
low_data = first_test.count_avg()
with open(LOW_RPS_DATA, 'wb') as handle:
pickle.dump(low_data, handle)
second_test = Pstat(MEDIUM_RPS_FOLDER)
second_test.load_profiler_data()
medium_data = second_test.count_avg()
with open(MEDIUM_RPS_DATA, 'wb') as handle:
pickle.dump(medium_data, handle)
third_test = Pstat(HIGH_RPS_FOLDER)
third_test.load_profiler_data()
high_data = third_test.count_avg()
with open(HIGH_RPS_DATA, 'wb') as handle:
pickle.dump(high_data, handle)