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

Make uptime type consitent to fix boot time error. #1225

Merged
merged 2 commits into from
Mar 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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