-
-
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
psutil.disk_io_counters returns microseconds instead of seconds #1012
Comments
To be clear: if you divide psutil's time-related results by |
Up? |
That is exactly correct. |
From my own testing (gist) it seems I checked the implementation in You can see that it multiplies the value by 10 before dividing by 1000. The implementation of that particular value fetch is still the same. The commit doesn't have any message to explain why this is done, but I'm guessing it's to make the value a proper integer instead of a float. I tested it locally (Win7 pro x64) and neither I would recommend either changing the documentation to indicate that on Windows the returned values are in tens of microseconds (so that the code doesn't need to be modified if it works on other systems) or removing the x10 and stating that it returns microseconds on Windows. I'm assuming milliseconds are returned on other systems so this has to be documented for Windows explicitly. |
Sorry for being late. The values are supposed to be in milliseconds on all platforms including Windows. I don't have time to look into this right now but it seems some of you guys have figured out the math already. Can somebody provide a PR or tell me the math operation to use instead of the current |
The same operation won't work on all platforms because Windows returns different values than the Unixes do. I don't think a change needs to be made - just updating the documentation should be enough. However, if code is to be adjusted so that it returns milliseconds on Windows, just detect if the OS is Windows and divide by Is there any reason not to just return microseconds on all platforms? The adjustment for Windows would still be needed (division by There can be a compromise: return both values separately (raw and milliseconds) and just adjust the value differently on Windows to get the ms. |
Portability. It's easier to declare that milliseconds are returned on all platforms so that user won't have to do:
I'll just divide by |
Sorry, I was wrong: ((1*10)/1000)/1e5 = 1e-7 so the equivalent to what I've been doing to get milliseconds would be to divide by
In that sense, portability is a matter of consistency between platforms, not what unit you use. So milliseconds or microseconds would work just as well. I don't mind either way, just clarifying. |
Bug occured on these systems:
Windows 10: Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Windows 7: Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Bug did NOT occur with this Arch Linux system:
Python 2.7.13 (default, Dec 21 2016, 07:16:46)
Note: Bug tested to happen on both Windows 10 and Windows 7.
Example output on Windows:
query disk_io_counters() at 1 second intervals consistently results in the write_time being more than 5000 in difference. However, if the units were in milliseconds you can't spend more than 1000 milliseconds writing to disk within a second.
It seems that the units are microseconds. I spun up perfmon.exe and its numbers match to what i'm getting with python when I convert from microseconds to milliseconds.
The text was updated successfully, but these errors were encountered: