Improved profiler support for threads working on the same task

This commit is contained in:
palana 2013-09-06 16:45:56 +02:00
parent 7806d11b7e
commit aeeb5f9227
2 changed files with 23 additions and 8 deletions

View File

@ -50,6 +50,7 @@ struct BASE_EXPORT ProfileNodeInfo
CTSTR lpName; CTSTR lpName;
DWORD numCalls; DWORD numCalls;
DWORD numParallelCalls;
DWORD avgTimeElapsed; DWORD avgTimeElapsed;
DWORD avgCpuTime; DWORD avgCpuTime;
double avgPercentage; double avgPercentage;
@ -70,8 +71,8 @@ struct BASE_EXPORT ProfileNodeInfo
void calculateProfileData(int rootCallCount) void calculateProfileData(int rootCallCount)
{ {
avgTimeElapsed = (DWORD)(totalTimeElapsed/(QWORD)rootCallCount); avgTimeElapsed = (DWORD)(totalTimeElapsed/(QWORD)numCalls);
avgCpuTime = (DWORD)(cpuTimeElapsed/(QWORD)rootCallCount); avgCpuTime = (DWORD)(cpuTimeElapsed/(QWORD)numCalls);
if(parent) avgPercentage = (double(avgTimeElapsed)/double(parent->avgTimeElapsed))*parent->avgPercentage; if(parent) avgPercentage = (double(avgTimeElapsed)/double(parent->avgTimeElapsed))*parent->avgPercentage;
@ -97,7 +98,10 @@ struct BASE_EXPORT ProfileNodeInfo
void dumpData(int rootCallCount, int indent=0) void dumpData(int rootCallCount, int indent=0)
{ {
if(indent == 0) if(indent == 0)
{
rootCallCount = (int)floor(rootCallCount/(double)numParallelCalls+0.5);
calculateProfileData(rootCallCount); calculateProfileData(rootCallCount);
}
String indentStr; String indentStr;
for(int i=0; i<indent; i++) for(int i=0; i<indent; i++)
@ -276,6 +280,8 @@ ProfilerNode::ProfilerNode(CTSTR lpName, bool bSingularize)
MonitorThread(OSGetCurrentThread()); MonitorThread(OSGetCurrentThread());
parallelCalls = 1;
exit: exit:
OSLeaveMutex(hProfilerMutex); OSLeaveMutex(hProfilerMutex);
} }
@ -298,6 +304,7 @@ ProfilerNode::~ProfilerNode()
info->cpuTimeElapsed += cpuTime; info->cpuTimeElapsed += cpuTime;
info->lastCpuTimeElapsed = cpuTime; info->lastCpuTimeElapsed = cpuTime;
} }
info->numParallelCalls = parallelCalls;
} }
if(!bSingularNode) if(!bSingularNode)
@ -313,3 +320,8 @@ void ProfilerNode::MonitorThread(HANDLE thread_)
thread = thread_; thread = thread_;
cpuStartTime = OSGetThreadTime(thread); cpuStartTime = OSGetThreadTime(thread);
} }
void ProfilerNode::SetParallelCallCount(DWORD num)
{
parallelCalls = num;
}

View File

@ -28,6 +28,7 @@ class BASE_EXPORT ProfilerNode
CTSTR lpName; CTSTR lpName;
QWORD startTime, QWORD startTime,
cpuStartTime; cpuStartTime;
DWORD parallelCalls;
HANDLE thread; HANDLE thread;
ProfilerNode *parent; ProfilerNode *parent;
bool bSingularNode; bool bSingularNode;
@ -37,6 +38,7 @@ public:
ProfilerNode(CTSTR name, bool bSingularize=false); ProfilerNode(CTSTR name, bool bSingularize=false);
~ProfilerNode(); ~ProfilerNode();
void MonitorThread(HANDLE thread); void MonitorThread(HANDLE thread);
void SetParallelCallCount(DWORD num);
}; };
//BASE_EXPORT extern ProfilerNode *__curProfilerNode; //BASE_EXPORT extern ProfilerNode *__curProfilerNode;
@ -48,6 +50,7 @@ BASE_EXPORT extern BOOL bProfilingEnabled;
#define profileSingularSegment(name) ProfilerNode _curProfiler(TEXT(name), true); #define profileSingularSegment(name) ProfilerNode _curProfiler(TEXT(name), true);
#define profileSingularIn(name) {ProfilerNode _curProfiler(TEXT(name), true); #define profileSingularIn(name) {ProfilerNode _curProfiler(TEXT(name), true);
#define profileSegment(name) ProfilerNode _curProfiler(TEXT(name)); #define profileSegment(name) ProfilerNode _curProfiler(TEXT(name));
#define profileParallelSegment(name, num) ProfilerNode _curProfiler(TEXT(name)); _curProfiler.SetParallelCallCount(num);
#define profileIn(name) {ProfilerNode _curProfiler(TEXT(name)); #define profileIn(name) {ProfilerNode _curProfiler(TEXT(name));
#define profileOut } #define profileOut }
#else #else