Skip to content
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

cpu_times() GetSystemTimes function double dword convert to __int64,t… #1243

Merged
merged 4 commits into from Mar 13, 2018

Conversation

stswandering
Copy link
Contributor

cpu_times() GetSystemTimes function double dword convert to __int64,then double,instead of float.

@giampaolo
Copy link
Owner

giampaolo commented Mar 12, 2018

So, I took those "weird" numbers from cPython source code (os.times() function):
https://github.com/python/cpython/blob/3b20d3454e8082e07dba93617793de5dc9237828/Modules/posixmodule.c#L7734
As such, I would kinda feel safer if we leave them in place instead of introducing a new conversion logic.
What happens if simply cast the numbers to double?
Something like (pseudo code):

        user = (double)((HI_T * sppi[i].UserTime.HighPart) +
                        (LO_T * sppi[i].UserTime.LowPart));
        ...
        Py_BuildValue("d", user);

@stswandering
Copy link
Contributor Author

Cool! I have tried this method,it returns the same value. So, I change my pull request.

@giampaolo
Copy link
Owner

You also need to change this:

Py_BuildValue("(fff)", user, system, idle);

...to this:

Py_BuildValue("(ddd)", user, system, idle);

@stswandering
Copy link
Contributor Author

Yeah,Sure! It's my fault.

@giampaolo
Copy link
Owner

LGTM. Merging. Thanks. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants