Skip to content

Commit

Permalink
fix #761: [Windows] psutil.boot_time() wraps to 0 after 49 days
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 9, 2016
1 parent 09b4bc6 commit ab9f29b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include .gitignore
include .travis.yml
include appveyor.yml
include CREDITS
include DEVNOTES.rst
include DEVGUIDE.rst
include HISTORY.rst
include INSTALL.rst
include LICENSE
Expand Down
2 changes: 1 addition & 1 deletion make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if "%1" == "build" (
if "%1" == "install" (
:install
call :build
%PYTHON% setup.py install
%PYTHON% setup.py develop
goto :eof
)

Expand Down
15 changes: 12 additions & 3 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ psutil_get_nic_addresses() {
*/
static PyObject *
psutil_boot_time(PyObject *self, PyObject *args) {
double uptime;
#if (_WIN32_WINNT >= 0x0600) // Windows Vista
ULONGLONG uptime;
#else
double uptime;
#endif
time_t pt;
FILETIME fileTime;
long long ll;
Expand All @@ -212,10 +216,15 @@ psutil_boot_time(PyObject *self, PyObject *args) {
+ fileTime.dwLowDateTime;
pt = (time_t)((ll - 116444736000000000ull) / 10000000ull);

// XXX - By using GetTickCount() time will wrap around to zero if the
#if (_WIN32_WINNT >= 0x0600) // Windows Vista
uptime = GetTickCount64() / (ULONGLONG)1000.00f;
#else
// GetTickCount() time will wrap around to zero if the
// system is run continuously for 49.7 days.
uptime = GetTickCount() / 1000.00f;
return Py_BuildValue("d", (double)pt - uptime);
#endif

return Py_BuildValue("d", (double)pt - (double)uptime);
}


Expand Down

0 comments on commit ab9f29b

Please sign in to comment.