Minor profiler update
This commit is contained in:
parent
d0d822447d
commit
a9f4176f2b
|
@ -198,6 +198,8 @@ profilerFuncMap::profilerFuncMap(void)
|
||||||
{
|
{
|
||||||
//printf("profilerFuncMap Constructor: %p\n", this);
|
//printf("profilerFuncMap Constructor: %p\n", this);
|
||||||
pMgr.addThreadProfiler(this);
|
pMgr.addThreadProfiler(this);
|
||||||
|
|
||||||
|
_map_it = _map.begin();
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
profilerFuncMap::~profilerFuncMap(void)
|
profilerFuncMap::~profilerFuncMap(void)
|
||||||
|
@ -205,11 +207,15 @@ profilerFuncMap::~profilerFuncMap(void)
|
||||||
//printf("profilerFuncMap Destructor: %p\n", this);
|
//printf("profilerFuncMap Destructor: %p\n", this);
|
||||||
pMgr.removeThreadProfiler(this);
|
pMgr.removeThreadProfiler(this);
|
||||||
|
|
||||||
for (auto it = _map.begin(); it != _map.end(); it++)
|
|
||||||
{
|
{
|
||||||
delete it->second;
|
autoScopedLock aLock(_mapMtx);
|
||||||
|
|
||||||
|
for (auto it = _map.begin(); it != _map.end(); it++)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
_map.clear();
|
||||||
}
|
}
|
||||||
_map.clear();
|
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
void profilerFuncMap::pushStack(funcProfileRecord *rec)
|
void profilerFuncMap::pushStack(funcProfileRecord *rec)
|
||||||
|
@ -228,6 +234,7 @@ funcProfileRecord *profilerFuncMap::findRecord(const char *fileNameStringLiteral
|
||||||
const char *commentStringLiteral,
|
const char *commentStringLiteral,
|
||||||
bool create)
|
bool create)
|
||||||
{
|
{
|
||||||
|
autoScopedLock aLock(_mapMtx);
|
||||||
char lineString[64];
|
char lineString[64];
|
||||||
funcProfileRecord *rec = nullptr;
|
funcProfileRecord *rec = nullptr;
|
||||||
|
|
||||||
|
@ -255,8 +262,45 @@ funcProfileRecord *profilerFuncMap::findRecord(const char *fileNameStringLiteral
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
funcProfileRecord *profilerFuncMap::iterateBegin(void)
|
||||||
|
{
|
||||||
|
autoScopedLock aLock(_mapMtx);
|
||||||
|
funcProfileRecord *rec = nullptr;
|
||||||
|
|
||||||
|
_map_it = _map.begin();
|
||||||
|
|
||||||
|
if (_map_it != _map.end())
|
||||||
|
{
|
||||||
|
rec = _map_it->second;
|
||||||
|
}
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
funcProfileRecord *profilerFuncMap::iterateNext(void)
|
||||||
|
{
|
||||||
|
autoScopedLock aLock(_mapMtx);
|
||||||
|
funcProfileRecord *rec = nullptr;
|
||||||
|
|
||||||
|
if (_map_it != _map.end())
|
||||||
|
{
|
||||||
|
_map_it++;
|
||||||
|
}
|
||||||
|
if (_map_it != _map.end())
|
||||||
|
{
|
||||||
|
rec = _map_it->second;
|
||||||
|
}
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
//----- profilerManager class
|
//----- profilerManager class
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
profilerManager* profilerManager::instance = nullptr;
|
||||||
|
|
||||||
|
profilerManager* profilerManager::getInstance(void)
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
profilerManager::profilerManager(void)
|
profilerManager::profilerManager(void)
|
||||||
{
|
{
|
||||||
calibrateTSC();
|
calibrateTSC();
|
||||||
|
@ -266,6 +310,11 @@ profilerManager::profilerManager(void)
|
||||||
{
|
{
|
||||||
pLog = stdout;
|
pLog = stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instance == nullptr)
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
profilerManager::~profilerManager(void)
|
profilerManager::~profilerManager(void)
|
||||||
|
@ -280,6 +329,10 @@ profilerManager::~profilerManager(void)
|
||||||
{
|
{
|
||||||
fclose(pLog); pLog = nullptr;
|
fclose(pLog); pLog = nullptr;
|
||||||
}
|
}
|
||||||
|
if (instance == this)
|
||||||
|
{
|
||||||
|
instance = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int profilerManager::addThreadProfiler( profilerFuncMap *m )
|
int profilerManager::addThreadProfiler( profilerFuncMap *m )
|
||||||
|
|
|
@ -273,10 +273,15 @@ namespace FCEU
|
||||||
const char *commentStringLiteral,
|
const char *commentStringLiteral,
|
||||||
bool create = false);
|
bool create = false);
|
||||||
|
|
||||||
|
funcProfileRecord *iterateBegin(void);
|
||||||
|
funcProfileRecord *iterateNext(void);
|
||||||
|
|
||||||
void pushStack(funcProfileRecord *rec);
|
void pushStack(funcProfileRecord *rec);
|
||||||
void popStack(funcProfileRecord *rec);
|
void popStack(funcProfileRecord *rec);
|
||||||
private:
|
private:
|
||||||
|
mutex _mapMtx;
|
||||||
std::map<std::string, funcProfileRecord*> _map;
|
std::map<std::string, funcProfileRecord*> _map;
|
||||||
|
std::map<std::string, funcProfileRecord*>::iterator _map_it;
|
||||||
|
|
||||||
std::vector <funcProfileRecord*> stack;
|
std::vector <funcProfileRecord*> stack;
|
||||||
};
|
};
|
||||||
|
@ -291,10 +296,13 @@ namespace FCEU
|
||||||
int removeThreadProfiler( profilerFuncMap *m, bool shouldDestroy = false );
|
int removeThreadProfiler( profilerFuncMap *m, bool shouldDestroy = false );
|
||||||
|
|
||||||
static FILE *pLog;
|
static FILE *pLog;
|
||||||
|
|
||||||
|
static profilerManager *getInstance();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
mutex threadListMtx;
|
mutex threadListMtx;
|
||||||
std::list <profilerFuncMap*> threadList;
|
std::list <profilerFuncMap*> threadList;
|
||||||
|
static profilerManager *instance;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue