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

windows cpu_times() in _psutil.windows.c use float will lose accuracy in a long running system #1240

Closed
stswandering opened this issue Mar 11, 2018 · 4 comments

Comments

@stswandering
Copy link
Contributor

In windows platform, GetSystemTimes function return double dword,high and low.
At precent,using float:
#define LO_T ((float)1e-7)
#define HI_T (LO_T*4294967296.0)
idle = (float)((HI_T * idle_time.dwHighDateTime) + * idle_time.dwLowDateTime));

for example:dwHighDateTime= 367519,dwLowDateTime=3192589922,returns 157848096.000000,
but in fact it was 1578480983281250.

the right way is to use __int64:
unsigned __int64 idle = idle_time.dwHighDateTime ;
idle <<= 32 ;
idle |= idle_time.dwLowDateTime ;

@giampaolo
Copy link
Owner

giampaolo commented Mar 11, 2018 via email

@stswandering
Copy link
Contributor Author

Thanks Reply! I'll try!

@stswandering
Copy link
Contributor Author

0826d7d
My pull request commited.

@giampaolo
Copy link
Owner

Fixed in #1243.

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

No branches or pull requests

2 participants