Esempio n. 1
0
    def output(self):
        transferred = {}

        for tid in self.state.tids.keys():
            transferred[tid] = {'ipv4': {}, 'ipv6': {}}

            transferred[tid]['ipv4'] = {'up': 0, 'down': 0}
            transferred[tid]['ipv6'] = {'up': 0, 'down': 0}

            for fd in self.state.tids[tid].fds.values():
                if fd.fdtype is FDType.net:
                    if fd.family == socket.AF_INET:
                        transferred[tid]['ipv4']['up'] += fd.net_write
                        transferred[tid]['ipv4']['down'] += fd.net_read
                    elif fd.family == socket.AF_INET6:
                        transferred[tid]['ipv6']['up'] += fd.net_write
                        transferred[tid]['ipv6']['down'] += fd.net_read

        print('Processes by Network I/O')
        print('#' * 80)

        for tid in sorted(transferred, key=lambda tid:
                          self.get_total_transfer(transferred[tid]),
                          reverse=True)[:self.number]:

            total = self.get_total_transfer(transferred[tid])

            if total != 0:
                print(NetTop.TOTAL_FORMAT.format(self.state.tids[tid].comm,
                                                 '(' + str(tid) + ')',
                                                 convert_size(total)))
Esempio n. 2
0
    def output(self):
        transferred = {}

        for tid in self.state.tids.keys():
            transferred[tid] = {'ipv4': {}, 'ipv6': {}}

            transferred[tid]['ipv4'] = {'up': 0, 'down': 0}
            transferred[tid]['ipv6'] = {'up': 0, 'down': 0}

            for fd in self.state.tids[tid].fds.values():
                if fd.fdtype is FDType.net:
                    if fd.family == socket.AF_INET:
                        transferred[tid]['ipv4']['up'] += fd.net_write
                        transferred[tid]['ipv4']['down'] += fd.net_read
                    elif fd.family == socket.AF_INET6:
                        transferred[tid]['ipv6']['up'] += fd.net_write
                        transferred[tid]['ipv6']['down'] += fd.net_read

        print('Processes by Network I/O')
        print('#' * 80)

        for tid in sorted(
                transferred,
                key=lambda tid: self.get_total_transfer(transferred[tid]),
                reverse=True)[:self.number]:

            total = self.get_total_transfer(transferred[tid])

            if total != 0:
                print(
                    NetTop.TOTAL_FORMAT.format(self.state.tids[tid].comm,
                                               '(' + str(tid) + ')',
                                               convert_size(total)))
Esempio n. 3
0
 def iotop_output_print_file_write(self, args, files):
     # Compute files read
     count = 0
     limit = args.top
     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(
             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)
Esempio n. 4
0
 def iotop_output_net_sent_bytes(self, args):
     graph = Pyasciigraph()
     values = []
     for iface in sorted(self.state.ifaces.values(),
                         key=operator.attrgetter('send_bytes'),
                         reverse=True):
         values.append(("%s %s" % (convert_size(iface.send_bytes),
                                   iface.name),
                       iface.send_bytes))
     for line in graph.graph('Network sent_bytes', values,
                             with_value=False):
         print(line)
