'Get extended stats, only for top processes (see issue #403).
- cpu_affinity (Linux, Windows, FreeBSD)
- ionice (Linux and Windows > Vista)
- memory_full_info (Linux)
- num_ctx_switches (not available on Illumos/Solaris)
- num_fds (Unix-like)
- num_handles (Windows)
- num_threads (not available on *BSD)
- memory_maps (only swap, Linux)
https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
- connections (TCP and UDP)'

def __get_extended_stats(self, proc, procstat):

    procstat['extended_stats'] = True
    for stat in ['cpu_affinity', 'ionice', 'memory_full_info', 'num_ctx_switches', 'num_fds', 'num_handles', 'num_threads']:
        try:
            procstat.update(proc.as_dict(attrs=[stat]))
        except psutil.NoSuchProcess:
            pass
        except (ValueError, AttributeError):
            procstat[stat] = None
    if LINUX:
        try:
            procstat['memory_swap'] = sum([v.swap for v in proc.memory_maps()])
        except psutil.NoSuchProcess:
            pass
        except (psutil.AccessDenied, TypeError, NotImplementedError):
            procstat['memory_swap'] = None
    try:
        procstat['tcp'] = len(proc.connections(kind='tcp'))
        procstat['udp'] = len(proc.connections(kind='udp'))
    except psutil.AccessDenied:
        procstat['tcp'] = None
        procstat['udp'] = None
    return procstat
