iOS platform and Android don't have __thread local storage, so avoid multi-threaded profiler on those (only on _WIN32, __linux__ and __APPLE__ and not TARGET_OS_IPHONE
Add a Sleep(0) for Windows to yield threads (and not Sleep(1))
This commit is contained in:
@@ -293,8 +293,10 @@ void processProfileData( MyProfileWindow* profWindow, bool idle)
|
||||
{
|
||||
if (profWindow)
|
||||
{
|
||||
|
||||
profWindow->UpdateText(profWindow->profIter, idle);
|
||||
if (profWindow->profIter)
|
||||
{
|
||||
profWindow->UpdateText(profWindow->profIter, idle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,6 +255,7 @@ void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory)
|
||||
|
||||
do
|
||||
{
|
||||
B3_PROFILE("ExampleBrowserThreadFunc");
|
||||
float deltaTimeInSeconds = clock.getTimeMicroseconds()/1000000.f;
|
||||
{
|
||||
if (deltaTimeInSeconds > 0.1)
|
||||
@@ -263,9 +264,11 @@ void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory)
|
||||
}
|
||||
if (deltaTimeInSeconds < (gMinUpdateTimeMicroSecs/1e6))
|
||||
{
|
||||
B3_PROFILE("clock.usleep");
|
||||
clock.usleep(gMinUpdateTimeMicroSecs/10.);
|
||||
} else
|
||||
{
|
||||
B3_PROFILE("exampleBrowser->update");
|
||||
clock.reset();
|
||||
exampleBrowser->update(deltaTimeInSeconds);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ bool gAllowRetina = true;
|
||||
bool gDisableDemoSelection = false;
|
||||
static class ExampleEntries* gAllExamples=0;
|
||||
bool sUseOpenGL2 = false;
|
||||
bool drawGUI=true;
|
||||
#ifndef USE_OPENGL3
|
||||
extern bool useShadowMap;
|
||||
#endif
|
||||
@@ -298,17 +297,20 @@ struct btTimings
|
||||
int m_activeBuffer;
|
||||
btAlignedObjectArray<btTiming> m_timings[1];
|
||||
};
|
||||
|
||||
btTimings gTimings[BT_MAX_THREAD_COUNT];
|
||||
#ifndef BT_NO_PROFILE
|
||||
btTimings gTimings[BT_QUICKPROF_MAX_THREAD_COUNT];
|
||||
#define MAX_NESTING 1024
|
||||
int gStackDepths[BT_QUICKPROF_MAX_THREAD_COUNT] = {0};
|
||||
const char* gFuncNames[BT_QUICKPROF_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
unsigned long long int gStartTimes[BT_QUICKPROF_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
#endif
|
||||
|
||||
btClock clk;
|
||||
|
||||
#define MAX_NESTING 1024
|
||||
|
||||
|
||||
bool gProfileDisabled = true;
|
||||
int gStackDepths[BT_MAX_THREAD_COUNT] = {0};
|
||||
const char* gFuncNames[BT_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
unsigned long long int gStartTimes[BT_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
|
||||
|
||||
void MyDummyEnterProfileZoneFunc(const char* msg)
|
||||
{
|
||||
@@ -322,8 +324,11 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
{
|
||||
if (gProfileDisabled)
|
||||
return;
|
||||
int threadId = btGetCurrentThreadIndex();
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId]>=MAX_NESTING)
|
||||
{
|
||||
btAssert(0);
|
||||
@@ -336,14 +341,18 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
gStartTimes[threadId][gStackDepths[threadId]]=1+gStartTimes[threadId][gStackDepths[threadId]-1];
|
||||
}
|
||||
gStackDepths[threadId]++;
|
||||
#endif
|
||||
|
||||
}
|
||||
void MyLeaveProfileZoneFunc()
|
||||
{
|
||||
if (gProfileDisabled)
|
||||
return;
|
||||
|
||||
int threadId = btGetCurrentThreadIndex();
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId]<=0)
|
||||
{
|
||||
return;
|
||||
@@ -356,6 +365,7 @@ void MyLeaveProfileZoneFunc()
|
||||
|
||||
unsigned long long int endTime = clk.getTimeNanoseconds();
|
||||
gTimings[threadId].addTiming(name,threadId,startTime,endTime);
|
||||
#endif //BT_NO_PROFILE
|
||||
}
|
||||
|
||||
|
||||
@@ -455,6 +465,7 @@ void MyKeyboardCallback(int key, int state)
|
||||
|
||||
if (key=='p')
|
||||
{
|
||||
#ifndef BT_NO_PROFILE
|
||||
if (state)
|
||||
{
|
||||
m_firstTiming = true;
|
||||
@@ -479,7 +490,7 @@ void MyKeyboardCallback(int key, int state)
|
||||
gTimingFile = fopen(fileName,"w");
|
||||
fprintf(gTimingFile,"{\"traceEvents\":[\n");
|
||||
//dump the content to file
|
||||
for (int i=0;i<BT_MAX_THREAD_COUNT;i++)
|
||||
for (int i=0;i<BT_QUICKPROF_MAX_THREAD_COUNT;i++)
|
||||
{
|
||||
if (gTimings[i].m_numTimings)
|
||||
{
|
||||
@@ -492,6 +503,7 @@ void MyKeyboardCallback(int key, int state)
|
||||
gTimingFile = 0;
|
||||
|
||||
}
|
||||
#endif //BT_NO_PROFILE
|
||||
}
|
||||
|
||||
#ifndef NO_OPENGL3
|
||||
|
||||
@@ -272,10 +272,10 @@ struct MotionThreadLocalStorage
|
||||
int threadId;
|
||||
};
|
||||
|
||||
int skip = 0;
|
||||
int skip1 = 0;
|
||||
|
||||
float clampedDeltaTime = 0.2;
|
||||
|
||||
|
||||
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
{
|
||||
printf("MotionThreadFunc thread started\n");
|
||||
@@ -299,24 +299,19 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
do
|
||||
{
|
||||
BT_PROFILE("loop");
|
||||
deltaTimeInSeconds+= double(clock.getTimeMicroseconds())/1000000.;
|
||||
|
||||
{
|
||||
BT_PROFILE("Sleep(0)");
|
||||
b3Clock::usleep(0);
|
||||
}
|
||||
double dt = double(clock.getTimeMicroseconds())/1000000.;
|
||||
|
||||
deltaTimeInSeconds+= dt;
|
||||
|
||||
clock.reset();
|
||||
|
||||
if (deltaTimeInSeconds<(1./5000.))
|
||||
|
||||
{
|
||||
|
||||
skip++;
|
||||
skip1++;
|
||||
//if (skip1>105)
|
||||
if (skip1>5)
|
||||
{
|
||||
BT_PROFILE("b3Clock::usleep(250)");
|
||||
b3Clock::usleep(250);
|
||||
skip1 = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
skip1=0;
|
||||
|
||||
//process special controller commands, such as
|
||||
//VR controller button press/release and controller motion
|
||||
@@ -450,9 +445,6 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
}
|
||||
|
||||
|
||||
printf("finished, #skip = %d, skip1 = %d\n",skip,skip1);
|
||||
skip=0;
|
||||
skip1=0;
|
||||
//do nothing
|
||||
|
||||
}
|
||||
|
||||
@@ -187,12 +187,16 @@ double b3Clock::getTimeInSeconds()
|
||||
void b3Clock::usleep(int microSeconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int millis = microSeconds/1000;
|
||||
if (millis < 1)
|
||||
if (microSeconds==0)
|
||||
{
|
||||
millis = 1;
|
||||
Sleep(0);
|
||||
} else
|
||||
{
|
||||
int millis = microSeconds/1000;
|
||||
if (millis<1)
|
||||
millis=1;
|
||||
Sleep(millis);
|
||||
}
|
||||
Sleep(millis);
|
||||
#else
|
||||
|
||||
::usleep(microSeconds);
|
||||
|
||||
Reference in New Issue
Block a user