Esempio n. 5
0
 def iotop_output_net_sent_bytes(self, args):
     graph = Pyasciigraph()
     values = []
     for iface in sorted(self.state.ifaces.values(),
                         key=operator.attrgetter('send_bytes'),
                         reverse=True):
         values.append(
             ("%s %s" % (convert_size(iface.send_bytes), iface.name),
              iface.send_bytes))
     for line in graph.graph('Network sent_bytes', values,
                             with_value=False):
         print(line)
 def text_per_tid_report(self, total_ns, proc_list, limit=0, syscalls=0,
                         fds=0, mem=0):
     print("### Per-TID Usage ###")
     count = 0
     for tid in sorted(self.tids.values(),
                       key=operator.attrgetter('cpu_ns'), reverse=True):
         if len(proc_list) > 0 and tid.comm not in proc_list:
             continue
         print("%s (%d) : %0.02f%%, read %s, write %s"
               % (tid.comm, tid.tid, ((tid.cpu_ns * 100) / total_ns),
                  convert_size(tid.read), convert_size(tid.write)), end="")
         if tid.migrate_count > 0:
             print(""" (%d migration(s))""" % tid.migrate_count)
         else:
             print("")
         count = count + 1
         if fds:
             if tid.tid == tid.pid:
                 if len(tid.fds.keys()) > 0:
                     print("- Still opened files :")
                 for fd in tid.fds.values():
                     if fd.parent != -1 and fd.parent != tid.tid:
                         inherit = " (inherited by %s (%d))" % \
                             (self.tids[fd.parent].comm, fd.parent)
                     else:
                         inherit = ""
                     print("   - %s (%d), read = %s, write = %s, "
                           "open = %d, close = %d%s" %
                           (fd.filename, fd.fd, convert_size(fd.read),
                            convert_size(fd.write), fd.open,
                            fd.close, inherit))
                 if len(tid.closed_fds.keys()) > 0:
                     print("- Closed files :")
                 for fd in tid.closed_fds.values():
                     if fd.parent != -1 and fd.parent != tid.tid:
                         inherit = " (inherited by %s (%d))" % \
                             (self.tids[fd.parent].comm, fd.parent)
                     else:
                         inherit = ""
                     print("   - %s (%d), read = %s, write = %s, "
                           "open = %d, close = %d%s" %
                           (fd.filename, fd.fd, convert_size(fd.read),
                            convert_size(fd.write), fd.open,
                            fd.close, inherit))
         if syscalls:
             if len(tid.syscalls.keys()) > 0:
                 print("- Syscalls")
             for syscall in sorted(tid.syscalls.values(),
                                   key=operator.attrgetter('count'),
                                   reverse=True):
                 if syscall.count == 0:
                     continue
                 print(" - %s : %d" % (syscall.name, syscall.count))
         if mem:
             print("- Memory")
             print(" - Allocated %d pages" % tid.allocated_pages)
             print(" - Freed %d pages" % tid.freed_pages)
         if limit > 0 and count >= limit:
             break
