Ejemplo n.º 1
0
Archivo: meter.py Proyecto: notkeo/rtop
def procs_snapshot_diff(snap_a, snap_b):
    pids = set(snap_a.keys()) & set(snap_b.keys())
    result = dict.fromkeys(pids)
    for pid in pids:
        a, b = snap_a[pid], snap_b[pid]
        used_ticks, wait_ticks = a.used_ticks - b.used_ticks, a.wait_ticks - b.wait_ticks
        wbytes, rbytes = a.wbytes - b.wbytes, a.rbytes - b.rbytes
        result[pid] = proc_snapshot(pid, b.name, b.uid, b.status, used_ticks, wait_ticks,
                                    b.threads, b.resident_mem, wbytes, rbytes)
    return result
Ejemplo n.º 2
0
Archivo: meter.py Proyecto: notkeo/rtop
def create_procs_snapshot(pids=None):
    if not pids:
        pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
    snapshots = dict.fromkeys(pids)
    for pid in snapshots:
        io = process_stat.read_io_stat(pid)
        cpu = process_stat.read_cpu_stat(pid)
        mem = process_stat.read_mem_stat(pid)
        uid = process_stat.read_uid(pid)
        snapshots[pid] = proc_snapshot(pid, cpu.name, uid, cpu.status, cpu.stime + cpu.utime, cpu.blkio_ticks,
                                       cpu.threads, mem.resident, io.write_bytes, io.read_bytes)
    return snapshots