static uint64 calcStampsPerSecond() { static bool firstTime = true; if (firstTime) { firstTime = false; } #ifdef KBE_USE_RDTSC return calcStampsPerSecond_rdtsc(); #else if (g_timingMethod == RDTSC_TIMING_METHOD) return calcStampsPerSecond_rdtsc(); else if (g_timingMethod == GET_TIME_OF_DAY_TIMING_METHOD) return calcStampsPerSecond_gettimeofday(); else if (g_timingMethod == GET_TIME_TIMING_METHOD) return calcStampsPerSecond_gettime(); else { char * timingMethod = getenv("KBE_TIMING_METHOD"); if (!timingMethod) { g_timingMethod = DEFAULT_TIMING_METHOD; } else if (strcmp(timingMethod, "rdtsc") == 0) { g_timingMethod = RDTSC_TIMING_METHOD; } else if (strcmp(timingMethod, "gettimeofday") == 0) { g_timingMethod = GET_TIME_OF_DAY_TIMING_METHOD; } else if (strcmp(timingMethod, "gettime") == 0) { g_timingMethod = GET_TIME_TIMING_METHOD; } else { WARNING_MSG(fmt::format("calcStampsPerSecond: " "Unknown timing method '%s', using clock_gettime.\n", timingMethod)); g_timingMethod = DEFAULT_TIMING_METHOD; } return calcStampsPerSecond(); } #endif }
uint64 stampsPerSecond_rdtsc() { static uint64 stampsPerSecondCache = calcStampsPerSecond_rdtsc(); return stampsPerSecondCache; }