More reliable profiling.

clock is the first instruction to execute on `EndTimingBlock`

Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
Ricardo Quesada 2013-08-28 18:29:09 -07:00
parent c4eb6c99ab
commit 57ce406bdb
1 changed files with 4 additions and 2 deletions

View File

@ -151,17 +151,20 @@ void ProfilingBeginTimingBlock(const char *timerName)
timer->numberOfCalls++; timer->numberOfCalls++;
// should be the last instruction in order to be more reliable
timer->_startTime = chrono::high_resolution_clock::now(); timer->_startTime = chrono::high_resolution_clock::now();
} }
void ProfilingEndTimingBlock(const char *timerName) void ProfilingEndTimingBlock(const char *timerName)
{ {
// should be the 1st instruction in order to be more reliable
auto now = chrono::high_resolution_clock::now();
Profiler* p = Profiler::getInstance(); Profiler* p = Profiler::getInstance();
ProfilingTimer* timer = (ProfilingTimer*)p->_activeTimers->objectForKey(timerName); ProfilingTimer* timer = (ProfilingTimer*)p->_activeTimers->objectForKey(timerName);
CCASSERT(timer, "CCProfilingTimer not found"); CCASSERT(timer, "CCProfilingTimer not found");
auto now = chrono::high_resolution_clock::now();
int duration = chrono::duration_cast<chrono::microseconds>(now - timer->_startTime).count(); int duration = chrono::duration_cast<chrono::microseconds>(now - timer->_startTime).count();
@ -170,7 +173,6 @@ void ProfilingEndTimingBlock(const char *timerName)
timer->_averageTime2 = timer->totalTime / timer->numberOfCalls; timer->_averageTime2 = timer->totalTime / timer->numberOfCalls;
timer->maxTime = MAX( timer->maxTime, duration); timer->maxTime = MAX( timer->maxTime, duration);
timer->minTime = MIN( timer->minTime, duration); timer->minTime = MIN( timer->minTime, duration);
} }
void ProfilingResetTimingBlock(const char *timerName) void ProfilingResetTimingBlock(const char *timerName)