Minor profiler update

This commit is contained in:
harry 2023-05-09 22:53:40 -04:00
parent d0d822447d
commit a9f4176f2b
2 changed files with 64 additions and 3 deletions

View File

@ -198,6 +198,8 @@ profilerFuncMap::profilerFuncMap(void)
{
//printf("profilerFuncMap Constructor: %p\n", this);
pMgr.addThreadProfiler(this);
_map_it = _map.begin();
}
//-------------------------------------------------------------------------
profilerFuncMap::~profilerFuncMap(void)
@ -205,11 +207,15 @@ profilerFuncMap::~profilerFuncMap(void)
//printf("profilerFuncMap Destructor: %p\n", 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)
@ -228,6 +234,7 @@ funcProfileRecord *profilerFuncMap::findRecord(const char *fileNameStringLiteral
const char *commentStringLiteral,
bool create)
{
autoScopedLock aLock(_mapMtx);
char lineString[64];
funcProfileRecord *rec = nullptr;
@ -255,8 +262,45 @@ funcProfileRecord *profilerFuncMap::findRecord(const char *fileNameStringLiteral
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* profilerManager::instance = nullptr;
profilerManager* profilerManager::getInstance(void)
{
return instance;
}
//-------------------------------------------------------------------------
profilerManager::profilerManager(void)
{
calibrateTSC();
@ -266,6 +310,11 @@ profilerManager::profilerManager(void)
{
pLog = stdout;
}
if (instance == nullptr)
{
instance = this;
}
}
profilerManager::~profilerManager(void)
@ -280,6 +329,10 @@ profilerManager::~profilerManager(void)
{
fclose(pLog); pLog = nullptr;
}
if (instance == this)
{
instance = nullptr;
}
}
int profilerManager::addThreadProfiler( profilerFuncMap *m )

View File

@ -273,10 +273,15 @@ namespace FCEU
const char *commentStringLiteral,
bool create = false);
funcProfileRecord *iterateBegin(void);
funcProfileRecord *iterateNext(void);
void pushStack(funcProfileRecord *rec);
void popStack(funcProfileRecord *rec);
private:
mutex _mapMtx;
std::map<std::string, funcProfileRecord*> _map;
std::map<std::string, funcProfileRecord*>::iterator _map_it;
std::vector <funcProfileRecord*> stack;
};
@ -291,10 +296,13 @@ namespace FCEU
int removeThreadProfiler( profilerFuncMap *m, bool shouldDestroy = false );
static FILE *pLog;
static profilerManager *getInstance();
private:
mutex threadListMtx;
std::list <profilerFuncMap*> threadList;
static profilerManager *instance;
};
}