Skip to content

Commit 974bb2b

Browse files
committed
Simplify uptime and reduce to one hour
#493
1 parent ccf6a9f commit 974bb2b

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8145
1+
#define BUILD_NUMBER 8146

Utils/Utils.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ namespace Utils
139139

140140
DWORD SubtractTimeInMS_gtc = 0;
141141
int64_t SubtractTimeInMS_gtc64 = 0;
142-
DWORD SubtractTimeInMS_tmt = 0;
143-
DWORD SubtractTimeInMS_mmt = 0;
144142
int64_t SubtractTimeInTicks_qpc = 0;
145143
bool IsPerformanceFrequencyCapped = false;
146144
uint64_t PerformanceFrequency_real = 0;
@@ -535,7 +533,7 @@ SIZE_T WINAPI Utils::kernel_HeapSize(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
535533

536534
bool Utils::InitUpTimeOffsets()
537535
{
538-
const uint64_t MS_PER_DAY = 86400000ULL;
536+
constexpr uint64_t MS_PER_HOUR = 1000ULL * 60 * 60;
539537

540538
// Gather system uptime values
541539
LARGE_INTEGER qpc, freq;
@@ -547,33 +545,12 @@ bool Utils::InitUpTimeOffsets()
547545
}
548546
uint64_t ms_qpc = (qpc.QuadPart * 1000ULL) / freq.QuadPart;
549547

550-
MMTIME mmt = {};
551-
mmt.wType = TIME_MS;
552-
if (timeGetSystemTime(&mmt, sizeof(mmt)) != MMSYSERR_NOERROR || mmt.wType != TIME_MS)
553-
{
554-
Logging::Log() << __FUNCTION__ << " Error: timeGetSystemTime failed!";
555-
556-
return false;
557-
}
558-
559-
DWORD tmt = timeGetTime();
560-
561-
DWORD gtc = GetTickCount();
562-
#if (_WIN32_WINNT >= 0x0502)
563-
ULONGLONG gtc64 = GetTickCount64();
564-
#endif
565-
566548
// Calculate full days from uptime in ms
567-
uint64_t timeInDays = ms_qpc / MS_PER_DAY;
568-
uint64_t timeInMS = timeInDays * MS_PER_DAY;
569-
uint64_t remainderTimeMS = ms_qpc - timeInMS;
549+
uint64_t timeInHours = ms_qpc / MS_PER_HOUR; // total hours since boot
550+
uint64_t timeInMS = timeInHours * MS_PER_HOUR; // milliseconds in those hours
570551

571-
SubtractTimeInMS_gtc = static_cast<DWORD>(gtc - remainderTimeMS);
572-
#if (_WIN32_WINNT >= 0x0502)
573-
SubtractTimeInMS_gtc64 = gtc64 - remainderTimeMS;
574-
#endif
575-
SubtractTimeInMS_tmt = static_cast<DWORD>(tmt - remainderTimeMS);
576-
SubtractTimeInMS_mmt = static_cast<DWORD>(mmt.u.ms - remainderTimeMS);
552+
SubtractTimeInMS_gtc = static_cast<DWORD>(timeInMS);
553+
SubtractTimeInMS_gtc64 = timeInMS;
577554
SubtractTimeInTicks_qpc = (timeInMS * freq.QuadPart) / 1000ULL;
578555

579556
PerformanceFrequency_real = freq.QuadPart;
@@ -588,7 +565,7 @@ bool Utils::InitUpTimeOffsets()
588565
" Capped: " << ((double)PerformanceFrequency_cap / 1'000'000'000.0) << " GHz";
589566
}
590567

591-
Logging::Log() << __FUNCTION__ << " Found " << timeInDays << " day" << (timeInDays == 1 ? "" : "s") << " system up time!";
568+
Logging::Log() << __FUNCTION__ << " Found " << timeInHours << " hours" << (timeInHours == 1 ? "" : "s") << " system up time!";
592569

593570
return true;
594571
}
@@ -715,7 +692,7 @@ DWORD WINAPI Utils::winmm_timeGetTime()
715692
return 0;
716693
}
717694

718-
return timeGetTime() - SubtractTimeInMS_tmt;
695+
return timeGetTime() - SubtractTimeInMS_gtc;
719696
}
720697

721698
MMRESULT WINAPI Utils::winmm_timeGetSystemTime(LPMMTIME pmmt, UINT cbmmt)
@@ -732,7 +709,7 @@ MMRESULT WINAPI Utils::winmm_timeGetSystemTime(LPMMTIME pmmt, UINT cbmmt)
732709
{
733710
if (cbmmt == sizeof(MMTIME) && pmmt->wType == TIME_MS)
734711
{
735-
pmmt->u.ms -= SubtractTimeInMS_mmt;
712+
pmmt->u.ms -= SubtractTimeInMS_gtc;
736713
}
737714
}
738715
return result;

0 commit comments

Comments
 (0)