diff options
author | Olivier Dormond <odormond@users.noreply.github.com> | 2021-11-10 23:28:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-10 23:28:27 +0100 |
commit | 324b297de09feb1d5982db1145db2b6a6a4609b8 (patch) | |
tree | 8e2227587e25cd220e460b14d7e65a4bad35d871 /psutil/_psutil_osx.c | |
parent | 8fa1746685a86b8ddda454e2e2746d535e2b6d89 (diff) | |
download | psutil-324b297de09feb1d5982db1145db2b6a6a4609b8.tar.gz |
[macOS / M1] cpu_times(): convert mach tick units to nsecs (fixes #1956) (PR #2011)
Signed-off-by: Olivier Dormond <olivier.dormond@pix4d.com>
Diffstat (limited to 'psutil/_psutil_osx.c')
-rw-r--r-- | psutil/_psutil_osx.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 8c5990ae..87ec495b 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -279,16 +279,23 @@ static PyObject * psutil_proc_pidtaskinfo_oneshot(PyObject *self, PyObject *args) { pid_t pid; struct proc_taskinfo pti; + uint64_t total_user; + uint64_t total_system; if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) return NULL; if (psutil_proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti)) <= 0) return NULL; + total_user = pti.pti_total_user * PSUTIL_MACH_TIMEBASE_INFO.numer; + total_user /= PSUTIL_MACH_TIMEBASE_INFO.denom; + total_system = pti.pti_total_system * PSUTIL_MACH_TIMEBASE_INFO.numer; + total_system /= PSUTIL_MACH_TIMEBASE_INFO.denom; + return Py_BuildValue( "(ddKKkkkk)", - (float)pti.pti_total_user / 1000000000.0, // (float) cpu user time - (float)pti.pti_total_system / 1000000000.0, // (float) cpu sys time + (float)total_user / 1000000000.0, // (float) cpu user time + (float)total_system / 1000000000.0, // (float) cpu sys time // Note about memory: determining other mem stats on macOS is a mess: // http://www.opensource.apple.com/source/top/top-67/libtop.c?txt // I just give up. |