forked from fuchuanpu/IPID_SideChannel_CCS20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkload.py
33 lines (28 loc) · 782 Bytes
/
workload.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
import time
import psutil
import json
import os
if __name__ == '__main__':
cpu_utl = []
mem_utl = []
print('start: ')
try:
while True:
cpu = psutil.cpu_percent(None)
mem = psutil.virtual_memory()
print(cpu)
print(mem.percent)
cpu_utl.append(cpu)
mem_utl.append(mem.percent)
time.sleep(1)
except KeyboardInterrupt:
print('End.')
path = './record'
if not os.path.exists(path):
os.makedirs(path)
filelist = os.listdir(path)
dic = {'cpu':cpu_utl, 'mem':mem_utl}
jstr = json.dumps(dic)
with open(path + '/data_' + str(len(filelist))+ '.json', 'w') as f:
f.write(jstr)
print('Finish.')