pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/sysutils/py-psutil



Module Name:    pkgsrc
Committed By:   fox
Date:           Mon Apr  6 16:53:12 UTC 2026

Modified Files:
        pkgsrc/sysutils/py-psutil: Makefile distinfo
Added Files:
        pkgsrc/sysutils/py-psutil/patches: patch-psutil___psbsd.py
            patch-psutil_arch_netbsd_cpu.c patch-psutil_arch_netbsd_mem.c
            patch-psutil_arch_netbsd_proc.c

Log Message:
sysutils/psutil: Patch to remove procfs dependency

Replace procfs depdendency in the following sections
- cpu stats calculation
- memory usage calculation

While here also handle EBUSY failures gracefully.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 pkgsrc/sysutils/py-psutil/Makefile
cvs rdiff -u -r1.65 -r1.66 pkgsrc/sysutils/py-psutil/distinfo
cvs rdiff -u -r0 -r1.9 \
    pkgsrc/sysutils/py-psutil/patches/patch-psutil___psbsd.py
cvs rdiff -u -r0 -r1.4 \
    pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_cpu.c
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_mem.c \
    pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_proc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/sysutils/py-psutil/Makefile
diff -u pkgsrc/sysutils/py-psutil/Makefile:1.67 pkgsrc/sysutils/py-psutil/Makefile:1.68
--- pkgsrc/sysutils/py-psutil/Makefile:1.67     Fri Jan 30 13:00:21 2026
+++ pkgsrc/sysutils/py-psutil/Makefile  Mon Apr  6 16:53:11 2026
@@ -1,7 +1,8 @@
-# $NetBSD: Makefile,v 1.67 2026/01/30 13:00:21 adam Exp $
+# $NetBSD: Makefile,v 1.68 2026/04/06 16:53:11 fox Exp $
 
 DISTNAME=      psutil-7.2.2
 PKGNAME=       ${PYPKGPREFIX}-${DISTNAME}
+PKGREVISION=    1
 CATEGORIES=    sysutils python
 MASTER_SITES=  ${MASTER_SITE_PYPI:=p/psutil/}
 

Index: pkgsrc/sysutils/py-psutil/distinfo
diff -u pkgsrc/sysutils/py-psutil/distinfo:1.65 pkgsrc/sysutils/py-psutil/distinfo:1.66
--- pkgsrc/sysutils/py-psutil/distinfo:1.65     Fri Jan 30 13:00:21 2026
+++ pkgsrc/sysutils/py-psutil/distinfo  Mon Apr  6 16:53:11 2026
@@ -1,5 +1,9 @@
-$NetBSD: distinfo,v 1.65 2026/01/30 13:00:21 adam Exp $
+$NetBSD: distinfo,v 1.66 2026/04/06 16:53:11 fox Exp $
 
 BLAKE2s (psutil-7.2.2.tar.gz) = 21da95acab2183abcd1363b4adbd71899b2901afa3253e12fe424276a7b35dd9
 SHA512 (psutil-7.2.2.tar.gz) = 2de05c69d152a8582a4d8f1f02233cae5927baaa35f8797e4b0745f33e6b3c7239b9a54b719b0582b0b6c5b4bbc86d2e1e226c3e9854e4e5be9c5e349c704961
 Size (psutil-7.2.2.tar.gz) = 493740 bytes
+SHA1 (patch-psutil___psbsd.py) = b747e338433aec67195163d3bbb0b559f0cfacde
+SHA1 (patch-psutil_arch_netbsd_cpu.c) = 0470c9ee13db1f92d7f94c1db7e934fecd775a08
+SHA1 (patch-psutil_arch_netbsd_mem.c) = e1fbdc49451f8931a579d78b7de852967e096d49
+SHA1 (patch-psutil_arch_netbsd_proc.c) = e1298ef850ce59bed47edf8e6d2b604148ceb92c

Added files:

