Skip to content

Commit da4c756

Browse files
committed
Intermediate changes
commit_hash:202dcb59cc75c6a8ee553d57ceb11687cdf21151
1 parent b4b9662 commit da4c756

File tree

35 files changed

+1213
-512
lines changed

35 files changed

+1213
-512
lines changed

contrib/python/psutil/py3/.dist-info/METADATA

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: psutil
3-
Version: 7.1.3
3+
Version: 7.2.0
44
Summary: Cross-platform lib for process and system monitoring.
55
Home-page: https://github.com/giampaolo/psutil
66
Author: Giampaolo Rodola
@@ -55,7 +55,6 @@ License-File: LICENSE
5555
Provides-Extra: dev
5656
Requires-Dist: pytest ; extra == 'dev'
5757
Requires-Dist: pytest-instafail ; extra == 'dev'
58-
Requires-Dist: pytest-subtests ; extra == 'dev'
5958
Requires-Dist: pytest-xdist ; extra == 'dev'
6059
Requires-Dist: setuptools ; extra == 'dev'
6160
Requires-Dist: abi3audit ; extra == 'dev'
@@ -78,20 +77,11 @@ Requires-Dist: validate-pyproject[all] ; extra == 'dev'
7877
Requires-Dist: virtualenv ; extra == 'dev'
7978
Requires-Dist: vulture ; extra == 'dev'
8079
Requires-Dist: wheel ; extra == 'dev'
81-
Requires-Dist: colorama ; (os_name == "nt") and extra == 'dev'
82-
Requires-Dist: pyreadline ; (os_name == "nt") and extra == 'dev'
83-
Requires-Dist: pywin32 ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'dev'
84-
Requires-Dist: wheel ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'dev'
85-
Requires-Dist: wmi ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'dev'
8680
Provides-Extra: test
8781
Requires-Dist: pytest ; extra == 'test'
8882
Requires-Dist: pytest-instafail ; extra == 'test'
89-
Requires-Dist: pytest-subtests ; extra == 'test'
9083
Requires-Dist: pytest-xdist ; extra == 'test'
9184
Requires-Dist: setuptools ; extra == 'test'
92-
Requires-Dist: pywin32 ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'test'
93-
Requires-Dist: wheel ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'test'
94-
Requires-Dist: wmi ; (os_name == "nt" and platform_python_implementation != "PyPy") and extra == 'test'
9585

9686
| |downloads| |stars| |forks| |contributors| |coverage|
9787
| |version| |packages| |license|
@@ -508,6 +498,16 @@ Further process APIs
508498
>>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
509499
>>>
510500

501+
Heap info
502+
---------
503+
504+
.. code-block:: python
505+
506+
>>> import psutil
507+
>>> psutil.heap_info()
508+
pheap(heap_used=5177792, mmap_used=819200)
509+
>>> psutil.heap_trim()
510+
511511
Windows services
512512
----------------
513513

contrib/python/psutil/py3/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ Further process APIs
454454
>>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
455455
>>>
456456
457+
Heap info
458+
---------
459+
460+
.. code-block:: python
461+
462+
>>> import psutil
463+
>>> psutil.heap_info()
464+
pheap(heap_used=5177792, mmap_used=819200)
465+
>>> psutil.heap_trim()
466+
457467
Windows services
458468
----------------
459469

