📄 rosperf.c
字号:
if (4 == VersionInfo.dwMajorVersion &&
0 == lstrcmpiW(VersionInfo.szCSDVersion, L"Service Pack 6"))
{
/* Test for SP6 versus SP6a. */
Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
0, KEY_QUERY_VALUE, &hKey);
if (ERROR_SUCCESS == Ret)
{
wprintf(L"Service Pack 6a (Build %d)\n", VersionInfo.dwBuildNumber & 0xFFFF);
}
else /* Windows NT 4.0 prior to SP6a */
{
wprintf(L"%s (Build %d)\n",
VersionInfo.szCSDVersion,
VersionInfo.dwBuildNumber & 0xFFFF);
}
RegCloseKey(hKey);
}
else /* not Windows NT 4.0 */
{
wprintf(L"%s (Build %d)\n",
VersionInfo.szCSDVersion,
VersionInfo.dwBuildNumber & 0xFFFF);
}
break;
/* Test for the Windows Me/98/95. A bit silly since we're using Unicode... */
case VER_PLATFORM_WIN32_WINDOWS:
if (4 == VersionInfo.dwMajorVersion && 0 == VersionInfo.dwMinorVersion)
{
wprintf(L"Running on Microsoft Windows 95 ");
if (L'C' == VersionInfo.szCSDVersion[1] || L'B' == VersionInfo.szCSDVersion[1])
{
wprintf(L"OSR2");
}
}
else if (4 == VersionInfo.dwMajorVersion && 10 == VersionInfo.dwMinorVersion)
{
wprintf(L"Running on Microsoft Windows 98 ");
if (L'A' == VersionInfo.szCSDVersion[1])
{
wprintf(L"SE");
}
}
else if (4 == VersionInfo.dwMajorVersion && 90 == VersionInfo.dwMinorVersion)
{
wprintf(L"Running on Microsoft Windows Millennium Edition");
}
wprintf(L"\n");
break;
case VER_PLATFORM_WIN32s: /* Even silier... */
wprintf(L"Running on Microsoft Win32s\n");
break;
}
}
static void
PrintAppVersion(void)
{
wprintf(L"RosPerf %S (Build %S)\n", KERNEL_VERSION_STR, KERNEL_VERSION_BUILD_STR);
}
static void
PrintDisplayInfo(void)
{
HDC Dc;
Dc = GetDC(NULL);
if (NULL == Dc)
{
return;
}
wprintf(L"Display settings %d * %d * %d\n", GetDeviceCaps(Dc, HORZRES),
GetDeviceCaps(Dc, VERTRES), GetDeviceCaps(Dc, BITSPIXEL) * GetDeviceCaps(Dc, PLANES));
ReleaseDC(NULL, Dc);
}
static void
PrintStartupInfo(void)
{
PrintAppVersion();
PrintOSVersion();
PrintDisplayInfo();
}
static LRESULT CALLBACK
MainWndProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT Ps;
HDC Dc;
LRESULT Result;
switch (Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
Result = 0;
break;
case WM_PAINT:
Dc = BeginPaint(Wnd, &Ps);
EndPaint (Wnd, &Ps);
Result = 0;
break;
default:
Result = DefWindowProcW(Wnd, Msg, wParam, lParam);
break;
}
return Result;
}
static LRESULT CALLBACK
LabelWndProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT Ps;
HDC Dc;
RECT ClientRect, WindowRect;
TEXTMETRICW Tm;
LRESULT Result;
WCHAR Title[80];
switch (Msg)
{
case WM_CREATE:
/* Make text fit */
Dc = GetDC(Wnd);
if (NULL != Dc && GetClientRect(Wnd, &ClientRect) && GetWindowRect(Wnd, &WindowRect)
&& GetTextMetricsW(Dc, &Tm))
{
if (Tm.tmHeight != ClientRect.bottom)
{
SetWindowPos(Wnd, NULL, 0, 0, WindowRect.right - WindowRect.left,
(WindowRect.bottom - WindowRect.top) + (Tm.tmHeight - ClientRect.bottom),
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}
}
if (NULL != Dc)
{
ReleaseDC(Wnd, Dc);
}
Result = DefWindowProcW(Wnd, Msg, wParam, lParam);
break;
case WM_PAINT:
Dc = BeginPaint(Wnd, &Ps);
GetWindowTextW(Wnd, Title, sizeof(Title) / sizeof(Title[0]));
TextOutW(Dc, 0, 0, Title, wcslen(Title));
EndPaint (Wnd, &Ps);
Result = 0;
break;
default:
Result = DefWindowProcW(Wnd, Msg, wParam, lParam);
break;
}
return Result;
}
static HWND
CreatePerfWindows(HINSTANCE hInstance, PPERF_INFO PerfInfo)
{
WNDCLASSW wc;
HWND MainWnd;
wc.lpszClassName = L"RosPerfMain";
wc.lpfnWndProc = MainWndProc;
wc.style = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, (LPCWSTR) IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(PerfInfo->BackgroundColor);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (RegisterClassW(&wc) == 0)
{
fwprintf(stderr, L"Failed to register RosPerfMain (last error %d)\n",
GetLastError());
return NULL;
}
wc.lpszClassName = L"RosPerfLabel";
wc.lpfnWndProc = LabelWndProc;
wc.style = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, (LPCWSTR) IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (RegisterClassW(&wc) == 0)
{
fwprintf(stderr, L"Failed to register RosPerfLabel (last error %d)\n",
GetLastError());
return NULL;
}
MainWnd = CreateWindowW(L"RosPerfMain",
L"ReactOS performance test",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,
0,
MAINWND_WIDTH,
MAINWND_HEIGHT,
NULL,
NULL,
hInstance,
NULL);
if (NULL == MainWnd)
{
fwprintf(stderr, L"Failed to create main window (last error %d)\n",
GetLastError());
return NULL;
}
LabelWnd = CreateWindowW(L"RosPerfLabel",
L"",
WS_POPUP | WS_THICKFRAME | WS_VISIBLE,
0,
MAINWND_HEIGHT + 10,
MAINWND_WIDTH,
20,
MainWnd,
NULL,
hInstance,
NULL);
if (NULL == LabelWnd)
{
fwprintf(stderr, L"Failed to create label window (last error 0x%lX)\n",
GetLastError());
return NULL;
}
SetActiveWindow(MainWnd);
return MainWnd;
}
static BOOL
ProcessCommandLine(PPERF_INFO PerfInfo, unsigned *TestCount, PTEST *Tests)
{
int ArgC, Arg;
LPWSTR *ArgV;
LPWSTR EndPtr;
PTEST AllTests;
BOOL *DoTest;
BOOL DoAll;
unsigned AllTestCount, i, j;
ArgV = CommandLineToArgvW(GetCommandLineW(), &ArgC);
if (NULL == ArgV)
{
fwprintf(stderr, L"CommandLineToArgvW failed\n");
return FALSE;
}
GetTests(&AllTestCount, &AllTests);
DoTest = malloc(AllTestCount * sizeof(BOOL));
if (NULL == DoTest)
{
fwprintf(stderr, L"Out of memory\n");
return FALSE;
}
DoAll = TRUE;
for (Arg = 1; Arg < ArgC; Arg++)
{
if (L'/' == ArgV[Arg][0] || L'-' == ArgV[Arg][0])
{
if (0 == _wcsicmp(ArgV[Arg] + 1, L"repeat"))
{
if (ArgC <= Arg + 1)
{
fwprintf(stderr, L"%s needs a repeat count\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
Arg++;
PerfInfo->Repeats = wcstoul(ArgV[Arg], &EndPtr, 0);
if (L'\0' != *EndPtr || (long) PerfInfo->Repeats <= 0 || ULONG_MAX == PerfInfo->Repeats)
{
fwprintf(stderr, L"Invalid repeat count %s\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
}
else if (0 == _wcsicmp(ArgV[Arg] + 1, L"seconds"))
{
if (ArgC <= Arg + 1)
{
fwprintf(stderr, L"%s needs a number of seconds\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
Arg++;
PerfInfo->Seconds = wcstoul(ArgV[Arg], &EndPtr, 0);
if (L'\0' != *EndPtr || (long) PerfInfo->Seconds < 0 || ULONG_MAX == PerfInfo->Seconds)
{
fwprintf(stderr, L"Invalid duration %s\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
}
else
{
fwprintf(stderr, L"Unrecognized option %s\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
}
else
{
if (DoAll)
{
for (i = 0; i < AllTestCount; i++)
{
DoTest[i] = FALSE;
}
DoAll = FALSE;
}
for (i = 0; i < AllTestCount; i++)
{
if (0 == _wcsicmp(ArgV[Arg], AllTests[i].Option))
{
DoTest[i] = TRUE;
break;
}
}
if (AllTestCount <= i)
{
fwprintf(stderr, L"Unrecognized test %s\n", ArgV[Arg]);
free(DoTest);
GlobalFree(ArgV);
return FALSE;
}
}
}
GlobalFree(ArgV);
if (DoAll)
{
for (i = 0; i < AllTestCount; i++)
{
DoTest[i] = TRUE;
}
}
*TestCount = 0;
for (i = 0; i < AllTestCount; i++)
{
if (DoTest[i])
{
(*TestCount)++;
}
}
*Tests = malloc(*TestCount * sizeof(TEST));
if (NULL == *Tests)
{
fwprintf(stderr, L"Out of memory\n");
free(DoTest);
return FALSE;
}
j = 0;
for (i = 0; i < AllTestCount; i++)
{
if (DoTest[i])
{
(*Tests)[j] = AllTests[i];
j++;
}
}
free(DoTest);
return TRUE;
}
int WINAPI
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
PTEST Tests;
unsigned TestCount;
unsigned CurrentTest;
RECT Rect;
PERF_INFO PerfInfo;
PrintStartupInfo();
PerfInfo.Seconds = 15;
PerfInfo.Repeats = 4;
PerfInfo.ForegroundColor = RGB(0, 0, 0);
PerfInfo.BackgroundColor = RGB(255, 255, 255);
if (! ProcessCommandLine(&PerfInfo, &TestCount, &Tests))
{
exit(1);
}
PerfInfo.Wnd = CreatePerfWindows(hInstance, &PerfInfo);
if (NULL == PerfInfo.Wnd)
{
exit(1);
}
GetClientRect(PerfInfo.Wnd, &Rect);
PerfInfo.WndWidth = Rect.right - Rect.left;
PerfInfo.WndHeight = Rect.bottom - Rect.top;
PerfInfo.ForegroundDc = GetDC(PerfInfo.Wnd);
PerfInfo.BackgroundDc = GetDC(PerfInfo.Wnd);
if (NULL == PerfInfo.ForegroundDc || NULL == PerfInfo.BackgroundDc)
{
fwprintf(stderr, L"Failed to create device contexts (last error %d)\n",
GetLastError());
exit(1);
}
SelectObject(PerfInfo.ForegroundDc, CreateSolidBrush(PerfInfo.ForegroundColor));
SelectObject(PerfInfo.ForegroundDc, CreatePen(PS_SOLID, 0, PerfInfo.ForegroundColor));
SelectObject(PerfInfo.BackgroundDc, CreateSolidBrush(PerfInfo.BackgroundColor));
SelectObject(PerfInfo.BackgroundDc, CreatePen(PS_SOLID, 0, PerfInfo.BackgroundColor));
ProcessMessages();
/* Move cursor out of the way */
GetWindowRect(LabelWnd, &Rect);
SetCursorPos(Rect.right, Rect.bottom);
for (CurrentTest = 0; CurrentTest < TestCount; CurrentTest++)
{
wprintf(L"\n");
ProcessTest(Tests + CurrentTest, &PerfInfo);
}
GlobalFree(Tests);
return 0;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -