フレームワークでラグをプロファイリングしようとしています。私は MinGW を使用しているため、gprof は DLL で動作しません(私にとっては、初期化関数が 1 回だけではなく何千回も実行されるなどのゴミ情報さえ提供してくれました)、gperftools のプロファイラーは Windows ではサポートされていません (まだ)。試してみました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 に変更すると、時折より意味のある値が得られます。
足りないものはありますか?より良いプロファイリングオプションはありますか、それとも根本的に間違っていますか?
ありがとう。