Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -17,28 +17,26 @@ struct btTiming
|
||||
FILE* gTimingFile = 0;
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif //__STDC_FORMAT_MACROS
|
||||
#endif //__STDC_FORMAT_MACROS
|
||||
|
||||
//see http://stackoverflow.com/questions/18107426/printf-format-for-unsigned-int64-on-windows
|
||||
#ifndef _WIN32
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#define BT_TIMING_CAPACITY 16*65536
|
||||
#define BT_TIMING_CAPACITY 16 * 65536
|
||||
static bool m_firstTiming = true;
|
||||
|
||||
|
||||
struct btTimings
|
||||
{
|
||||
btTimings()
|
||||
:m_numTimings(0),
|
||||
m_activeBuffer(0)
|
||||
: m_numTimings(0),
|
||||
m_activeBuffer(0)
|
||||
{
|
||||
|
||||
}
|
||||
void flush()
|
||||
{
|
||||
for (int i = 0; i<m_numTimings; i++)
|
||||
for (int i = 0; i < m_numTimings; i++)
|
||||
{
|
||||
const char* name = m_timings[m_activeBuffer][i].m_name;
|
||||
int threadId = m_timings[m_activeBuffer][i].m_threadId;
|
||||
@@ -64,8 +62,7 @@ struct btTimings
|
||||
|
||||
#else
|
||||
|
||||
|
||||
if (startTime>endTime)
|
||||
if (startTime > endTime)
|
||||
{
|
||||
endTime = startTime;
|
||||
}
|
||||
@@ -75,13 +72,13 @@ struct btTimings
|
||||
char startTimeRem1000Str[16];
|
||||
char endTimeRem1000Str[16];
|
||||
|
||||
if (startTimeRem1000<10)
|
||||
if (startTimeRem1000 < 10)
|
||||
{
|
||||
sprintf(startTimeRem1000Str, "00%d", startTimeRem1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startTimeRem1000<100)
|
||||
if (startTimeRem1000 < 100)
|
||||
{
|
||||
sprintf(startTimeRem1000Str, "0%d", startTimeRem1000);
|
||||
}
|
||||
@@ -91,13 +88,13 @@ struct btTimings
|
||||
}
|
||||
}
|
||||
|
||||
if (endTimeRem1000<10)
|
||||
if (endTimeRem1000 < 10)
|
||||
{
|
||||
sprintf(endTimeRem1000Str, "00%d", endTimeRem1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endTimeRem1000<100)
|
||||
if (endTimeRem1000 < 100)
|
||||
{
|
||||
sprintf(endTimeRem1000Str, "0%d", endTimeRem1000);
|
||||
}
|
||||
@@ -114,21 +111,19 @@ struct btTimings
|
||||
#ifdef _WIN32
|
||||
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%I64d.%s ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%I64d.%s ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
|
||||
#else
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
m_numTimings = 0;
|
||||
|
||||
}
|
||||
|
||||
void addTiming(const char* name, int threadId, unsigned long long int startTime, unsigned long long int endTime)
|
||||
@@ -151,7 +146,6 @@ struct btTimings
|
||||
m_timings[m_activeBuffer][slot].m_usEndTime = endTime;
|
||||
}
|
||||
|
||||
|
||||
int m_numTimings;
|
||||
int m_activeBuffer;
|
||||
btAlignedObjectArray<btTiming> m_timings[1];
|
||||
@@ -159,18 +153,15 @@ struct btTimings
|
||||
//#ifndef BT_NO_PROFILE
|
||||
btTimings gTimings[BT_QUICKPROF_MAX_THREAD_COUNT];
|
||||
#define MAX_NESTING 1024
|
||||
int gStackDepths[BT_QUICKPROF_MAX_THREAD_COUNT] = { 0 };
|
||||
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;
|
||||
|
||||
|
||||
|
||||
bool gProfileDisabled = true;
|
||||
|
||||
|
||||
void MyDummyEnterProfileZoneFunc(const char* msg)
|
||||
{
|
||||
}
|
||||
@@ -185,7 +176,7 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
return;
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
if (threadId < 0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId] >= MAX_NESTING)
|
||||
@@ -201,7 +192,6 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
}
|
||||
gStackDepths[threadId]++;
|
||||
#endif
|
||||
|
||||
}
|
||||
void MyLeaveProfileZoneFunc()
|
||||
{
|
||||
@@ -209,8 +199,8 @@ void MyLeaveProfileZoneFunc()
|
||||
return;
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
if (threadId < 0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId] <= 0)
|
||||
{
|
||||
@@ -224,56 +214,55 @@ void MyLeaveProfileZoneFunc()
|
||||
|
||||
unsigned long long int endTime = clk.getTimeNanoseconds();
|
||||
gTimings[threadId].addTiming(name, threadId, startTime, endTime);
|
||||
#endif //BT_NO_PROFILE
|
||||
#endif //BT_NO_PROFILE
|
||||
}
|
||||
|
||||
|
||||
void b3ChromeUtilsStartTimings()
|
||||
{
|
||||
m_firstTiming = true;
|
||||
gProfileDisabled = false;//true;
|
||||
b3SetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
m_firstTiming = true;
|
||||
gProfileDisabled = false; //true;
|
||||
b3SetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
}
|
||||
|
||||
void b3ChromeUtilsStopTimingsAndWriteJsonFile(const char* fileNamePrefix)
|
||||
{
|
||||
b3SetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
char fileName[1024];
|
||||
static int fileCounter = 0;
|
||||
sprintf(fileName,"%s_%d.json",fileNamePrefix, fileCounter++);
|
||||
gTimingFile = fopen(fileName,"w");
|
||||
if (gTimingFile)
|
||||
b3SetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
char fileName[1024];
|
||||
static int fileCounter = 0;
|
||||
sprintf(fileName, "%s_%d.json", fileNamePrefix, fileCounter++);
|
||||
gTimingFile = fopen(fileName, "w");
|
||||
if (gTimingFile)
|
||||
{
|
||||
fprintf(gTimingFile, "{\"traceEvents\":[\n");
|
||||
//dump the content to file
|
||||
for (int i = 0; i < BT_QUICKPROF_MAX_THREAD_COUNT; i++)
|
||||
{
|
||||
if (gTimings[i].m_numTimings)
|
||||
{
|
||||
fprintf(gTimingFile,"{\"traceEvents\":[\n");
|
||||
//dump the content to file
|
||||
for (int i=0;i<BT_QUICKPROF_MAX_THREAD_COUNT;i++)
|
||||
{
|
||||
if (gTimings[i].m_numTimings)
|
||||
{
|
||||
printf("Writing %d timings for thread %d\n", gTimings[i].m_numTimings, i);
|
||||
gTimings[i].flush();
|
||||
}
|
||||
}
|
||||
fprintf(gTimingFile,"\n],\n\"displayTimeUnit\": \"ns\"}");
|
||||
fclose(gTimingFile);
|
||||
} else
|
||||
{
|
||||
b3Printf("Error opening file");
|
||||
b3Printf(fileName);
|
||||
printf("Writing %d timings for thread %d\n", gTimings[i].m_numTimings, i);
|
||||
gTimings[i].flush();
|
||||
}
|
||||
gTimingFile = 0;
|
||||
}
|
||||
fprintf(gTimingFile, "\n],\n\"displayTimeUnit\": \"ns\"}");
|
||||
fclose(gTimingFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Printf("Error opening file");
|
||||
b3Printf(fileName);
|
||||
}
|
||||
gTimingFile = 0;
|
||||
}
|
||||
|
||||
|
||||
void b3ChromeUtilsEnableProfiling()
|
||||
{
|
||||
gProfileDisabled = false;
|
||||
|
||||
Reference in New Issue
Block a user