def get_cpu_sample(): [a, b, c, d] = subprocess.getoutput("cat /proc/stat | grep ^cpu\ | awk '{print $2, $3, $4, $6}'").split() cpu_time = int(a) + int(b) + int(c) + int(d) return (cpu_time, time.time())