Esempio n. 7
0
 def iotop_output_write(self, args):
     count = 0
     limit = args.top
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('write'), reverse=True):
         if len(args.proc_list) > 0 and tid.comm not in args.proc_list:
             continue
         info_fmt = "{:>10} {:<25} {:>9} file {:>9} net {:>9} unknown "
         values.append((info_fmt.format(
                        convert_size(tid.write, padding_after=True),
                        "%s (%d)" % (tid.comm, tid.tid),
                        convert_size(tid.disk_write, padding_after=True),
                        convert_size(tid.net_write, padding_after=True),
                        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)
Esempio n. 8
0
 def iotop_output_write(self, args):
     count = 0
     limit = args.top
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('write'),
                       reverse=True):
         if len(args.proc_list) > 0 and tid.comm not in args.proc_list:
             continue
         info_fmt = "{:>10} {:<25} {:>9} file {:>9} net {:>9} unknown "
         values.append((info_fmt.format(
             convert_size(tid.write, padding_after=True),
             "%s (%d)" % (tid.comm, tid.tid),
             convert_size(tid.disk_write, padding_after=True),
             convert_size(tid.net_write, padding_after=True),
             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)
Esempio n. 9
0
 def iotop_output_disk_read(self, args):
     count = 0
     limit = args.top
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('block_read'),
                       reverse=True):
         if tid.block_read == 0:
             continue
         if len(args.proc_list) > 0 and tid.comm not in args.proc_list:
             continue
         info_fmt = "{:>10} {:<22}"
         values.append((info_fmt.format(
             convert_size(tid.block_read, padding_after=True),
             "%s (tid=%d)" % (tid.comm, tid.tid)), 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)
Esempio n. 10
0
 def iotop_output_disk_read(self, args):
     count = 0
     limit = args.top
     graph = Pyasciigraph()
     values = []
     for tid in sorted(self.state.tids.values(),
                       key=operator.attrgetter('block_read'), reverse=True):
         if tid.block_read == 0:
             continue
         if len(args.proc_list) > 0 and tid.comm not in args.proc_list:
             continue
         info_fmt = "{:>10} {:<22}"
         values.append((info_fmt.format(convert_size(tid.block_read,
                                        padding_after=True),
                                        "%s (tid=%d)" % (tid.comm,
                                                         tid.tid)),
                        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)
Esempio n. 11
0
 def iotop_output_print_file_read(self, args, files):
     count = 0
     limit = args.top
     graph = Pyasciigraph()
     values = []
     sorted_f = sorted(files.items(), key=lambda files: files[1]['read'],
                       reverse=True)
     for f in sorted_f:
         if f[1]["read"] == 0:
             continue
         info_fmt = "{:>10}".format(convert_size(f[1]["read"],
                                    padding_after=True))
         values.append(("%s %s %s" % (info_fmt,
                                      f[1]["name"],
                                      str(f[1]["other"])[1:-1]),
                        f[1]["read"]))
         count = count + 1
         if limit > 0 and count >= limit:
             break
     for line in graph.graph('Files Read', values, sort=2,
                             with_value=False):
         print(line)
Esempio n. 12
0
 def text_per_tid_report(self,
                         total_ns,
                         proc_list,
                         limit=0,
                         syscalls=0,
                         fds=0,
                         mem=0):
     print("### Per-TID Usage ###")
     count = 0
     for tid in sorted(self.tids.values(),
                       key=operator.attrgetter('cpu_ns'),
                       reverse=True):
         if len(proc_list) > 0 and tid.comm not in proc_list:
             continue
         print("%s (%d) : %0.02f%%, read %s, write %s" %
               (tid.comm, tid.tid, ((tid.cpu_ns * 100) / total_ns),
                convert_size(tid.read), convert_size(tid.write)),
               end="")
         if tid.migrate_count > 0:
             print(""" (%d migration(s))""" % tid.migrate_count)
         else:
             print("")
         count = count + 1
         if fds:
             if tid.tid == tid.pid:
                 if len(tid.fds.keys()) > 0:
                     print("- Still opened files :")
                 for fd in tid.fds.values():
                     if fd.parent != -1 and fd.parent != tid.tid:
                         inherit = " (inherited by %s (%d))" % \
                             (self.tids[fd.parent].comm, fd.parent)
                     else:
                         inherit = ""
                     print("   - %s (%d), read = %s, write = %s, "
                           "open = %d, close = %d%s" %
                           (fd.filename, fd.fd, convert_size(
                               fd.read), convert_size(
                                   fd.write), fd.open, fd.close, inherit))
                 if len(tid.closed_fds.keys()) > 0:
                     print("- Closed files :")
                 for fd in tid.closed_fds.values():
                     if fd.parent != -1 and fd.parent != tid.tid:
                         inherit = " (inherited by %s (%d))" % \
                             (self.tids[fd.parent].comm, fd.parent)
                     else:
                         inherit = ""
                     print("   - %s (%d), read = %s, write = %s, "
                           "open = %d, close = %d%s" %
                           (fd.filename, fd.fd, convert_size(
                               fd.read), convert_size(
                                   fd.write), fd.open, fd.close, inherit))
         if syscalls:
             if len(tid.syscalls.keys()) > 0:
                 print("- Syscalls")
             for syscall in sorted(tid.syscalls.values(),
                                   key=operator.attrgetter('count'),
                                   reverse=True):
                 if syscall.count == 0:
                     continue
                 print(" - %s : %d" % (syscall.name, syscall.count))
         if mem:
             print("- Memory")
             print(" - Allocated %d pages" % tid.allocated_pages)
             print(" - Freed %d pages" % tid.freed_pages)
         if limit > 0 and count >= limit:
             break