-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
182 lines (161 loc) · 5.82 KB
/
process.py
File metadata and controls
182 lines (161 loc) · 5.82 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# -*- coding: utf-8 -*-
import sys
import os
import numpy as np
vecfile = []
scafile = []
def formate_filename(filename: str, deep: int = 0) -> str:
tab = ''
d = 0
while d < deep:
tab += ' '
d += 1
return tab + os.path.basename(filename)
def list_dir(dirname: str, deep: int = 0) -> None:
if not os.path.exists(dirname):
print(dirname, 'is not existed')
sys.exit(1)
if os.path.isfile(dirname):
if "vec" in dirname:
vecfile.append(dirname)
if "sca" in dirname:
scafile.append(dirname)
# print dirname
# print formate_filename(dirname, deep)
if os.path.isdir(dirname):
# print formate_filename(dirname, deep) + ":"
# 列出目录的所有文件和子目录
filenames = os.listdir(dirname)
for filename in filenames:
list_dir(dirname + os.sep + filename, deep + 1)
def averagenum(num: int) -> int:
nsum = 0
for i in range(len(num)):
nsum += num[i]
return nsum / len(num)
def parse_vector(filename: str) -> None:
print('----------------------------------------------------------')
linenum = 0
print(filename)
latency = []
smallmessage = []
latencyl = []
largemessage = []
with open(filename) as f:
for line in f.readlines():
lines = []
lines = line.split('\t')
if "Latency" in line:
lines = line.split(' ')
smallmessage.append(lines[1])
if "Large" and "latency" in line:
lines = line.split(' ')
largemessage.append(lines[1])
lines = line.split('\t')
if len(lines) == 4 and lines[0] in smallmessage:
latency.append(float(lines[3]))
if len(lines) == 4 and lines[0] in largemessage:
latencyl.append(float(lines[3]))
linenum = linenum + 1
# latency.sort()
if len(latency) > 0:
print('number of SMALL messages: ' + str(len(latency)))
print('number of LARGE messages: ' + str(len(latencyl)))
'''
if len(latency) % 2 == 0:
print 'average of latency: ' + str((latency[len(latency)/2]+latency[len(latency)/2-1])/2.0)
else:
print 'average of latency: ' + str(latency[len(latency)/2])
'''
if len(latency) > 0:
print('average latency of SMALL messages: ' + str(averagenum(latency)))
print('average latency of LARGE messages: ' + str(averagenum(latencyl)))
# print 'max latency of SMALL messages: ' + str(max(latency))
# print 'min latency of SMALL messages: ' + str(min(latency))
if len(latency) > 0:
print(np.percentile(latency, 99.9)) # 95%分位数
print(np.percentile(latencyl, 99.9))
def parse_vector2(filename: str) -> None:
print('----------------------------------------------------------')
linenum = 0
print(filename)
flag = 0
latencysum = 0
latency = []
largemessage = []
with open(filename) as f:
for line in f.readlines():
lines = []
lines = line.split('\t')
if "Large" in line:
lines = line.split(' ')
largemessage.append(lines[1])
lines = line.split('\t')
if len(lines) == 4 and lines[0] in largemessage:
latency.append(float(lines[3]))
linenum = linenum + 1
# latency.sort()
print('number of LARGE messages: ' + str(len(latency)))
print('average latency of LARGE message: ' + str(averagenum(latency)))
print('max latency: ' + str(max(latency)))
print('min latency: ' + str(min(latency)))
print(np.percentile(latency, 99.9))
def parse_scala(filename: str) -> None:
print('----------------------------------------------------------')
print(filename)
linenum = 0
throughput = []
utilization = []
fraction = []
with open(filename) as f:
for line in f.readlines():
lines = []
lines = line.split(' ')
# print lines
# throughput data
if "throughput" in line and "scalar" in line:
throughput.append(float(lines[len(lines)-1]))
# utilization data
if "utilization" in line and "scalar" in line:
utilization.append(float(lines[len(lines)-1]))
if "fraction" in line and "scalar" in line:
fraction.append(float(lines[len(lines)-1]))
linenum = linenum + 1
throughput.sort()
print('number of senders: ' + str(len(throughput)))
'''
if len(throughput) % 2 == 0:
print 'average of throughput: ' + str((throughput[len(throughput)/2]+throughput[len(throughput)/2-1])/2.0)
else:
print 'average of throughput: ' + str(throughput[len(throughput)/2])
'''
print('average of throughput: ' + str(averagenum(throughput)))
print('max throughput: ' + str(max(throughput)))
print('min throughput: ' + str(min(throughput)))
utilization.sort()
print('number of receivers: ' + str(len(utilization)))
'''
if len(utilization) % 2 == 0:
print 'average of utilization: ' + str((utilization[len(utilization)/2]+utilization[len(utilization)/2-1])/2.0)
else:
print 'average of utilization: ' + str(utilization[len(utilization)/2])
'''
print('average of utilization: ' + str(averagenum(utilization)))
print('max utilization: ' + str(max(utilization)))
print('min utilization: ' + str(min(utilization)))
if len(fraction) > 0:
print('average of cnp fraction: ' + str(averagenum(fraction)))
print('max cnp fraction: ' + str(max(fraction)))
print('min cnp fraction: ' + str(min(fraction)))
if len(sys.argv) < 2:
print('you should input the dirname')
sys.exit(1)
del sys.argv[0]
for dirname in sys.argv:
list_dir(dirname)
print
# parse vec file
for v in vecfile:
parse_vector(v)
for s in scafile:
parse_scala(s)