From df1e9732d0eee9c04b83c4ad39c817d92968fa2e Mon Sep 17 00:00:00 2001 From: Siana Gearz Date: Tue, 21 Aug 2012 07:43:47 +0200 Subject: [PATCH] Developers, profile thy profiler! --- indra/llcommon/llfasttimer_class.cpp | 46 ++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/indra/llcommon/llfasttimer_class.cpp b/indra/llcommon/llfasttimer_class.cpp index 15075aa87..5fb9fd580 100644 --- a/indra/llcommon/llfasttimer_class.cpp +++ b/indra/llcommon/llfasttimer_class.cpp @@ -183,6 +183,10 @@ BOOL LLFastTimer::sMetricLog = FALSE; LLMutex* LLFastTimer::sLogLock = NULL; std::queue LLFastTimer::sLogQueue; +#if LL_WINDOWS +#define USE_RDTSC 1 +#endif + std::vector* LLFastTimer::sTimerInfos = NULL; U64 LLFastTimer::sTimerCycles = 0; U32 LLFastTimer::sTimerCalls = 0; @@ -380,7 +384,9 @@ void LLFastTimer::updateCachedPointers() } // See lltimer.cpp. -#if LL_LINUX || LL_DARWIN || LL_SOLARIS +#if USE_RDTSC +std::string LLFastTimer::sClockType = "rdtsc"; +#elif LL_LINUX || LL_DARWIN || LL_SOLARIS std::string LLFastTimer::sClockType = "gettimeofday"; #elif LL_WINDOWS std::string LLFastTimer::sClockType = "QueryPerformanceCounter"; @@ -391,6 +397,9 @@ std::string LLFastTimer::sClockType = "QueryPerformanceCounter"; //static U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer { +#if USE_RDTSC + static U64 sCPUClockFrequency = U64(LLProcessorInfo().getCPUFrequency()*1000000.0); +#else static bool firstcall = true; static U64 sCPUClockFrequency; if (firstcall) @@ -398,6 +407,7 @@ U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer sCPUClockFrequency = calc_clock_frequency(); firstcall = false; } +#endif return sCPUClockFrequency >> 8; } @@ -937,6 +947,38 @@ LLFastTimer::LLFastTimer(LLFastTimer::FrameState* state) // Important note: These implementations must be FAST! // +#if USE_RDTSC +U32 LLFastTimer::getCPUClockCount32() +{ + U32 ret_val; + __asm + { + _emit 0x0f + _emit 0x31 + shr eax,8 + shl edx,24 + or eax, edx + mov dword ptr [ret_val], eax + } + return ret_val; +} + +// return full timer value, *not* shifted by 8 bits +U64 LLFastTimer::getCPUClockCount64() +{ + U64 ret_val; + __asm + { + _emit 0x0f + _emit 0x31 + mov eax,eax + mov edx,edx + mov dword ptr [ret_val+4], edx + mov dword ptr [ret_val], eax + } + return ret_val; +} +#else //LL_COMMON_API U64 get_clock_count(); // in lltimer.cpp // These use QueryPerformanceCounter, which is arguably fine and also works on AMD architectures. U32 LLFastTimer::getCPUClockCount32() @@ -948,4 +990,4 @@ U64 LLFastTimer::getCPUClockCount64() { return get_clock_count(); } - +#endif