contrib/python/psutil/py3/patches/99-fix-ya.make.patch

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- -DPSUTIL_WINDOWS=1
99
- -DPSUTIL_SIZEOF_PID_T=4
1010
- -DPSUTIL_MAYBE_EXTERN=extern
11-
@@ -42,50 +33,4 @@ SRCS(
11+
@@ -42,53 +33,4 @@ SRCS(
1212
- psutil/_psutil_linux.c
1313
- psutil/_psutil_osx.c
1414
- psutil/_psutil_windows.c
@@ -17,11 +17,13 @@
1717
psutil/arch/all/pids.c
1818
psutil/arch/all/str.c
1919
- psutil/arch/linux/disk.c
20+
- psutil/arch/linux/heap.c
2021
- psutil/arch/linux/mem.c
2122
- psutil/arch/linux/net.c
2223
- psutil/arch/linux/proc.c
2324
- psutil/arch/osx/cpu.c
2425
- psutil/arch/osx/disk.c
26+
- psutil/arch/osx/heap.c
2527
- psutil/arch/osx/init.c
2628
- psutil/arch/osx/mem.c
2729
- psutil/arch/osx/net.c
@@ -45,6 +47,7 @@
4547
- psutil/arch/sunos/sys.c
4648
- psutil/arch/windows/cpu.c
4749
- psutil/arch/windows/disk.c
50+
- psutil/arch/windows/heap.c
4851
- psutil/arch/windows/init.c
4952
- psutil/arch/windows/mem.c
5053
- psutil/arch/windows/net.c
@@ -59,7 +62,7 @@
5962
- psutil/arch/windows/socks.c
6063
- psutil/arch/windows/sys.c
6164
- psutil/arch/windows/wmi.c
62-
@@ -74,5 +36,99 @@ SRCS(
65+
@@ -74,5 +36,102 @@ SRCS(
6366
-PY_REGISTER(
6467
- psutil._psutil_linux
6568
- psutil._psutil_osx
@@ -74,6 +77,7 @@
7477
+ SRCS(
7578
+ psutil/_psutil_linux.c
7679
+ psutil/arch/linux/disk.c
80+
+ psutil/arch/linux/heap.c
7781
+ psutil/arch/linux/mem.c
7882
+ psutil/arch/linux/net.c
7983
+ psutil/arch/linux/proc.c
@@ -105,6 +109,7 @@
105109
+ psutil/_psutil_osx.c
106110
+ psutil/arch/osx/cpu.c
107111
+ psutil/arch/osx/disk.c
112+
+ psutil/arch/osx/heap.c
108113
+ psutil/arch/osx/init.c
109114
+ psutil/arch/osx/mem.c
110115
+ psutil/arch/osx/net.c
@@ -144,6 +149,7 @@
144149
+ psutil/_psutil_windows.c
145150
+ psutil/arch/windows/cpu.c
146151
+ psutil/arch/windows/disk.c
152+
+ psutil/arch/windows/heap.c
147153
+ psutil/arch/windows/init.c
148154
+ psutil/arch/windows/mem.c
149155
+ psutil/arch/windows/net.c

contrib/python/psutil/py3/psutil/__init__.py

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
pwd = None
3737

3838
from . import _common
39+
from . import _ntuples as _ntp
3940
from ._common import AIX
4041
from ._common import BSD
4142
from ._common import CONN_CLOSE
@@ -203,7 +204,7 @@
203204
AF_LINK = _psplatform.AF_LINK
204205

205206
__author__ = "Giampaolo Rodola'"
206-
__version__ = "7.1.3"
207+
__version__ = "7.2.0"
207208
version_info = tuple(int(num) for num in __version__.split('.'))
208209

209210
_timer = getattr(time, 'monotonic', time.time)
@@ -1162,7 +1163,7 @@ def memory_percent(self, memtype="rss"):
11621163
>>> psutil.Process().memory_info()._fields
11631164
('rss', 'vms', 'shared', 'text', 'lib', 'data', 'dirty', 'uss', 'pss')
11641165
"""
1165-
valid_types = list(_psplatform.pfullmem._fields)
1166+
valid_types = list(_ntp.pfullmem._fields)
11661167
if memtype not in valid_types:
11671168
msg = (
11681169
f"invalid memtype {memtype!r}; valid types are"
@@ -1171,7 +1172,7 @@ def memory_percent(self, memtype="rss"):
11711172
raise ValueError(msg)
11721173
fun = (
11731174
self.memory_info
1174-
if memtype in _psplatform.pmem._fields
1175+
if memtype in _ntp.pmem._fields
11751176
else self.memory_full_info
11761177
)
11771178
metrics = fun()
@@ -1211,11 +1212,9 @@ def memory_maps(self, grouped=True):
12111212
d[path] = list(map(lambda x, y: x + y, d[path], nums))
12121213
except KeyError:
12131214
d[path] = nums
1214-
nt = _psplatform.pmmap_grouped
1215-
return [nt(path, *d[path]) for path in d]
1215+
return [_ntp.pmmap_grouped(path, *d[path]) for path in d]
12161216
else:
1217-
nt = _psplatform.pmmap_ext
1218-
return [nt(*x) for x in it]
1217+
return [_ntp.pmmap_ext(*x) for x in it]
12191218

12201219
def open_files(self):
12211220
"""Return files opened by process as a list of
@@ -1751,7 +1750,7 @@ def _cpu_busy_time(times):
17511750
def _cpu_times_deltas(t1, t2):
17521751
assert t1._fields == t2._fields, (t1, t2)
17531752
field_deltas = []
1754-
for field in _psplatform.scputimes._fields:
1753+
for field in _ntp.scputimes._fields:
17551754
field_delta = getattr(t2, field) - getattr(t1, field)
17561755
# CPU times are always supposed to increase over time
17571756
# or at least remain the same and that's because time
@@ -1766,7 +1765,7 @@ def _cpu_times_deltas(t1, t2):
17661765
# https://gitlab.com/procps-ng/procps/blob/v3.3.12/top/top.c#L5063
17671766
field_delta = max(0, field_delta)
17681767
field_deltas.append(field_delta)
1769-
return _psplatform.scputimes(*field_deltas)
1768+
return _ntp.scputimes(*field_deltas)
17701769

17711770

17721771
def cpu_percent(interval=None, percpu=False):
@@ -1885,7 +1884,7 @@ def calculate(t1, t2):
18851884
# make sure we don't return negative values or values over 100%
18861885
field_perc = min(max(0.0, field_perc), 100.0)
18871886
nums.append(field_perc)
1888-
return _psplatform.scputimes(*nums)
1887+
return _ntp.scputimes(*nums)
18891888

18901889
# system-wide usage
18911890
if not percpu:
@@ -1955,7 +1954,7 @@ def cpu_freq(percpu=False):
19551954
min_ = mins / num_cpus
19561955
max_ = maxs / num_cpus
19571956

1958-
return _common.scpufreq(current, min_, max_)
1957+
return _ntp.scpufreq(current, min_, max_)
19591958

19601959
__all__.append("cpu_freq")
19611960

@@ -2114,13 +2113,12 @@ def disk_io_counters(perdisk=False, nowrap=True):
21142113
return {} if perdisk else None
21152114
if nowrap:
21162115
rawdict = _wrap_numbers(rawdict, 'psutil.disk_io_counters')
2117-
nt = getattr(_psplatform, "sdiskio", _common.sdiskio)
21182116
if perdisk:
21192117
for disk, fields in rawdict.items():
2120-
rawdict[disk] = nt(*fields)
2118+
rawdict[disk] = _ntp.sdiskio(*fields)
21212119
return rawdict
21222120
else:
2123-
return nt(*(sum(x) for x in zip(*rawdict.values())))
2121+
return _ntp.sdiskio(*(sum(x) for x in zip(*rawdict.values())))
21242122

21252123

21262124
disk_io_counters.cache_clear = functools.partial(
@@ -2167,10 +2165,10 @@ def net_io_counters(pernic=False, nowrap=True):
21672165
rawdict = _wrap_numbers(rawdict, 'psutil.net_io_counters')
21682166
if pernic:
21692167
for nic, fields in rawdict.items():
2170-
rawdict[nic] = _common.snetio(*fields)
2168+
rawdict[nic] = _ntp.snetio(*fields)
21712169
return rawdict
21722170
else:
2173-
return _common.snetio(*[sum(x) for x in zip(*rawdict.values())])
2171+
return _ntp.snetio(*[sum(x) for x in zip(*rawdict.values())])
21742172

21752173

21762174
net_io_counters.cache_clear = functools.partial(
@@ -2252,7 +2250,7 @@ def net_if_addrs():
22522250
while addr.count(separator) < 5:
22532251
addr += f"{separator}00"
22542252

2255-
nt = _common.snicaddr(fam, addr, mask, broadcast, ptp)
2253+
nt = _ntp.snicaddr(fam, addr, mask, broadcast, ptp)
22562254

22572255
# On Windows broadcast is None, so we determine it via
22582256
# ipaddress module.
@@ -2321,9 +2319,7 @@ def convert(n):
23212319
elif critical and not high:
23222320
high = critical
23232321

2324-
ret[name].append(
2325-
_common.shwtemp(label, current, high, critical)
2326-
)
2322+
ret[name].append(_ntp.shwtemp(label, current, high, critical))
23272323

23282324
return dict(ret)
23292325

@@ -2409,6 +2405,52 @@ def win_service_get(name):
24092405
return _psplatform.win_service_get(name)
24102406

24112407

2408+
# =====================================================================
2409+
# --- malloc / heap
2410+
# =====================================================================
2411+
2412+
2413+
# Linux + glibc, Windows, macOS, FreeBSD, NetBSD
2414+
if hasattr(_psplatform, "heap_info"):
2415+
2416+
def heap_info():
2417+
"""Return low-level heap statistics from the C heap allocator
2418+
(glibc).
2419+
2420+
- `heap_used`: the total number of bytes allocated via
2421+
malloc/free. These are typically allocations smaller than
2422+
MMAP_THRESHOLD.
2423+
2424+
- `mmap_used`: the total number of bytes allocated via `mmap()`
2425+
or via large ``malloc()`` allocations.
2426+
2427+
- `heap_count` (Windows only): number of private heaps created
2428+
via `HeapCreate()`.
2429+
"""
2430+
return _ntp.pheap(*_psplatform.heap_info())
2431+
2432+
def heap_trim():
2433+
"""Request that the underlying allocator free any unused memory
2434+
it's holding in the heap (typically small `malloc()`
2435+
allocations).
2436+
2437+
In practice, modern allocators rarely comply, so this is not a
2438+
general-purpose memory-reduction tool and won't meaningfully
2439+
shrink RSS in real programs. Its primary value is in **leak
2440+
detection tools**.
2441+
2442+
Calling `heap_trim()` before taking measurements helps reduce
2443+
allocator noise, giving you a cleaner baseline so that changes
2444+
in `heap_used` come from the code you're testing, not from
2445+
internal allocator caching or fragmentation. Its effectiveness
2446+
depends on allocator behavior and fragmentation patterns.
2447+
"""
2448+
_psplatform.heap_trim()
2449+
2450+
__all__.append("heap_info")
2451+
__all__.append("heap_trim")
2452+
2453+
24122454
# =====================================================================
24132455

24142456

0 commit comments

Comments
 (0)