示例#1
0
 def iotop_output_write(self):
     count = 0
     limit = self._arg_limit
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('write'), reverse=True):
         if not self.filter_process(tid):
             continue
         info_fmt = "{:>10} {:<25} {:>9} file {:>9} net {:>9} unknown "
         values.append((info_fmt.format(
                        common.convert_size(tid.write, padding_after=True),
                        "%s (%d)" % (tid.comm, tid.pid),
                        common.convert_size(tid.disk_write,
                                            padding_after=True),
                        common.convert_size(tid.net_write,
                                            padding_after=True),
                        common.convert_size(tid.unk_write,
                                            padding_after=True)),
                        tid.write))
         count = count + 1
         if limit > 0 and count >= limit:
             break
     for line in graph.graph('Per-process I/O Write', values,
                             with_value=False):
         print(line)
示例#2
0
 def iotop_output_print_file_write(self, files):
     # Compute files read
     count = 0
     limit = self._arg_limit
     graph = Pyasciigraph()
     values = []
     sorted_f = sorted(files.items(),
                       key=lambda files: files[1]['write'],
                       reverse=True)
     for f in sorted_f:
         if f[1]["write"] == 0:
             continue
         info_fmt = "{:>10}".format(
             common.convert_size(f[1]["write"], padding_after=True))
         values.append(("%s %s %s" %
                        (info_fmt, f[1]["name"], str(f[1]["other"])[1:-1]),
                        f[1]["write"]))
         count = count + 1
         if limit > 0 and count >= limit:
             break
     for line in graph.graph('Files Write',
                             values,
                             sort=2,
                             with_value=False):
         print(line)
示例#3
0
 def iotop_output_net_sent_bytes(self):
     graph = Pyasciigraph()
     values = []
     for iface in sorted(self.state.ifaces.values(),
                         key=operator.attrgetter('send_bytes'),
                         reverse=True):
         values.append(("%s %s" % (common.convert_size(iface.send_bytes),
                                   iface.name),
                       iface.send_bytes))
     for line in graph.graph('Network sent_bytes', values,
                             with_value=False):
         print(line)
示例#4
0
 def iotop_output_disk_read(self):
     count = 0
     limit = self._arg_limit
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('block_read'),
                       reverse=True):
         if not self.filter_process(tid):
             continue
         if tid.block_read == 0:
             continue
         info_fmt = "{:>10} {:<22}"
         values.append((info_fmt.format(
             common.convert_size(tid.block_read, padding_after=True),
             "%s (pid=%d)" % (tid.comm, tid.pid)), tid.block_read))
         count = count + 1
         if limit > 0 and count >= limit:
             break
     for line in graph.graph('Block I/O Read', values, with_value=False):
         print(line)
示例#5
0
    def iolatency_syscalls_list_output(self, title, rq_list,
                                       sortkey, reverse):
        limit = self._arg_limit
        count = 0
        outrange_legend = False
        if len(rq_list) == 0:
            return
        print(title)
        if self._arg_extra:
            extra_fmt = "{:<48}"
            extra_title = "{:<8} {:<8} {:<8} {:<8} {:<8} {:<8} ".format(
                "Dirtied", "Alloc", "Free", "Written", "Kswap", "Cleared")
        else:
            extra_fmt = "{:<0}"
            extra_title = ""
        title_fmt = "{:<19} {:<20} {:<16} {:<23} {:<5} {:<24} {:<8} " + \
            extra_fmt + "{:<14}"
        fmt = "{:<40} {:<16} {:>16} {:>11}  {:<24} {:<8} " + \
            extra_fmt + "{:<14}"
        print(title_fmt.format("Begin", "End", "Name", "Duration (usec)",
                               "Size", "Proc", "PID", extra_title, "Filename"))
        for rq in sorted(rq_list,
                         key=operator.attrgetter(sortkey), reverse=reverse):
            # only limit the output if in the "top" view
            if reverse and count > limit:
                break
            if rq.size is None:
                size = "N/A"
            else:
                size = common.convert_size(rq.size)
            if self._arg_extra:
                extra = "{:<8} {:<8} {:<8} {:<8} {:<8} {:<8} ".format(
                    rq.dirty, rq.page_alloc, rq.page_free, rq.page_written,
                    rq.woke_kswapd, rq.page_cleared)
            else:
                extra = ""
            name = rq.name.replace("syscall_entry_", "").replace("sys_", "")
            if rq.fd is None:
                filename = "None"
                fd = "None"
            else:
                filename = rq.fd.filename
                fd = rq.fd.fd
            end = common.ns_to_hour_nsec(rq.end, self._arg_multi_day,
                                         self._arg_gmt)

            outrange = " "
            duration = rq.duration
            if self._arg_begin and rq.begin < self._arg_begin:
                outrange = "*"
                outrange_legend = True
            if self._arg_end and rq.end > self._arg_end:
                outrange = "*"
                outrange_legend = True

            print(fmt.format("[" + common.ns_to_hour_nsec(
                rq.begin, self._arg_multi_day, self._arg_gmt) + "," +
                end + "]" + outrange,
                name,
                "%0.03f" % (duration/1000) + outrange,
                size, rq.proc.comm,
                rq.proc.pid, extra,
                "%s (fd=%s)" % (filename, fd)))
            count += 1
        if outrange_legend:
            print("*: Syscalls started and/or completed outside of the "
                  "range specified")