Reduce CPU usage up to 25%
Optimize reading /proc/meminfo
This commit is contained in:
parent
045b3922a3
commit
747cff404e
@ -1339,18 +1339,11 @@ def find_psi_metrics_value(psi_path, psi_metrics):
|
||||
def check_mem_and_swap():
|
||||
"""
|
||||
"""
|
||||
with open('/proc/meminfo') as f:
|
||||
for n, line in enumerate(f):
|
||||
if n == 2:
|
||||
mem_available = int(line.split(':')[1][:-4])
|
||||
continue
|
||||
if n is swap_total_index:
|
||||
swap_total = int(line.split(':')[1][:-4])
|
||||
continue
|
||||
if n is swap_free_index:
|
||||
swap_free = int(line.split(':')[1][:-4])
|
||||
break
|
||||
return mem_available, swap_total, swap_free
|
||||
with open('/proc/meminfo', 'rb') as f:
|
||||
m_list = f.read().decode().split(' kB\n')
|
||||
return (int(m_list[2].split(':')[1]),
|
||||
int(m_list[swap_total_index].split(':')[1]),
|
||||
int(m_list[swap_free_index].split(':')[1]))
|
||||
|
||||
|
||||
def check_zram():
|
||||
|
Loading…
Reference in New Issue
Block a user