-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert mach tick units to nsecs #1958
Conversation
Shouldn't this be executed on M1 only ( |
No, that's not necessary: mach_timebase_info will always give you a valid conversion factor, even if it happens to be 1/1. |
(closing & reopening to trigger a CI test run) |
(closing & reopening to trigger a CI test run) |
@rmalouf looks like there are compilation issues:
|
Hi @giampaolo! The compilation error is fixed for me by applying the following patch: diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 67a52aa9..2effa0a0 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -214,6 +214,7 @@ static PyObject *
psutil_proc_pidtaskinfo_oneshot(PyObject *self, PyObject *args) {
pid_t pid;
struct proc_taskinfo pti;
+ struct mach_timebase_info info;
uint64_t total_user, total_system;
if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) I have only tested it on Intel mac yet but will give it a shot tomorrow on M1. |
I finally managed to get my hands on an M1 and I can now confirm that this works. I've tested it on intel Monterey with python 3.9.6 from brew and M1 BigSur with python 3.8.2 from Apple. |
Closing this out since it's been outdated / fixed by #2011. |
Summary
Description
{{{
Mach sys calls report cpu time in "tick units" -- on intel cpus, these happen to be nsecs but on M1 machines they're about 40 nsecs. This PR corrects for this, but I think it still needs two improvements: the value of mach_timebase_info should be cached somewhere, and there are probably other places where the code depends on 1 tick=1 nsec that also need to be updated. Sounds reasonable? I can work on both of those, but I wanted to get some feedback first before I spend any more time on this.
}}}