| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- # Copyright (c) 2009, Giampaolo Rodola". All rights reserved.
- # Use of this source code is governed by a BSD-style license that can be
- # found in the LICENSE file.
- from collections import namedtuple as nt
- from ._common import AIX
- from ._common import BSD
- from ._common import FREEBSD
- from ._common import LINUX
- from ._common import MACOS
- from ._common import SUNOS
- from ._common import WINDOWS
- # ===================================================================
- # --- system functions
- # ===================================================================
- # psutil.swap_memory()
- sswap = nt("sswap", ("total", "used", "free", "percent", "sin", "sout"))
- # psutil.disk_usage()
- sdiskusage = nt("sdiskusage", ("total", "used", "free", "percent"))
- # psutil.disk_io_counters()
- sdiskio = nt(
- "sdiskio",
- (
- "read_count",
- "write_count",
- "read_bytes",
- "write_bytes",
- "read_time",
- "write_time",
- ),
- )
- # psutil.disk_partitions()
- sdiskpart = nt("sdiskpart", ("device", "mountpoint", "fstype", "opts"))
- # psutil.net_io_counters()
- snetio = nt(
- "snetio",
- (
- "bytes_sent",
- "bytes_recv",
- "packets_sent",
- "packets_recv",
- "errin",
- "errout",
- "dropin",
- "dropout",
- ),
- )
- # psutil.users()
- suser = nt("suser", ("name", "terminal", "host", "started", "pid"))
- # psutil.net_connections()
- sconn = nt(
- "sconn", ("fd", "family", "type", "laddr", "raddr", "status", "pid")
- )
- # psutil.net_if_addrs()
- snicaddr = nt("snicaddr", ("family", "address", "netmask", "broadcast", "ptp"))
- # psutil.net_if_stats()
- snicstats = nt("snicstats", ("isup", "duplex", "speed", "mtu", "flags"))
- # psutil.cpu_stats()
- scpustats = nt(
- "scpustats", ("ctx_switches", "interrupts", "soft_interrupts", "syscalls")
- )
- # psutil.cpu_freq()
- scpufreq = nt("scpufreq", ("current", "min", "max"))
- # psutil.sensors_temperatures()
- shwtemp = nt("shwtemp", ("label", "current", "high", "critical"))
- # psutil.sensors_battery()
- sbattery = nt("sbattery", ("percent", "secsleft", "power_plugged"))
- # psutil.sensors_fans()
- sfan = nt("sfan", ("label", "current"))
- # psutil.heap_info() (mallinfo2 Linux struct)
- if LINUX or WINDOWS or MACOS or BSD:
- pheap = nt(
- "pheap",
- [
- "heap_used", # uordblks, memory allocated via malloc()
- "mmap_used", # hblkhd, memory allocated via mmap() (large blocks)
- ],
- )
- if WINDOWS:
- pheap = nt("pheap", pheap._fields + ("heap_count",))
- # ===================================================================
- # --- Process class
- # ===================================================================
- # psutil.Process.cpu_times()
- pcputimes = nt(
- "pcputimes", ("user", "system", "children_user", "children_system")
- )
- # psutil.Process.open_files()
- popenfile = nt("popenfile", ("path", "fd"))
- # psutil.Process.threads()
- pthread = nt("pthread", ("id", "user_time", "system_time"))
- # psutil.Process.uids()
- puids = nt("puids", ("real", "effective", "saved"))
- # psutil.Process.gids()
- pgids = nt("pgids", ("real", "effective", "saved"))
- # psutil.Process.io_counters()
- pio = nt("pio", ("read_count", "write_count", "read_bytes", "write_bytes"))
- # psutil.Process.ionice()
- pionice = nt("pionice", ("ioclass", "value"))
- # psutil.Process.ctx_switches()
- pctxsw = nt("pctxsw", ("voluntary", "involuntary"))
- # psutil.Process.net_connections()
- pconn = nt("pconn", ("fd", "family", "type", "laddr", "raddr", "status"))
- # psutil.net_connections() and psutil.Process.net_connections()
- addr = nt("addr", ("ip", "port"))
- # ===================================================================
- # --- Linux
- # ===================================================================
- if LINUX:
- # This gets set from _pslinux.py
- scputimes = None
- # psutil.virtual_memory()
- svmem = nt(
- "svmem",
- (
- "total",
- "available",
- "percent",
- "used",
- "free",
- "active",
- "inactive",
- "buffers",
- "cached",
- "shared",
- "slab",
- ),
- )
- # psutil.disk_io_counters()
- sdiskio = nt(
- "sdiskio",
- (
- "read_count",
- "write_count",
- "read_bytes",
- "write_bytes",
- "read_time",
- "write_time",
- "read_merged_count",
- "write_merged_count",
- "busy_time",
- ),
- )
- # psutil.Process().open_files()
- popenfile = nt("popenfile", ("path", "fd", "position", "mode", "flags"))
- # psutil.Process().memory_info()
- pmem = nt("pmem", ("rss", "vms", "shared", "text", "lib", "data", "dirty"))
- # psutil.Process().memory_full_info()
- pfullmem = nt("pfullmem", pmem._fields + ("uss", "pss", "swap"))
- # psutil.Process().memory_maps(grouped=True)
- pmmap_grouped = nt(
- "pmmap_grouped",
- (
- "path",
- "rss",
- "size",
- "pss",
- "shared_clean",
- "shared_dirty",
- "private_clean",
- "private_dirty",
- "referenced",
- "anonymous",
- "swap",
- ),
- )
- # psutil.Process().memory_maps(grouped=False)
- pmmap_ext = nt(
- "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
- )
- # psutil.Process.io_counters()
- pio = nt(
- "pio",
- (
- "read_count",
- "write_count",
- "read_bytes",
- "write_bytes",
- "read_chars",
- "write_chars",
- ),
- )
- # psutil.Process.cpu_times()
- pcputimes = nt(
- "pcputimes",
- ("user", "system", "children_user", "children_system", "iowait"),
- )
- # ===================================================================
- # --- Windows
- # ===================================================================
- elif WINDOWS:
- # psutil.cpu_times()
- scputimes = nt("scputimes", ("user", "system", "idle", "interrupt", "dpc"))
- # psutil.virtual_memory()
- svmem = nt("svmem", ("total", "available", "percent", "used", "free"))
- # psutil.Process.memory_info()
- pmem = nt(
- "pmem",
- (
- "rss",
- "vms",
- "num_page_faults",
- "peak_wset",
- "wset",
- "peak_paged_pool",
- "paged_pool",
- "peak_nonpaged_pool",
- "nonpaged_pool",
- "pagefile",
- "peak_pagefile",
- "private",
- ),
- )
- # psutil.Process.memory_full_info()
- pfullmem = nt("pfullmem", pmem._fields + ("uss",))
- # psutil.Process.memory_maps(grouped=True)
- pmmap_grouped = nt("pmmap_grouped", ("path", "rss"))
- # psutil.Process.memory_maps(grouped=False)
- pmmap_ext = nt(
- "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
- )
- # psutil.Process.io_counters()
- pio = nt(
- "pio",
- (
- "read_count",
- "write_count",
- "read_bytes",
- "write_bytes",
- "other_count",
- "other_bytes",
- ),
- )
- # ===================================================================
- # --- macOS
- # ===================================================================
- elif MACOS:
- # psutil.cpu_times()
- scputimes = nt("scputimes", ("user", "nice", "system", "idle"))
- # psutil.virtual_memory()
- svmem = nt(
- "svmem",
- (
- "total",
- "available",
- "percent",
- "used",
- "free",
- "active",
- "inactive",
- "wired",
- ),
- )
- # psutil.Process.memory_info()
- pmem = nt("pmem", ("rss", "vms", "pfaults", "pageins"))
- # psutil.Process.memory_full_info()
- pfullmem = nt("pfullmem", pmem._fields + ("uss",))
- # ===================================================================
- # --- BSD
- # ===================================================================
- elif BSD:
- # psutil.virtual_memory()
- svmem = nt(
- "svmem",
- (
- "total",
- "available",
- "percent",
- "used",
- "free",
- "active",
- "inactive",
- "buffers",
- "cached",
- "shared",
- "wired",
- ),
- )
- # psutil.cpu_times()
- scputimes = nt("scputimes", ("user", "nice", "system", "idle", "irq"))
- # psutil.Process.memory_info()
- pmem = nt("pmem", ("rss", "vms", "text", "data", "stack"))
- # psutil.Process.memory_full_info()
- pfullmem = pmem
- # psutil.Process.cpu_times()
- pcputimes = nt(
- "pcputimes", ("user", "system", "children_user", "children_system")
- )
- # psutil.Process.memory_maps(grouped=True)
- pmmap_grouped = nt(
- "pmmap_grouped", "path rss, private, ref_count, shadow_count"
- )
- # psutil.Process.memory_maps(grouped=False)
- pmmap_ext = nt(
- "pmmap_ext", "addr, perms path rss, private, ref_count, shadow_count"
- )
- # psutil.disk_io_counters()
- if FREEBSD:
- sdiskio = nt(
- "sdiskio",
- (
- "read_count",
- "write_count",
- "read_bytes",
- "write_bytes",
- "read_time",
- "write_time",
- "busy_time",
- ),
- )
- else:
- sdiskio = nt(
- "sdiskio",
- ("read_count", "write_count", "read_bytes", "write_bytes"),
- )
- # ===================================================================
- # --- SunOS
- # ===================================================================
- elif SUNOS:
- # psutil.cpu_times()
- scputimes = nt("scputimes", ("user", "system", "idle", "iowait"))
- # psutil.cpu_times(percpu=True)
- pcputimes = nt(
- "pcputimes", ("user", "system", "children_user", "children_system")
- )
- # psutil.virtual_memory()
- svmem = nt("svmem", ("total", "available", "percent", "used", "free"))
- # psutil.Process.memory_info()
- pmem = nt("pmem", ("rss", "vms"))
- # psutil.Process.memory_full_info()
- pfullmem = pmem
- # psutil.Process.memory_maps(grouped=True)
- pmmap_grouped = nt("pmmap_grouped", ("path", "rss", "anonymous", "locked"))
- # psutil.Process.memory_maps(grouped=False)
- pmmap_ext = nt(
- "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
- )
- # ===================================================================
- # --- AIX
- # ===================================================================
- elif AIX:
- # psutil.Process.memory_info()
- pmem = nt("pmem", ("rss", "vms"))
- # psutil.Process.memory_full_info()
- pfullmem = pmem
- # psutil.Process.cpu_times()
- scputimes = nt("scputimes", ("user", "system", "idle", "iowait"))
- # psutil.virtual_memory()
- svmem = nt("svmem", ("total", "available", "percent", "used", "free"))
|