summaryrefslogtreecommitdiff
path: root/psutil
Commit message (Collapse)AuthorAgeFilesLines
* fix typos and some other minor bugs (#2253)HEADmastercui fliter2023-05-094-7/+7
| | | Signed-off-by: cui fliter <imcusg@gmail.com>
* skip who CLI related test if necessaryGiampaolo Rodola2023-05-021-1/+2
|
* NetBSD, cmdline(): add debug message on EINVAL (re. to #2250)Giampaolo Rodola2023-05-021-4/+6
|
* SunOS: fix some C compilation warningsGiampaolo Rodola2023-04-224-14/+16
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* OSX / refact: get rid of process_info.c (#2243)Giampaolo Rodola2023-04-205-432/+396
|
* OSX C refact: reconstruct _psutil_osx.c to preserve historyosx-move-proc-funcsGiampaolo Rodola2023-04-194-165/+186
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* OSX: rename psutil/_psutil_osx.c to arch/osx/proc.c to preserve GIT historyGiampaolo Rodola2023-04-191-0/+0
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* OSX big C refactoring (#2242)Giampaolo Rodola2023-04-2013-792/+906
|
* fix failing users() test; update HISTORY; give CREDITS to @0-wiz-0 for #2241Giampaolo Rodola2023-04-201-2/+9
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* win, C, refact: rename process_*.c files to proc_*.cwin-c-refactGiampaolo Rodola2023-04-199-11/+18
|\
| * win C refact: reconstruct _psutil_windows.c trying to preserve historyGiampaolo Rodola2023-04-194-301/+360
| | | | | | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
| * rename _psutil_windows.c -> proc.cGiampaolo Rodola2023-04-191-0/+0
| | | | | | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* | Win, C, refact: move proc funcs into proc.c fileGiampaolo Rodola2023-04-194-1224/+1276
|/ | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* Merge branch 'c-refact'Giampaolo Rodola2023-04-1911-1001/+1060
|\
| * BSD big refact: move proc funcs in new proc.c fileGiampaolo Rodola2023-04-1911-1001/+1060
| |
* | Fix build on NetBSD due to missing .h include. (#2241)Thomas Klausner2023-04-191-0/+1
|/
* Win, C, refact: move boot_time() and users() in new sys.cGiampaolo Rodola2023-04-183-167/+194
|
* Windows / refact: new sensors.c fileGiampaolo Rodola2023-04-183-25/+42
|
* C refact: remove useless cmdline / cwd / environ layers. Call direct functionsGiampaolo Rodola2023-04-1814-281/+170
|
* Add CI testing for OpenBSD and NetBSD (#2240)Giampaolo Rodola2023-04-172-2/+3
|
* Fix #2239 / proc name(): don't fail with ZombieProcess on cmdline()Giampaolo Rodola2023-04-172-3/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A recent failure observed on OpenBSD led me to an interesting consideration. ``` ====================================================================== ERROR: psutil.tests.test_process.TestProcess.test_long_name ---------------------------------------------------------------------- Traceback (most recent call last): File "/vagrant/psutil/psutil/_psbsd.py", line 566, in wrapper return fun(self, *args, **kwargs) File "/vagrant/psutil/psutil/_psbsd.py", line 684, in cmdline return cext.proc_cmdline(self.pid) ProcessLookupError: [Errno 3] No such process During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/vagrant/psutil/psutil/tests/test_process.py", line 751, in test_long_name self.assertEqual(p.name(), os.path.basename(testfn)) File "/vagrant/psutil/psutil/__init__.py", line 628, in name cmdline = self.cmdline() File "/vagrant/psutil/psutil/__init__.py", line 681, in cmdline return self._proc.cmdline() File "/vagrant/psutil/psutil/_psbsd.py", line 569, in wrapper raise ZombieProcess(self.pid, self._name, self._ppid) psutil.ZombieProcess: PID still exists but it's a zombie (pid=48379) ---------------------------------------------------------------------- ``` The exception above occurs sporadically. It originates from `sysctl (KERN_PROC_ARGV)`: https://github.com/giampaolo/psutil/blob/0a81fa089fd4b25b4b7ee71ed39213b83f73c052/psutil/arch/openbsd/proc.c#L149 The error per se does not represent a bug in the OpenBSD `cmdline ()` implemention because the process **really** is a zombie at that point (I'm not sure why it's a zombie - this seems only to occur only on OpenBSD for this specific test case - but that's not the point). The interesting thing is that the test calls process `name()` (which succeeds, despite it's a zombie process), but since the process name is too long it gets truncated to 15 chars (this is a UNIX thing) so psutil tries to guess the remaining characters from the process `cmdline()`, which fails: https://github.com/giampaolo/psutil/blob/0a81fa089fd4b25b4b7ee71ed39213b83f73c052/psutil/__init__.py#L623-L630 The problem to fix here is that, if `name()` succeeds but `cmdline()` fails, we should not raise `ZombieProcess`: we should simply return the (truncated) process `name()` instead, because that is better than nothing. Not on OpenBSD but on all platforms. Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* #2238: passed wrong value to Py_BuildValueGiampaolo Rodola2023-04-172-2/+2
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* fix #2238 if cwd() cannot be determined always return "" instead of NoneGiampaolo Rodola2023-04-177-21/+21
|
* Fix #2237, OpenBSD, cwd(): return None instead of FileNotFoundErrorGiampaolo Rodola2023-04-163-5/+10
|
* BSD: refactor py code related to filtering connectionsGiampaolo Rodola2023-04-161-42/+18
|
* Fix #2236 / NetNBSD: skip terminated process threadsGiampaolo Rodola2023-04-141-0/+4
| | | | | | | | | Process threads() and num_threads() methods now skip threads which are in ZOMBIE or IDLE state. It turns out that after a thread is terminated / join()ed, instead of disappearing it can stick around in a ZOMBIE or IDLE state, presumably for a while before being garbage collected. Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* [NetBSD] virtual_memory() metrics are completely wrong (#2235), fixes #2234Giampaolo Rodola2023-04-152-30/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Match values shown by **htop**. This is before. In here: * available mem is almost the same as total (unrealistic) * used is higher than total; there's also a failing test: ``` MEMORY ------ Total : 972.7M Available : 959.1M Percent : 1.4 Used : 1.1G Free : 173.6M Active : 434.3M Inactive : 258.4M Buffers : 509.4M Cached : 692.9M Shared : 0.0B Wired : 280.0K ``` Now: ``` MEMORY ------ Total : 972.7M Available : 538.1M Percent : 44.7 Used : 434.5M Free : 173.6M Active : 434.2M Inactive : 258.4M Buffers : 509.4M Cached : 692.9M Shared : 0.0B Wired : 280.0K ```
* [NetBSD] available mem can be higher than total (#2233)Giampaolo Rodola2023-04-142-14/+25
| | | | | | | | | | | | | | | | | On NetBSD "available" memory can be higher than "total". From now now calculate it exactly the same as Zabbix: https://github.com/zabbix/zabbix/blob/af5e0f80253e585ca7082ca6bc9cc07400afe2a7/src/libs/zbxsysinfo/netbsd/memory.c Fixes https://github.com/giampaolo/psutil/issues/2231 which produced this failure: ``` ====================================================================== FAIL: psutil.tests.test_system.TestMemoryAPIs.test_virtual_memory ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/vagrant/psutil/psutil/tests/test_system.py", line 275, in test_virtual_memory assert 0 <= mem.percent <= 100, mem ^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: svmem(total=1019899904, available=1046573056, percent=-2.6, used=603414528, free=545050624, active=234807296, inactive=133210112, buffers=260288512, cached=368312320, shared=0, wired=294912) ```
* [NetBSD] move files / refactoring of C files (#2232)Giampaolo Rodola2023-04-149-268/+325
|
* fix NetBSD test failure + add test for cached memGiampaolo Rodola2023-04-131-0/+12
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* OpenBSD: rewrite net_connections() from scratch (#2230)Giampaolo Rodola2023-04-139-267/+227
|
* Get Windows percent swap usage from performance counters (#2160)Daniel Widdis2023-04-135-5/+85
| | | Signed-off-by: Daniel Widdis <widdis@gmail.com>
* fix users() test on OpenBSDGiampaolo Rodola2023-04-121-5/+7
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* OpenBSD is unable to recognize zombie process. (#2229)Giampaolo Rodola2023-04-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | OpenBSD is unable to recognize zombie process. It will raise NoSuchProcess instead of ZombieProcess. Test failure: ====================================================================== ERROR: psutil.tests.test_process.TestProcess.test_zombie_process ---------------------------------------------------------------------- Traceback (most recent call last): File "/vagrant/psutil/psutil/_psbsd.py", line 560, in wrapper return fun(self, *args, **kwargs) File "/vagrant/psutil/psutil/_psbsd.py", line 862, in open_files rawlist = cext.proc_open_files(self.pid) ProcessLookupError: [Errno 3] No such process During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/vagrant/psutil/psutil/tests/test_process.py", line 1312, in test_zombie_process zproc.as_dict() File "/vagrant/psutil/psutil/__init__.py", line 528, in as_dict ret = meth() File "/vagrant/psutil/psutil/__init__.py", line 1142, in open_files return self._proc.open_files() File "/vagrant/psutil/psutil/_psbsd.py", line 565, in wrapper raise NoSuchProcess(self.pid, self._name) psutil.NoSuchProcess: process no longer exists (pid=67013) This happens because OpenBSD is the only BSD defining 2 codes for zombie processes: # According to /usr/include/sys/proc.h SZOMB is unused. # test_zombie_process() shows that SDEAD is the right # equivalent. Also it appears there's no equivalent of # psutil.STATUS_DEAD. SDEAD really means STATUS_ZOMBIE. # cext.SZOMB: _common.STATUS_ZOMBIE, cext.SDEAD: _common.STATUS_ZOMBIE, cext.SZOMB: _common.STATUS_ZOMBIE,
* [POSIX] psutil.users() loses precision for "started" attribute #2225 (#2226)Giampaolo Rodola2023-04-121-2/+2
|
* fix some tests on BSD platformsGiampaolo Rodola2023-04-124-5/+14
|
* [POSIX] psutil.users() loses precision for "started" attribute #2225 (#2226)Giampaolo Rodola2023-04-116-16/+44
|
* move psutil_getpagesize() in a new mem.c fileGiampaolo Rodola2023-04-103-12/+10
|
* move psutil_virtual_mem() in a new mem.c fileGiampaolo Rodola2023-04-103-29/+45
|
* Fix Linux test: allow '-dirty' or other version postfixes (#2221)Mark Asselstine2023-04-051-1/+1
| | | | | | | | | | | | | | | | | It is possible that 'free -V' will return a version that includes a postfix such as '-dirty'. For example procps-ng will explicitly add this when building from git: https://gitlab.com/procps-ng/procps/-/blob/master/local/git-version-gen#L154 Process the version string to drop these string postfixes from the version tuple, failing to do so will result in the test failing File ".../psutil/tests/test_linux.py", line 204, in get_free_version_info return tuple(map(int, out.split()[-1].split('.'))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '3-dirty' Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
* Fix pylint warnings / cleanup (#2218)Giampaolo Rodola2023-04-0119-108/+65
|
* Merge branch 'master' of github.com:giampaolo/psutilGiampaolo Rodola2023-03-292-68/+103
|\
| * [Linux] guess `available` virtual_memory() if kernel says it's 0 (#2052)Giampaolo Rodola2023-03-292-68/+103
| | | | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* | fix C compilation warning on Linux + Python 2Giampaolo Rodola2023-03-291-1/+8
|/ | | | | | | | | | | psutil/_psutil_linux.c: In function ‘psutil_proc_cpu_affinity_set’: psutil/_psutil_linux.c:317:80: warning: unknown conversion type character ‘R’ in format [-Wformat=] 317 | return PyErr_Format(PyExc_TypeError, "sequence argument expected, got %R", Py_TYPE(py_cpu_set)); | ^ psutil/_psutil_linux.c:317:46: warning: too many arguments for format [-Wformat-extra-args] 317 | return PyErr_Format(PyExc_TypeError, "sequence argument expected, got %R", Py_TYPE(py_cpu_set)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ creating build/lib.linux-x86_64-2.7
* fix linux testsGiampaolo Rodola2023-03-281-3/+0
|
* When raising warning, always use stacklevel=2Giampaolo Rodola2023-03-273-6/+6
| | | | | | | | | | B028: No explicit stacklevel argument found. The warn method from the warnings module uses a stacklevel of 1 by default. This will only show a stack trace for the line on which the warn method is called. It is therefore recommended to use a stacklevel of 2 or greater to provide more information to the user. Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* Win: fix running tests in a virtual environment (#2216)Matthieu Darbois2023-03-274-18/+30
| | | | | | | | | | | | On windows, starting with python 3.7, virtual environments use a venvlauncher startup process This does not play well when counting spawned processes or when relying on the pid of the spawned process to do some checks e.g. connection check per pid This commit detects this situation and uses the base python executable to spawn processes when required. Signed-off-by: mayeut <mayeut@users.noreply.github.com>
* CI: fix TestScripts tests failing due to ambiguous SCRIPTS_DIR (#2211)Matthieu Darbois2023-03-181-1/+4
| | | | | | | | | | | | Tests are being run with psutil installed in a virtual environment within cibuildwheel builds. The scripts folder is not being found in this installation & thus, those tests are skipped. This commit allows to pass the path of the scripts folder through an environment variable & re-enables those tests. Signed-off-by: mayeut <mayeut@users.noreply.github.com>
* fix exec() compatibility with PYPY (closes #2198)Giampaolo Rodola2023-03-071-1/+6
|
* Clearer tracebacks in case of chained exceptions (#2196)Giampaolo Rodola2023-01-241-3/+26
| | | | | | In case of exception, display a cleaner error traceback by hiding the `KeyError` bit deriving from a missed cache hit. Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>