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
|
||||
|
||||
Reference in New Issue
Block a user