C++ 获取进程中的所有线程堆栈并找到模块,SymInitialize花费了太多时间
平台:windows 现在,我需要获取进程中的所有线程,并根据调用堆栈的模块对线程进行粗略分类 在Windows上,我已经可以使用StackWalk()获取线程堆栈,但是在调用之前,我需要先调用symcinitialize(),否则捕获的堆栈没有模块信息 但是,我目前的问题是,在Windows中,SymInitialize过程相对耗时,需要数百毫秒(系统中有十多个动态库模块)。我的目的是找到堆栈中调用所在的模块。它不需要精确到函数,所以我现在想知道是否有更快的方法 所以我的问题是: 有什么方法可以减少SymInitialize的电流消耗吗 或者有没有其他更快的方法让模块找到堆栈调用的位置 当前代码的一部分:C++ 获取进程中的所有线程堆栈并找到模块,SymInitialize花费了太多时间,c++,windows,C++,Windows,平台:windows 现在,我需要获取进程中的所有线程,并根据调用堆栈的模块对线程进行粗略分类 在Windows上,我已经可以使用StackWalk()获取线程堆栈,但是在调用之前,我需要先调用symcinitialize(),否则捕获的堆栈没有模块信息 但是,我目前的问题是,在Windows中,SymInitialize过程相对耗时,需要数百毫秒(系统中有十多个动态库模块)。我的目的是找到堆栈中调用所在的模块。它不需要精确到函数,所以我现在想知道是否有更快的方法 所以我的问题是: 有什么方法可
std::vector<std::string> LibMonitorThread::getThreadStack(uint64_t thread_id, int64_t stack_len, std::unordered_set<std::string> queryModuleList) {
DWORD current_thread_id = GetCurrentThreadId();
if (current_thread_id == (DWORD)thread_id) {
std::vector<std::string> return_stacks;
return return_stacks;
}
HANDLE process = GetCurrentProcess();
auto initRes = SymInitialize(process, NULL, TRUE);
HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, 0, (DWORD)thread_id);
DWORD res = SuspendThread(hThread); // 4294967295 is failed
CONTEXT context = {};
context.ContextFlags = CONTEXT_FULL;
GetThreadContext(hThread, &context);
std::vector<std::string> return_stacks = LibMonitorThread::getThreadStackByHandle(hThread, stack_len, queryModuleList, context); // StackWalk in this function
ResumeThread(hThread);
CloseHandle(hThread);
SymCleanup(process);
CloseHandle(process);
return return_stacks;
}
}
std::vector LibMonitorThread::getThreadStack(uint64线程id、int64线程堆栈、std::无序集查询模块列表){
DWORD current_thread_id=GetCurrentThreadId();
if(当前线程id==(DWORD)线程id){
std::向量返回_堆栈;
返回栈;
}
HANDLE process=GetCurrentProcess();
auto initRes=symcinitialize(进程,NULL,TRUE);
HANDLE hThread=OpenThread(THREAD\u ALL\u ACCESS,0,(DWORD)THREAD\u id);
DWORD res=SuspendThread(hThread);//4294967295失败
上下文={};
context.ContextFlags=context_FULL;
GetThreadContext(hThread,&context);
std::vector return_stacks=LibMonitorThread::getThreadStackByHandle(hThread,stack_len,queryModuleList,context);//此函数中的StackWalk
恢复线程(hThread);
CloseHandle(hThread);
符号清理(过程);
闭柄(过程);
返回栈;
}
}