Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/psutil/_ntuples.py: 54%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) 2009, Giampaolo Rodola". All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
5from collections import namedtuple as nt
7from ._common import AIX
8from ._common import BSD
9from ._common import FREEBSD
10from ._common import LINUX
11from ._common import MACOS
12from ._common import SUNOS
13from ._common import WINDOWS
15# ===================================================================
16# --- system functions
17# ===================================================================
19# psutil.swap_memory()
20sswap = nt("sswap", ("total", "used", "free", "percent", "sin", "sout"))
22# psutil.disk_usage()
23sdiskusage = nt("sdiskusage", ("total", "used", "free", "percent"))
25# psutil.disk_io_counters()
26sdiskio = nt(
27 "sdiskio",
28 (
29 "read_count",
30 "write_count",
31 "read_bytes",
32 "write_bytes",
33 "read_time",
34 "write_time",
35 ),
36)
38# psutil.disk_partitions()
39sdiskpart = nt("sdiskpart", ("device", "mountpoint", "fstype", "opts"))
41# psutil.net_io_counters()
42snetio = nt(
43 "snetio",
44 (
45 "bytes_sent",
46 "bytes_recv",
47 "packets_sent",
48 "packets_recv",
49 "errin",
50 "errout",
51 "dropin",
52 "dropout",
53 ),
54)
56# psutil.users()
57suser = nt("suser", ("name", "terminal", "host", "started", "pid"))
59# psutil.net_connections()
60sconn = nt(
61 "sconn", ("fd", "family", "type", "laddr", "raddr", "status", "pid")
62)
64# psutil.net_if_addrs()
65snicaddr = nt("snicaddr", ("family", "address", "netmask", "broadcast", "ptp"))
67# psutil.net_if_stats()
68snicstats = nt("snicstats", ("isup", "duplex", "speed", "mtu", "flags"))
70# psutil.cpu_stats()
71scpustats = nt(
72 "scpustats", ("ctx_switches", "interrupts", "soft_interrupts", "syscalls")
73)
75# psutil.cpu_freq()
76scpufreq = nt("scpufreq", ("current", "min", "max"))
78# psutil.sensors_temperatures()
79shwtemp = nt("shwtemp", ("label", "current", "high", "critical"))
81# psutil.sensors_battery()
82sbattery = nt("sbattery", ("percent", "secsleft", "power_plugged"))
84# psutil.sensors_fans()
85sfan = nt("sfan", ("label", "current"))
87# psutil.heap_info() (mallinfo2 Linux struct)
88if LINUX or WINDOWS or MACOS or BSD:
89 pheap = nt(
90 "pheap",
91 [
92 "heap_used", # uordblks, memory allocated via malloc()
93 "mmap_used", # hblkhd, memory allocated via mmap() (large blocks)
94 ],
95 )
96 if WINDOWS:
97 pheap = nt("pheap", pheap._fields + ("heap_count",))
99# ===================================================================
100# --- Process class
101# ===================================================================
103# psutil.Process.cpu_times()
104pcputimes = nt(
105 "pcputimes", ("user", "system", "children_user", "children_system")
106)
108# psutil.Process.open_files()
109popenfile = nt("popenfile", ("path", "fd"))
111# psutil.Process.threads()
112pthread = nt("pthread", ("id", "user_time", "system_time"))
114# psutil.Process.uids()
115puids = nt("puids", ("real", "effective", "saved"))
117# psutil.Process.gids()
118pgids = nt("pgids", ("real", "effective", "saved"))
120# psutil.Process.io_counters()
121pio = nt("pio", ("read_count", "write_count", "read_bytes", "write_bytes"))
123# psutil.Process.ionice()
124pionice = nt("pionice", ("ioclass", "value"))
126# psutil.Process.ctx_switches()
127pctxsw = nt("pctxsw", ("voluntary", "involuntary"))
129# psutil.Process.net_connections()
130pconn = nt("pconn", ("fd", "family", "type", "laddr", "raddr", "status"))
132# psutil.net_connections() and psutil.Process.net_connections()
133addr = nt("addr", ("ip", "port"))
135# ===================================================================
136# --- Linux
137# ===================================================================
139if LINUX:
141 # This gets set from _pslinux.py
142 scputimes = None
144 # psutil.virtual_memory()
145 svmem = nt(
146 "svmem",
147 (
148 "total",
149 "available",
150 "percent",
151 "used",
152 "free",
153 "active",
154 "inactive",
155 "buffers",
156 "cached",
157 "shared",
158 "slab",
159 ),
160 )
162 # psutil.disk_io_counters()
163 sdiskio = nt(
164 "sdiskio",
165 (
166 "read_count",
167 "write_count",
168 "read_bytes",
169 "write_bytes",
170 "read_time",
171 "write_time",
172 "read_merged_count",
173 "write_merged_count",
174 "busy_time",
175 ),
176 )
178 # psutil.Process().open_files()
179 popenfile = nt("popenfile", ("path", "fd", "position", "mode", "flags"))
181 # psutil.Process().memory_info()
182 pmem = nt("pmem", ("rss", "vms", "shared", "text", "lib", "data", "dirty"))
184 # psutil.Process().memory_full_info()
185 pfullmem = nt("pfullmem", pmem._fields + ("uss", "pss", "swap"))
187 # psutil.Process().memory_maps(grouped=True)
188 pmmap_grouped = nt(
189 "pmmap_grouped",
190 (
191 "path",
192 "rss",
193 "size",
194 "pss",
195 "shared_clean",
196 "shared_dirty",
197 "private_clean",
198 "private_dirty",
199 "referenced",
200 "anonymous",
201 "swap",
202 ),
203 )
205 # psutil.Process().memory_maps(grouped=False)
206 pmmap_ext = nt(
207 "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
208 )
210 # psutil.Process.io_counters()
211 pio = nt(
212 "pio",
213 (
214 "read_count",
215 "write_count",
216 "read_bytes",
217 "write_bytes",
218 "read_chars",
219 "write_chars",
220 ),
221 )
223 # psutil.Process.cpu_times()
224 pcputimes = nt(
225 "pcputimes",
226 ("user", "system", "children_user", "children_system", "iowait"),
227 )
229# ===================================================================
230# --- Windows
231# ===================================================================
233elif WINDOWS:
235 # psutil.cpu_times()
236 scputimes = nt("scputimes", ("user", "system", "idle", "interrupt", "dpc"))
238 # psutil.virtual_memory()
239 svmem = nt("svmem", ("total", "available", "percent", "used", "free"))
241 # psutil.Process.memory_info()
242 pmem = nt(
243 "pmem",
244 (
245 "rss",
246 "vms",
247 "num_page_faults",
248 "peak_wset",
249 "wset",
250 "peak_paged_pool",
251 "paged_pool",
252 "peak_nonpaged_pool",
253 "nonpaged_pool",
254 "pagefile",
255 "peak_pagefile",
256 "private",
257 ),
258 )
260 # psutil.Process.memory_full_info()
261 pfullmem = nt("pfullmem", pmem._fields + ("uss",))
263 # psutil.Process.memory_maps(grouped=True)
264 pmmap_grouped = nt("pmmap_grouped", ("path", "rss"))
266 # psutil.Process.memory_maps(grouped=False)
267 pmmap_ext = nt(
268 "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
269 )
271 # psutil.Process.io_counters()
272 pio = nt(
273 "pio",
274 (
275 "read_count",
276 "write_count",
277 "read_bytes",
278 "write_bytes",
279 "other_count",
280 "other_bytes",
281 ),
282 )
284# ===================================================================
285# --- macOS
286# ===================================================================
288elif MACOS:
290 # psutil.cpu_times()
291 scputimes = nt("scputimes", ("user", "nice", "system", "idle"))
293 # psutil.virtual_memory()
294 svmem = nt(
295 "svmem",
296 (
297 "total",
298 "available",
299 "percent",
300 "used",
301 "free",
302 "active",
303 "inactive",
304 "wired",
305 ),
306 )
308 # psutil.Process.memory_info()
309 pmem = nt("pmem", ("rss", "vms", "pfaults", "pageins"))
311 # psutil.Process.memory_full_info()
312 pfullmem = nt("pfullmem", pmem._fields + ("uss",))
314# ===================================================================
315# --- BSD
316# ===================================================================
318elif BSD:
320 # psutil.virtual_memory()
321 svmem = nt(
322 "svmem",
323 (
324 "total",
325 "available",
326 "percent",
327 "used",
328 "free",
329 "active",
330 "inactive",
331 "buffers",
332 "cached",
333 "shared",
334 "wired",
335 ),
336 )
338 # psutil.cpu_times()
339 scputimes = nt("scputimes", ("user", "nice", "system", "idle", "irq"))
341 # psutil.Process.memory_info()
342 pmem = nt("pmem", ("rss", "vms", "text", "data", "stack"))
344 # psutil.Process.memory_full_info()
345 pfullmem = pmem
347 # psutil.Process.cpu_times()
348 pcputimes = nt(
349 "pcputimes", ("user", "system", "children_user", "children_system")
350 )
352 # psutil.Process.memory_maps(grouped=True)
353 pmmap_grouped = nt(
354 "pmmap_grouped", "path rss, private, ref_count, shadow_count"
355 )
357 # psutil.Process.memory_maps(grouped=False)
358 pmmap_ext = nt(
359 "pmmap_ext", "addr, perms path rss, private, ref_count, shadow_count"
360 )
362 # psutil.disk_io_counters()
363 if FREEBSD:
364 sdiskio = nt(
365 "sdiskio",
366 (
367 "read_count",
368 "write_count",
369 "read_bytes",
370 "write_bytes",
371 "read_time",
372 "write_time",
373 "busy_time",
374 ),
375 )
376 else:
377 sdiskio = nt(
378 "sdiskio",
379 ("read_count", "write_count", "read_bytes", "write_bytes"),
380 )
382# ===================================================================
383# --- SunOS
384# ===================================================================
386elif SUNOS:
388 # psutil.cpu_times()
389 scputimes = nt("scputimes", ("user", "system", "idle", "iowait"))
391 # psutil.cpu_times(percpu=True)
392 pcputimes = nt(
393 "pcputimes", ("user", "system", "children_user", "children_system")
394 )
396 # psutil.virtual_memory()
397 svmem = nt("svmem", ("total", "available", "percent", "used", "free"))
399 # psutil.Process.memory_info()
400 pmem = nt("pmem", ("rss", "vms"))
402 # psutil.Process.memory_full_info()
403 pfullmem = pmem
405 # psutil.Process.memory_maps(grouped=True)
406 pmmap_grouped = nt("pmmap_grouped", ("path", "rss", "anonymous", "locked"))
408 # psutil.Process.memory_maps(grouped=False)
409 pmmap_ext = nt(
410 "pmmap_ext", "addr perms " + " ".join(pmmap_grouped._fields)
411 )
413# ===================================================================
414# --- AIX
415# ===================================================================
417elif AIX:
419 # psutil.Process.memory_info()
420 pmem = nt("pmem", ("rss", "vms"))
422 # psutil.Process.memory_full_info()
423 pfullmem = pmem
425 # psutil.Process.cpu_times()
426 scputimes = nt("scputimes", ("user", "system", "idle", "iowait"))
428 # psutil.virtual_memory()
429 svmem = nt("svmem", ("total", "available", "percent", "used", "free"))