add nanosecond resolution for Mac OSX clock / about://tracing timings

This commit is contained in:
Erwin Coumans
2016-12-23 18:18:35 -08:00
parent 4c06fd27b3
commit 0917310521
2 changed files with 94 additions and 10 deletions

View File

@@ -188,13 +188,62 @@ struct btTimings
m_firstTiming = false;
unsigned long long int startTimeDiv1000 = startTime/1000;
unsigned long long int endTimeDiv1000 = endTime/1000;
unsigned long long int startTimeDiv1000 = startTime/1000;
unsigned long long int endTimeDiv1000 = endTime/1000;
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 " ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
threadId, startTimeDiv1000,name);
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 " ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
threadId, endTimeDiv1000,name);
#if 0
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".123 ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
threadId, startTimeDiv1000, name);
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".234 ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
threadId, endTimeDiv1000,name);
#else
unsigned int startTimeRem1000 = startTime%1000;
unsigned int endTimeRem1000 = endTime%1000;
char startTimeRem1000Str[16];
char endTimeRem1000Str[16];
if (startTimeRem1000<10)
{
sprintf(startTimeRem1000Str,"00%d",startTimeRem1000);
}
else
{
if (startTimeRem1000<100)
{
sprintf(startTimeRem1000Str,"0%d",startTimeRem1000);
} else
{
sprintf(startTimeRem1000Str,"%d",startTimeRem1000);
}
}
if (endTimeRem1000<10)
{
sprintf(endTimeRem1000Str,"00%d",endTimeRem1000);
}
else
{
if (endTimeRem1000<100)
{
sprintf(endTimeRem1000Str,"0%d",endTimeRem1000);
} else
{
sprintf(endTimeRem1000Str,"%d",endTimeRem1000);
}
}
char newname[1024];
static int counter2=0;
sprintf(newname,"%s%d",name,counter2++);
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
threadId, startTimeDiv1000,startTimeRem1000Str, newname);
fprintf(gTimingFile,"{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
threadId, endTimeDiv1000,endTimeRem1000Str,newname);
#endif
}
m_numTimings = 0;
@@ -400,7 +449,7 @@ void MyKeyboardCallback(int key, int state)
btSetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
char fileName[1024];
static int fileCounter = 0;
sprintf(fileName,"d:/timings_%d.json",fileCounter++);
sprintf(fileName,"timings_%d.json",fileCounter++);
gTimingFile = fopen(fileName,"w");
fprintf(gTimingFile,"{\"traceEvents\":[\n");
//dump the content to file