forked from 5000user5000/vmcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_analysis.py
More file actions
33 lines (30 loc) · 1.27 KB
/
Copy pathtest_analysis.py
File metadata and controls
33 lines (30 loc) · 1.27 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
# 資料格式 ts,tx,rmb,wmb,system,threads,datasize,workload,batch
# 讀取 tx
import sys
def read_data(input_file,output_file):
tx_data = []
rmb_data = []
wmb_data = []
with open(input_file, 'r', encoding='utf-8') as file:
next(file) # 跳過第一行
for line in file:
columns = line.strip().split(',')
if len(columns) > 1: # 確保有第二個元素
# print(columns[1]) # 輸出第二個元素
tx_data.append(columns[1])
rmb_data.append(columns[2])
wmb_data.append(columns[3])
# 將字串轉換為浮點數
tx_data = list(map(float, tx_data))
rmb_data = list(map(float, rmb_data))
wmb_data = list(map(float, wmb_data))
# 將平均值資料以添加方式寫入檔案,(tx, rmb, wmb)
with open(output_file, 'a', encoding='utf-8') as file:
file.write(str(round(sum(tx_data) / len(tx_data), 2)) + ',' + str(round(sum(rmb_data) / len(rmb_data), 2)) + ',' + str(round(sum(wmb_data) / len(wmb_data), 2)) + '\n')
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Usage: python test.py input_file output_file")
else:
input_file = sys.argv[1]
output_file = sys.argv[2]
read_data(input_file,output_file)