field_defs = { 'PID': { 'desc': 'PID', 'dtype': str, }, 'PPID': { 'desc': 'Parent PID', 'dtype': str, }, 'UID': { 'desc': 'User ID', 'dtype': str, }, 'LXC': { 'desc': 'LXC ID', 'dtype': str, }, '%CUU': { 'desc': 'CPU Use', 'dtype': float, }, '%MEM': { 'desc': 'Memory Use', 'dtype': float, }, 'VSZ': { 'desc': 'Virtual Memory', 'dtype': int, 'mult': 1024, }, 'RSS': { 'desc': 'Resident Memory', 'dtype': int, 'mult': 1024, }, 'PSS': { 'desc': 'Proportional Shared Memory', 'dtype': int, 'mult': 1024, }, 'USS': { 'desc': 'Unique Memory', 'dtype': int, 'mult': 1024, }, 'SZ': { 'desc': 'Core Size', 'dtype': int, 'mult': 4096, }, 'SIZE': { 'desc': 'Approximate Memory', 'dtype': int, 'mult': 1024, }, 'THCNT': { 'desc': 'Thread Count', 'dtype': int, }, 'TIME': { 'desc': 'Execution Time', 'dtype': int, }, 'ELAPSED': { 'desc': 'Elapsed Time', 'dtype': int, }, 'STAT': { 'desc': 'Status', 'dtype': str, }, 'COMMAND': { 'desc': 'Command', 'dtype': str, } } def parseFile(fname): f = open(fname, 'r') data = f.read() f.close() data = data.split('\n') data = list(filter(bool, [line.split() for line in data])) header = data[0] procs = [] for line in data[1:]: proc = {} for i in range(len(header)): field = field_defs[header[i]] value = line[i] if i == len(header): value = ' '.join(line[i:]) value = field['dtype'](value) if 'mult' in field: value *= field['mult'] proc[header[i]] = value procs.append(proc) return procs