Skip to content

Commit

Permalink
Make uptime type consitent to fix boot time error. (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolingbao authored and giampaolo committed Mar 17, 2019
1 parent 01ca896 commit 7b70d28
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@ static PyObject *TimeoutAbandoned;
*/
static PyObject *
psutil_boot_time(PyObject *self, PyObject *args) {
#if (_WIN32_WINNT >= 0x0600) // Windows Vista
ULONGLONG uptime;
#else
double uptime;
#endif
time_t pt;
FILETIME fileTime;
long long ll;
ULONGLONG ll;
HINSTANCE hKernel32;
psutil_GetTickCount64 = NULL;

GetSystemTimeAsFileTime(&fileTime);
/*
Expand All @@ -157,33 +155,26 @@ psutil_boot_time(PyObject *self, PyObject *args) {
and 01-01-1601, from time_t the divide by 1e+7 to get to the same
base granularity.
*/
#if (_WIN32_WINNT >= 0x0600) // Windows Vista
ll = (((ULONGLONG)
#else
ll = (((LONGLONG)
#endif
(fileTime.dwHighDateTime)) << 32) + fileTime.dwLowDateTime;
pt = (time_t)((ll - 116444736000000000ull) / 10000000ull);

// GetTickCount64() is Windows Vista+ only. Dinamically load
// it at runtime. We may have used
// GetTickCount64() is Windows Vista+ only. Dynamically load
// GetTickCount64() at runtime. We may have used
// "#if (_WIN32_WINNT >= 0x0600)" pre-processor but that way
// the produced exe/wheels cannot be used on Windows XP, see:
// https://github.com/giampaolo/psutil/issues/811#issuecomment-230639178
if (psutil_GetTickCount64 != NULL) {
// Windows >= Vista
uptime = psutil_GetTickCount64() / (ULONGLONG)1000.00f;
return Py_BuildValue("K", pt - uptime);
uptime = psutil_GetTickCount64() / 1000ull;
}
else {
// Windows XP.
// GetTickCount() time will wrap around to zero if the
// system is run continuously for 49.7 days.
psutil_debug("Windows < Vista; using GetTickCount() instead of "
"GetTickCount64()");
uptime = GetTickCount() / (LONGLONG)1000.00f;
return Py_BuildValue("L", pt - uptime);
uptime = (ULONGLONG)GetTickCount() / 1000ull;
}
return Py_BuildValue("K", pt - uptime);
}


Expand Down

0 comments on commit 7b70d28

Please sign in to comment.