cache processFromHandle and threadFromHandle (14k events/s -> 20k events/s)

This commit is contained in:
mrexodia 2017-06-30 14:41:13 +02:00
parent 7a4d0b2ff4
commit 7da59f841d
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
1 changed files with 38 additions and 14 deletions

View File

@ -48,6 +48,8 @@ public:
void DebugLoop() void DebugLoop()
{ {
processFromHandleCache.clear();
threadFromHandleCache.clear();
Start(); Start();
} }
@ -775,26 +777,48 @@ private: //functions
} }
} }
std::unordered_map<HANDLE, Thread*> threadFromHandleCache;
Thread* threadFromHandle(HANDLE hThread) Thread* threadFromHandle(HANDLE hThread)
{ {
THREAD_BASIC_INFORMATION tbi; auto found = threadFromHandleCache.find(hThread);
if(!getThreadInfo(hThread, tbi)) if(found != threadFromHandleCache.end())
return nullptr; return found->second;
auto foundP = mProcesses.find(uint32(tbi.ClientId.UniqueProcess)); auto result = [this, hThread]() -> Thread*
if(foundP == mProcesses.end()) {
return nullptr; THREAD_BASIC_INFORMATION tbi;
auto foundT = foundP->second->threads.find(uint32(tbi.ClientId.UniqueThread)); if(!getThreadInfo(hThread, tbi))
if(foundT == foundP->second->threads.end()) return nullptr;
return nullptr; auto foundP = mProcesses.find(uint32(tbi.ClientId.UniqueProcess));
return foundT->second.get(); if(foundP == mProcesses.end())
return nullptr;
auto foundT = foundP->second->threads.find(uint32(tbi.ClientId.UniqueThread));
if(foundT == foundP->second->threads.end())
return nullptr;
return foundT->second.get();
}();
if(result)
threadFromHandleCache[hThread] = result;
return result;
} }
std::unordered_map<HANDLE, Process*> processFromHandleCache;
Process* processFromHandle(HANDLE hProcess) Process* processFromHandle(HANDLE hProcess)
{ {
auto foundP = mProcesses.find(GetProcessId(hProcess)); auto found = processFromHandleCache.find(hProcess);
if(foundP == mProcesses.end()) if(found != processFromHandleCache.end())
return nullptr; return found->second;
return foundP->second.get(); auto result = [this, hProcess]() -> Process*
{
auto foundP = mProcesses.find(GetProcessId(hProcess));
if(foundP == mProcesses.end())
return nullptr;
return foundP->second.get();
}();
if(result)
processFromHandleCache[hProcess] = result;
return result;
} }
static HardwareType hwtypeFromTitan(DWORD type) static HardwareType hwtypeFromTitan(DWORD type)