Index: pkgsrc/sysutils/py-psutil/patches/patch-psutil___psbsd.py
diff -u /dev/null pkgsrc/sysutils/py-psutil/patches/patch-psutil___psbsd.py:1.9
--- /dev/null   Mon Apr  6 16:53:12 2026
+++ pkgsrc/sysutils/py-psutil/patches/patch-psutil___psbsd.py   Mon Apr  6 16:53:12 2026
@@ -0,0 +1,65 @@
+$NetBSD: patch-psutil___psbsd.py,v 1.9 2026/04/06 16:53:12 fox Exp $
+
+Remove dependency on procfs.
+
+Upstream: https://github.com/giampaolo/psutil/pull/2805
+
+--- psutil/_psbsd.py.orig      2026-01-20 14:38:58.000000000 +0000
++++ psutil/_psbsd.py
+@@ -135,27 +135,11 @@ kinfo_proc_map = dict(
+ 
+ def virtual_memory():
+     mem = cext.virtual_mem()
++    total, free, active, inactive, wired, cached, buffers, shared = mem
+     if NETBSD:
+-        total, free, active, inactive, wired, cached = mem
+-        # On NetBSD buffers and shared mem is determined via /proc.
+-        # The C ext set them to 0.
+-        with open('/proc/meminfo', 'rb') as f:
+-            for line in f:
+-                if line.startswith(b'Buffers:'):
+-                    buffers = int(line.split()[1]) * 1024
+-                elif line.startswith(b'MemShared:'):
+-                    shared = int(line.split()[1]) * 1024
+-        # Before avail was calculated as (inactive + cached + free),
+-        # same as zabbix, but it turned out it could exceed total (see
+-        # #2233), so zabbix seems to be wrong. Htop calculates it
+-        # differently, and the used value seem more realistic, so let's
+-        # match htop.
+-        # https://github.com/htop-dev/htop/blob/e7f447b/netbsd/NetBSDProcessList.c#L162
+-        # https://github.com/zabbix/zabbix/blob/af5e0f8/src/libs/zbxsysinfo/netbsd/memory.c#L135
+         used = active + wired
+-        avail = total - used
+-    else:
+-        total, free, active, inactive, wired, cached, buffers, shared = mem
++        avail = total - used        
++    else:        
+         # matches freebsd-memory CLI:
+         # * https://people.freebsd.org/~rse/dist/freebsd-memory
+         # * https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
+@@ -260,24 +244,7 @@ def cpu_stats():
+         # Note: the C ext is returning some metrics we are not exposing:
+         # traps.
+         ctxsw, intrs, soft_intrs, syscalls, _traps = cext.cpu_stats()
+-    elif NETBSD:
+-        # XXX
+-        # Note about intrs: the C extension returns 0. intrs
+-        # can be determined via /proc/stat; it has the same value as
+-        # soft_intrs thought so the kernel is faking it (?).
+-        #
+-        # Note about syscalls: the C extension always sets it to 0 (?).
+-        #
+-        # Note: the C ext is returning some metrics we are not exposing:
+-        # traps, faults and forks.
+-        ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = (
+-            cext.cpu_stats()
+-        )
+-        with open('/proc/stat', 'rb') as f:
+-            for line in f:
+-                if line.startswith(b'intr'):
+-                    intrs = int(line.split()[1])
+-    elif OPENBSD:
++    elif NETBSD or OPENBSD:
+         # Note: the C ext is returning some metrics we are not exposing:
+         # traps, faults and forks.
+         ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = (

Index: pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_cpu.c
diff -u /dev/null pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_cpu.c:1.4
--- /dev/null   Mon Apr  6 16:53:12 2026
+++ pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_cpu.c    Mon Apr  6 16:53:12 2026
@@ -0,0 +1,89 @@
+$NetBSD: patch-psutil_arch_netbsd_cpu.c,v 1.4 2026/04/06 16:53:12 fox Exp $
+
+Remove dependency on procfs.
+
+Upstream: https://github.com/giampaolo/psutil/pull/2805
+
+--- psutil/arch/netbsd/cpu.c.orig      2025-11-06 17:44:47.000000000 +0000
++++ psutil/arch/netbsd/cpu.c
+@@ -6,6 +6,10 @@
+  */
+ 
+ #include <Python.h>
++#include <fcntl.h>
++#include <kvm.h>
++#include <limits.h>
++#include <nlist.h>
+ #include <sys/sched.h>
+ #include <sys/sysctl.h>
+ #include <uvm/uvm_extern.h>
+@@ -20,25 +24,59 @@ already) from cset 84219ad. For referenc
+ original(ish) implementations:
+ - per CPU times: 312442ad2a5b5d0c608476c5ab3e267735c3bc59 (Jan 2016)
+ - CPU stats: a991494e4502e1235ebc62b5ba450287d0dedec0 (Jan 2016)
+-*/
+-
+ 
++Interrupts are now taken by reading the kvm_open and reading
++the CPU counter there. We no longer need /proc/stat dependency.
++- https://github.com/NetBSD/src/blob/trunk/sys/miscfs/procfs/procfs_linux.c#L342
++*/
+ PyObject *
+ psutil_cpu_stats(PyObject *self, PyObject *args) {
+     struct uvmexp_sysctl uv;
+     int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
++    const int cpu_count_nintr = 3;
++    char errbuf[_POSIX2_LINE_MAX];
+ 
+     if (psutil_sysctl(uvmexp_mib, 2, &uv, sizeof(uv)) != 0)
+         return NULL;
++
++    kvm_t *kd = kvm_open(NULL, NULL, NULL, O_RDONLY, errbuf);
++    if (!kd) {
++        fprintf(stderr, "kvm_open: %s\n", errbuf);
++        return NULL;
++    }
++
++    struct nlist nl[] = {
++        { .n_name = "_cpu_counts" },
++        { .n_name = NULL          }
++    };
++
++    if (kvm_nlist(kd, nl) != 0 || nl[0].n_value == 0) {
++        fprintf(stderr, "kvm_nlist(_cpu_counts): %s\n", kvm_geterr(kd));
++        kvm_close(kd);
++        return NULL;
++    }
++
++    /* Read cpu_counts[CPU_COUNT_NINTR] — a single int64_t */
++    uintptr_t addr = nl[0].n_value + cpu_count_nintr * sizeof(int64_t);
++    int64_t nintr = 0;
++
++    if (kvm_read(kd, addr, &nintr, sizeof(nintr)) != sizeof(nintr)) {
++        fprintf(stderr, "kvm_read(cpu_counts[NINTR]): %s\n", kvm_geterr(kd));
++        kvm_close(kd);
++        return NULL;
++    }
++
++    kvm_close(kd);
++
+     return Py_BuildValue(
+-        "IIIIIII",
+-        uv.swtch,  // ctx switches
+-        uv.intrs,  // interrupts - XXX always 0, will be determined via /proc
+-        uv.softs,  // soft interrupts
+-        uv.syscalls,  // syscalls - XXX always 0
+-        uv.traps,  // traps
+-        uv.faults,  // faults
+-        uv.forks  // forks
++        "KKKKKKK",
++        (uint64_t)uv.swtch,    // ctx switches
++        (uint64_t)nintr,        // interrupts
++        (uint64_t)uv.softs,    // soft interrupts
++        (uint64_t)uv.syscalls, // syscalls - XXX always 0
++        (uint64_t)uv.traps,    // traps
++        (uint64_t)uv.faults,   // faults
++        (uint64_t)uv.forks     // forks
+     );
+ }
+ 

Index: pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_mem.c
diff -u /dev/null pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_mem.c:1.1
--- /dev/null   Mon Apr  6 16:53:12 2026
+++ pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_mem.c    Mon Apr  6 16:53:12 2026
@@ -0,0 +1,99 @@
+$NetBSD: patch-psutil_arch_netbsd_mem.c,v 1.1 2026/04/06 16:53:12 fox Exp $
+
+Remove dependency on procfs, compute values correctly.
+
+Upstream: https://github.com/giampaolo/psutil/pull/2805
+
+--- psutil/arch/netbsd/mem.c.orig      2025-11-02 21:47:52.000000000 +0000
++++ psutil/arch/netbsd/mem.c
+@@ -21,36 +21,70 @@ original(ish) implementations:
+ 
+ #include "../../arch/all/init.h"
+ 
+-
+-// Virtual memory stats, taken from:
+-// https://github.com/satterly/zabbix-stats/blob/master/src/libs/zbxsysinfo/
+-//     netbsd/memory.c
++/*
++ * Virtual memory stats for NetBSD using VM_UVMEXP2 and VM_METER.
++ *
++ * Sources:
++ *   cached  = (filepages + execpages + anonpages) << pageshift  [btop]
++ *   buffers = filepages << pageshift                             [file cache excl. exec]
++ *   shared  = (t_vmshr + t_rmshr) * pagesize                    [vmtotal]
++ *   used    = (active + wired) << pageshift                      [htop/btop]
++ *   avail   = total - used                                       [htop/btop]
++ */
+ PyObject *
+ psutil_virtual_mem(PyObject *self, PyObject *args) {
+-    size_t size;
+     struct uvmexp_sysctl uv;
+-    int mib[] = {CTL_VM, VM_UVMEXP2};
+-    long long cached;
++    struct vmtotal vmdata;
++    int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
++    int vmmeter_mib[] = {CTL_VM, VM_METER};
+ 
+-    if (psutil_sysctl(mib, 2, &uv, sizeof(uv)) != 0)
++    if (psutil_sysctl(uvmexp_mib, 2, &uv, sizeof(uv)) != 0)
+         return NULL;
++    if (psutil_sysctl(vmmeter_mib, 2, &vmdata, sizeof(vmdata)) != 0)
++        return NULL;
++
++    long long total    = (long long)uv.npages   << uv.pageshift;
++    long long free     = (long long)uv.free     << uv.pageshift;
++    long long active   = (long long)uv.active   << uv.pageshift;
++    long long inactive = (long long)uv.inactive << uv.pageshift;
++    long long wired    = (long long)uv.wired    << uv.pageshift;
++
++    /*
++     * cached: all memory currently backing file, exec, and anonymous
++     * mappings. Matches btop and the "Cached" line in /proc/meminfo.
++     */
++    long long cached = (long long)(uv.filepages + uv.execpages + uv.anonpages)
++                       << uv.pageshift;
++
++    /*
++     * buffers: file-backed pages excluding executable mappings.
++     * uvmexp_sysctl.filepages is the correct, always-synced source.
++     * Do NOT read this from /proc/meminfo "Buffers:" — that field is
++     * unreliable on NetBSD because procfs_domeminfo() reads cpu_counts[]
++     * without calling cpu_count_sync() first, producing stale values.
++     */
++    long long buffers = (long long)uv.filepages << uv.pageshift;
++
++    /*
++     * shared: virtual + real shared memory pages from vmtotal.
++     * This matches the "MemShared" line in /proc/meminfo.
++     */
++    long long shared = (long long)(vmdata.t_vmshr + vmdata.t_rmshr)
++                       << uv.pageshift;
+ 
+-    // Note: zabbix does not include anonpages, but that doesn't match the
+-    // "Cached" value in /proc/meminfo.
+-    // https://github.com/zabbix/zabbix/blob/af5e0f8/src/libs/zbxsysinfo/netbsd/memory.c#L182
+-    cached = (uv.filepages + uv.execpages + uv.anonpages) << uv.pageshift;
+     return Py_BuildValue(
+-        "LLLLLL",
+-        (long long)uv.npages << uv.pageshift,  // total
+-        (long long)uv.free << uv.pageshift,  // free
+-        (long long)uv.active << uv.pageshift,  // active
+-        (long long)uv.inactive << uv.pageshift,  // inactive
+-        (long long)uv.wired << uv.pageshift,  // wired
+-        cached  // cached
++        "LLLLLLLL",
++        total,     // total physical memory
++        free,      // free pages
++        active,    // active pages
++        inactive,  // inactive pages
++        wired,     // wired (kernel) pages
++        cached,    // file + exec + anon pages
++        buffers,   // file pages only (excl. exec)
++        shared     // shared memory pages
+     );
+ }
+ 
+-
+ PyObject *
+ psutil_swap_mem(PyObject *self, PyObject *args) {
+     uint64_t swap_total, swap_free;
Index: pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_proc.c
diff -u /dev/null pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_proc.c:1.1
--- /dev/null   Mon Apr  6 16:53:12 2026
+++ pkgsrc/sysutils/py-psutil/patches/patch-psutil_arch_netbsd_proc.c   Mon Apr  6 16:53:12 2026
@@ -0,0 +1,32 @@
+$NetBSD: patch-psutil_arch_netbsd_proc.c,v 1.1 2026/04/06 16:53:12 fox Exp $
+
+Handle EBUSY failures gracefully.
+
+Upstream: https://github.com/giampaolo/psutil/pull/2805
+
+--- psutil/arch/netbsd/proc.c.orig     2025-11-02 21:47:52.000000000 +0000
++++ psutil/arch/netbsd/proc.c
+@@ -227,6 +227,7 @@ psutil_proc_cmdline(PyObject *self, PyOb
+             if (errno == EBUSY) {
+                 // Usually happens with TestProcess.test_long_cmdline. See:
+                 // https://github.com/giampaolo/psutil/issues/2250
++              PyErr_Clear();
+                 attempt += 1;
+                 if (attempt < max_attempts) {
+                     psutil_debug("proc %zu cmdline(): retry on EBUSY", pid);
+@@ -236,6 +237,7 @@ psutil_proc_cmdline(PyObject *self, PyOb
+                     psutil_debug(
+                         "proc %zu cmdline(): return [] due to EBUSY", pid
+                     );
++                  PyErr_Clear();
+                     return py_retlist;
+                 }
+             }
+@@ -257,6 +259,7 @@ psutil_proc_cmdline(PyObject *self, PyOb
+     }
+ 
+     free(procargs);
++    PyErr_Clear();
+     return py_retlist;
+ 
+ error:



Home | Main Index | Thread Index | Old Index