我正在尝试在我的框架中分析滞后;因为我使用 MinGW,gprof 不适用于 DLL(对我来说,它甚至给了我垃圾信息,比如运行数千次而不是一次的初始化函数),并且 Windows 不支持 gperftools 的分析器(还),我试过了滚动受 Cygwin 启发的我自己的分析代码:
// 10 may 2015
#include "uipriv_windows.h"
static FILE *fprof = NULL;
static DWORD WINAPI profilerThread(LPVOID th)
{
HANDLE thread = (HANDLE) th;
LARGE_INTEGER counter;
CONTEXT ctxt;
// TODO check for errors
if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) == 0)
complain("error setting thread priority in profilerThread()");
for (;;) {
if (SuspendThread(thread) == (DWORD) (-1))
complain("error suspending thread in profilerThread()");
QueryPerformanceCounter(&counter);
ZeroMemory(&ctxt, sizeof (CONTEXT));
ctxt.ContextFlags = CONTEXT_CONTROL;
if (GetThreadContext(thread, &ctxt) == 0)
complain("error getting thread context in profilerThread()");
fprintf(fprof, "%I64X %I64d\n",
(DWORD64) (ctxt.Eip),
counter.QuadPart);
fflush(fprof);
if (ResumeThread(thread) == (DWORD) (-1))
complain("error resuming thread in profilerThread()");
Sleep(100);
}
return 0;
}
void initprofiler(HANDLE thread)
{
fprof = fopen("profiler.out", "w");
if (fprof == NULL) {
fprintf(stderr, "error opening profiler output file\n");
abort();
}
if (CreateThread(NULL, 0, profilerThread, thread, 0, NULL) == NULL)
complain("error creating profiler thread");
}
但是,此返回的配置文件是无用的:
F77B0C03 3571425665428
F77B0C03 3571426671982
F77B0C03 3571427677119
F77B0C03 3571428683227
F77B0C03 3571429689442
F77B0C03 3571430696476
F77B0C03 3571431702590
F77B0C03 3571432708622
此特定值在 wine 上,它重定向到__kernel_vsyscall+0x3
. 真正的 Windows 有类似的东西7C90E514
,它重定向到ntdll!KeFastSystemCallRet
.
我猜(给定葡萄酒堆栈跟踪)这是因为它卡在GetMessage()
.
如果我将睡眠持续时间从 100 更改为 1,我偶尔会得到更有意义的值。
有什么我想念的吗?有没有更好的分析选项,或者我在某种程度上有这个根本错误?
谢谢。