/* * Class: sage_Sage * Method: getEventTime0 * Signature: ()J */ JNIEXPORT jlong JNICALL Java_sage_Sage_getEventTime0(JNIEnv *env, jclass jc) { // DWORD event_offset = GetMessageTime(); // if (event_offset <= 0) { // event_offset = GetTickCount(); // } // NARFLEX - I have no idea why this was using GetMessageTime; but that causes the value to // vary between threads which is very, very bad so we don't use that at all anymore. DWORD event_offset = GetTickCount(); // All computations and stored values are in milliseconds. The Win32 // FILETIME structure is in 100s of nanoseconds, so the FT2INT64 macro // divides by 10^4. (10^7 / 10^4 = 10^3). // // UTC time is milliseconds since January 1, 1970. // Windows system time is 100s of nanoseconds since January 1, 1601. // Windows event time is milliseconds since boot, but wraps every 49.7 // days because it is only a DWORD. static const jlong WRAP_TIME_MILLIS = (jlong)((DWORD)-1); static jlong boot_time_utc = 0; static jlong boot_time_1601 = 0; static jlong utc_epoch_1601 = 0; if (utc_epoch_1601 == 0) { SYSTEMTIME sys_epoch_1601; FILETIME file_epoch_1601; memset(&sys_epoch_1601, 0, sizeof(SYSTEMTIME)); sys_epoch_1601.wYear = 1970; sys_epoch_1601.wMonth = 1; sys_epoch_1601.wDay = 1; SystemTimeToFileTime(&sys_epoch_1601, &file_epoch_1601); utc_epoch_1601 = FT2INT64(file_epoch_1601); } SYSTEMTIME current_sys_time_1601; FILETIME current_file_time_1601; jlong current_time_1601; GetSystemTime(¤t_sys_time_1601); SystemTimeToFileTime(¤t_sys_time_1601, ¤t_file_time_1601); current_time_1601 = FT2INT64(current_file_time_1601); if ((current_time_1601 - boot_time_1601) > WRAP_TIME_MILLIS) { // Need to reset boot time DWORD since_boot_millis = GetTickCount(); boot_time_1601 = current_time_1601 - since_boot_millis; boot_time_utc = boot_time_1601 - utc_epoch_1601; } return boot_time_utc + event_offset; }
long dbgsysCurrentTimeMillis() { static long fileTime_1_1_70 = 0; /* midnight 1/1/70 */ SYSTEMTIME st0; FILETIME ft0; /* initialize on first usage */ if (fileTime_1_1_70 == 0) { memset(&st0, 0, sizeof(st0)); st0.wYear = 1970; st0.wMonth = 1; st0.wDay = 1; SystemTimeToFileTime(&st0, &ft0); fileTime_1_1_70 = FT2INT64(ft0); } GetSystemTime(&st0); SystemTimeToFileTime(&st0, &ft0); return (FT2INT64(ft0) - fileTime_1_1_70) / 10000; }
jlong sysThreadCPUTime() { if (windowsNT) { FILETIME CreationTime; FILETIME ExitTime; FILETIME KernelTime; FILETIME UserTime; GetThreadTimes(GetCurrentThread(), &CreationTime, &ExitTime, &KernelTime, &UserTime); return FT2INT64(UserTime) * 100; } else { return (jlong)sysGetMilliTicks() * 1000000; } }