61 lines
1.2 KiB
Python
Executable File
61 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from time import sleep, time
|
|
|
|
t0 = time()
|
|
|
|
hog_list = []
|
|
|
|
duration = 60
|
|
|
|
sff_max = 0.55
|
|
sff_min = 0.45
|
|
|
|
mb = 1024 * 1024
|
|
path = '/dev/zero'
|
|
|
|
def sff():
|
|
"""
|
|
SwapFree fraction
|
|
"""
|
|
with open('/proc/meminfo') as f:
|
|
for i in f:
|
|
if i.startswith('SwapTotal'):
|
|
st = i.split(':')[1].strip(' kB\n')
|
|
if i.startswith('SwapFree'):
|
|
sf = i.split(':')[1].strip(' kB\n')
|
|
st = float(st) + 1
|
|
sf = float(sf)
|
|
return sf / st
|
|
|
|
|
|
def hog(hog_list):
|
|
"""
|
|
"""
|
|
with open(path, 'rb') as f:
|
|
raw = f.read(mb)
|
|
hog_list.append(raw)
|
|
|
|
return hog_list
|
|
|
|
|
|
while True:
|
|
|
|
while sff() > sff_min:
|
|
hog_list.reverse()
|
|
if time() - t0 > duration:
|
|
exit()
|
|
hog_list = hog(hog_list)
|
|
print('MiB:', len(hog_list), 'SwapFree:', sff(), 'time:', time() - t0)
|
|
|
|
while sff() < sff_max:
|
|
hog_list.reverse()
|
|
if time() - t0 > duration:
|
|
exit()
|
|
try:
|
|
hog_list.pop()
|
|
except IndexError:
|
|
break
|
|
print('MiB:', len(hog_list), 'SwapFree:', sff(), 'time:', time() - t0)
|
|
|