def get_mem_usage():
    with open('/proc/meminfo') as mem_info:
        mem_total = mem_info.readline()
        mem_free = mem_info.readline()
        mem_buff = mem_info.readline()
        # 部分操作系统内核会MemAvailable一行，所以Buffers应该再取下一行文本来提取读书。
        if not mem_buff.startswith('Buffers'):
            mem_buff = mem_info.readline()

        mem_cached  = mem_info.readline()

    mem_total = int(mem_total.split(':', 1)[1].split()[0])
    mem_free = int(mem_free.split(':', 1)[1].split()[0])
    mem_buff = int(mem_buff.split(':', 1)[1].split()[0])
    mem_cached = int(mem_cached.split(':', 1)[1].split()[0])

    mem_usage = mem_total - (mem_free + mem_buff + mem_cached)
    mem_usage = 1.0 * 100 * mem_usage / mem_total

    return ( mem_usage%'%.1f%%', '%dM'%(mem_total/1024) )
dataset/ETHPy150Open everydo/ztq/ztq_worker/ztq_worker/system_info/linux.py/get_mem_usage/swapped operands of `%`