def io_counters(self): try: ret = cext.proc_io_counters(self.pid) except OSError as err: if err.errno in ACCESS_DENIED_SET: ret = cext.proc_io_counters_2(self.pid) else: raise return _common.pio(*ret)
def io_counters(self): fname = "/proc/%s/io" % self.pid with open(fname, 'rb') as f: rcount = wcount = rbytes = wbytes = None for line in f: if rcount is None and line.startswith(b"syscr"): rcount = int(line.split()[1]) elif wcount is None and line.startswith(b"syscw"): wcount = int(line.split()[1]) elif rbytes is None and line.startswith(b"read_bytes"): rbytes = int(line.split()[1]) elif wbytes is None and line.startswith(b"write_bytes"): wbytes = int(line.split()[1]) for x in (rcount, wcount, rbytes, wbytes): if x is None: raise NotImplementedError( "couldn't read all necessary info from %r" % fname) return _common.pio(rcount, wcount, rbytes, wbytes)
def io_counters(self): fname = "/proc/%s/io" % self.pid f = open(fname, 'rb') SYSCR, SYSCW = b("syscr"), b("syscw") READ_BYTES, WRITE_BYTES = b("read_bytes"), b("write_bytes") try: rcount = wcount = rbytes = wbytes = None for line in f: if rcount is None and line.startswith(SYSCR): rcount = int(line.split()[1]) elif wcount is None and line.startswith(SYSCW): wcount = int(line.split()[1]) elif rbytes is None and line.startswith(READ_BYTES): rbytes = int(line.split()[1]) elif wbytes is None and line.startswith(WRITE_BYTES): wbytes = int(line.split()[1]) for x in (rcount, wcount, rbytes, wbytes): if x is None: raise NotImplementedError( "couldn't read all necessary info from %r" % fname) return _common.pio(rcount, wcount, rbytes, wbytes) finally: f.close()
def io_counters(self): rc, wc, rb, wb = cext.proc_io_counters(self.pid) return _common.pio(rc, wc, rb, wb)