Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234 lines
32 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Wperf.c
  5. Abstract:
  6. Win32 application to display performance statictics.
  7. Author:
  8. Mark Enstrom (marke)
  9. Environment:
  10. Win32
  11. Revision History:
  12. 10-20-91 Initial version
  13. --*/
  14. //
  15. // set variable to define global variables
  16. //
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <errno.h>
  22. #include "wperf.h"
  23. //
  24. // global handles
  25. //
  26. HANDLE hInst;
  27. //
  28. // Selected Display Mode (read from wp2.ini), default set here.
  29. //
  30. DISPLAY_ITEM PerfDataList[SAVE_SUBJECTS];
  31. WINPERF_INFO WinperfInfo;
  32. //
  33. // Window names
  34. //
  35. PUCHAR PerfNames[] = {
  36. "CPU0",
  37. "CPU1",
  38. "CPU2",
  39. "CPU3",
  40. "CPU4",
  41. "CPU5",
  42. "CPU6",
  43. "CPU7",
  44. "CPU8",
  45. "CPU9",
  46. "CPU10",
  47. "CPU11",
  48. "CPU12",
  49. "CPU13",
  50. "CPU14",
  51. "CPU15",
  52. "PAGE FLT",
  53. "PAGES AVAIL",
  54. "CONTEXT SW/S",
  55. "1st TB MISS/S",
  56. "2nd TB MISS/S",
  57. "SYSTEM CALLS/S",
  58. "INTERRUPT/S",
  59. "PAGE POOL",
  60. "NON-PAGE POOL",
  61. "PROCESSES",
  62. "THREADS",
  63. "ALIGN FIXUP",
  64. "EXCEPT DSPTCH",
  65. "FLOAT EMULAT",
  66. "INSTR EMULAT",
  67. "CPU"
  68. };
  69. int
  70. WINAPI
  71. WinMain(
  72. HINSTANCE hInstance,
  73. HINSTANCE hPrevInstance,
  74. LPSTR lpCmdLine,
  75. int nCmdShow
  76. )
  77. /*++
  78. Routine Description:
  79. Windows entry point routine
  80. Arguments:
  81. Return Value:
  82. status of operation
  83. Revision History:
  84. 03-21-91 Initial code
  85. --*/
  86. {
  87. MSG msg;
  88. HBRUSH BackBrush;
  89. //
  90. // check for other instances of this program
  91. //
  92. BackBrush = CreateSolidBrush(RGB(192,192,192));
  93. if (!InitApplication(hInstance,BackBrush)) {
  94. //DbgPrint("Init Application fails\n");
  95. return (FALSE);
  96. }
  97. //
  98. // Perform initializations that apply to a specific instance
  99. //
  100. if (!InitInstance(hInstance, nCmdShow)){
  101. return (FALSE);
  102. }
  103. //
  104. // Acquire and dispatch messages until a WM_QUIT message is received.
  105. //
  106. while (GetMessage(&msg, // message structure
  107. NULL, // handle of window receiving the message
  108. 0, // lowest message to examine
  109. 0)) // highest message to examine
  110. {
  111. TranslateMessage(&msg); // Translates virtual key codes
  112. DispatchMessage(&msg); // Dispatches message to window
  113. }
  114. DeleteObject(BackBrush);
  115. return (int)(msg.wParam); // Returns the value from PostQuitMessage
  116. }
  117. BOOL
  118. InitApplication(
  119. HANDLE hInstance,
  120. HBRUSH hBackground
  121. )
  122. /*++
  123. Routine Description:
  124. Initializes window data and registers window class.
  125. Arguments:
  126. hInstance - current instance
  127. hBackground - background fill brush
  128. Return Value:
  129. status of operation
  130. Revision History:
  131. 02-17-91 Initial code
  132. --*/
  133. {
  134. WNDCLASS wc;
  135. BOOL ReturnStatus;
  136. //
  137. // Fill in window class structure with parameters that describe the
  138. // main window.
  139. //
  140. wc.style = CS_DBLCLKS; // Class style(s).
  141. wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
  142. // windows of this class.
  143. wc.cbClsExtra = 0; // No per-class extra data.
  144. wc.cbWndExtra = 0; // No per-window extra data.
  145. wc.hInstance = hInstance; // Application that owns the class.
  146. wc.hIcon = LoadIcon(hInstance, //
  147. MAKEINTRESOURCE(WINPERF_ICON)); // Load Winperf icon
  148. wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load default cursor
  149. wc.hbrBackground = hBackground;; // Use background passed to routine
  150. wc.lpszMenuName = "winperfMenu"; // Name of menu resource in .RC file.
  151. wc.lpszClassName = "WinPerfClass"; // Name used in call to CreateWindow.
  152. ReturnStatus = RegisterClass(&wc);
  153. return(ReturnStatus);
  154. }
  155. BOOL
  156. InitInstance(
  157. HANDLE hInstance,
  158. int nCmdShow
  159. )
  160. /*++
  161. Routine Description:
  162. Save instance handle and create main window. This function performs
  163. initialization tasks that cannot be shared by multiple instances.
  164. Arguments:
  165. hInstance - Current instance identifier.
  166. nCmdShow - Param for first ShowWindow() call.
  167. Return Value:
  168. status of operation
  169. Revision History:
  170. 02-17-91 Initial code
  171. --*/
  172. {
  173. DWORD WindowStyle;
  174. //
  175. // Save the instance handle in a static variable, which will be used in
  176. // many subsequent calls from this application to Windows.
  177. //
  178. hInst = hInstance;
  179. //
  180. // init the window position and size to be in the upper corner of
  181. // the screen, 200x100
  182. //
  183. // What I want here is a way to get the WINDOW dimensions
  184. //
  185. WinperfInfo.WindowPositionX = 640 - 200;
  186. WinperfInfo.WindowPositionY = 0;
  187. WinperfInfo.WindowSizeX = 200;
  188. WinperfInfo.WindowSizeY = 100;
  189. WinperfInfo.CpuStyle = CPU_STYLE_LINE;
  190. //
  191. // read profile data from .ini file
  192. //
  193. InitProfileData(&WinperfInfo);
  194. WinperfInfo.hMenu = LoadMenu(hInstance,"winperfMenu");
  195. //
  196. // Create a main window for this application instance.
  197. //
  198. WinperfInfo.hWndMain = CreateWindow(
  199. "WinPerfClass", // See RegisterClass() call.
  200. "Perf Meter", // Text for window title bar.
  201. WS_OVERLAPPEDWINDOW, // window style
  202. WinperfInfo.WindowPositionX, // Default horizontal position.
  203. WinperfInfo.WindowPositionY, // Default vertical position.
  204. WinperfInfo.WindowSizeX, // Default width.
  205. WinperfInfo.WindowSizeY, // Default height.
  206. NULL, // Overlapped windows have no parent.
  207. NULL, // Use the window class menu.
  208. hInstance, // This instance owns this window.
  209. NULL // Pointer not needed.
  210. );
  211. //
  212. // Decide on whether or not to display the menu and caption
  213. // based on the window class read from the .ini file
  214. //
  215. if (WinperfInfo.DisplayMode==STYLE_ENABLE_MENU) {
  216. WinperfInfo.DisplayMenu = TRUE;
  217. } else {
  218. WinperfInfo.DisplayMenu = FALSE;
  219. WindowStyle = GetWindowLong(WinperfInfo.hWndMain,GWL_STYLE);
  220. WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU;
  221. SetWindowPos(WinperfInfo.hWndMain, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  222. SetWindowLong(WinperfInfo.hWndMain,GWL_STYLE,WindowStyle);
  223. SetMenu(WinperfInfo.hWndMain,NULL);
  224. }
  225. //
  226. // If window could not be created, return "failure"
  227. //
  228. if (!WinperfInfo.hWndMain) {
  229. return (FALSE);
  230. }
  231. //
  232. // Make the window visible; update its client area; and return "success"
  233. //
  234. SetFocus(WinperfInfo.hWndMain);
  235. ShowWindow(WinperfInfo.hWndMain, SW_SHOWNORMAL);
  236. UpdateWindow(WinperfInfo.hWndMain);
  237. return (TRUE);
  238. }
  239. LRESULT APIENTRY
  240. MainWndProc(
  241. HWND hWnd,
  242. UINT message,
  243. WPARAM wParam,
  244. LPARAM lParam
  245. )
  246. /*++
  247. Routine Description:
  248. Process messages.
  249. Arguments:
  250. hWnd - window hande
  251. message - type of message
  252. wParam - additional information
  253. lParam - additional information
  254. Return Value:
  255. status of operation
  256. Revision History:
  257. 02-17-91 Initial code
  258. --*/
  259. {
  260. PAINTSTRUCT ps;
  261. //
  262. // process each message
  263. //
  264. switch (message) {
  265. //
  266. // create window
  267. //
  268. case WM_CREATE:
  269. {
  270. HDC hDC = GetDC(hWnd);
  271. BOOLEAN Fit;
  272. UINT Index;
  273. //
  274. // make brushes and pens
  275. //
  276. WinperfInfo.hBluePen = CreatePen(PS_SOLID,1,RGB(000,000,128));
  277. WinperfInfo.hRedPen = CreatePen(PS_SOLID,1,RGB(255,000,000));
  278. WinperfInfo.hGreenPen = CreatePen(PS_SOLID,1,RGB(000,255,000));
  279. WinperfInfo.hMagentaPen = CreatePen(PS_SOLID,1,RGB(255,000,254));
  280. WinperfInfo.hYellowPen = CreatePen(PS_SOLID,1,RGB(255,255,000));
  281. WinperfInfo.hDotPen = CreatePen(PS_DOT,1,RGB(000,000,000));
  282. WinperfInfo.hBackground = CreateSolidBrush(RGB(192,192,192));
  283. WinperfInfo.hLightBrush = CreateSolidBrush(RGB(255,255,255));
  284. WinperfInfo.hDarkBrush = CreateSolidBrush(RGB(128,128,128));
  285. WinperfInfo.hRedBrush = CreateSolidBrush(RGB(255,000,000));
  286. WinperfInfo.hGreenBrush = CreateSolidBrush(RGB(000,255,000));
  287. WinperfInfo.hBlueBrush = CreateSolidBrush(RGB(000,000,255));
  288. WinperfInfo.hMagentaBrush= CreateSolidBrush(RGB(255,000,254));
  289. WinperfInfo.hYellowBrush = CreateSolidBrush(RGB(255,255,000));
  290. //
  291. // create thee fonts using NT default font families
  292. //
  293. WinperfInfo.SmallFont = CreateFont(8,
  294. 0,
  295. 0,
  296. 0,
  297. 400,
  298. FALSE,
  299. FALSE,
  300. FALSE,
  301. ANSI_CHARSET,
  302. OUT_DEFAULT_PRECIS,
  303. CLIP_DEFAULT_PRECIS,
  304. DRAFT_QUALITY,
  305. DEFAULT_PITCH,
  306. "Small Fonts");
  307. WinperfInfo.MediumFont = CreateFont(10,
  308. 0,
  309. 0,
  310. 0,
  311. 400,
  312. FALSE,
  313. FALSE,
  314. FALSE,
  315. ANSI_CHARSET,
  316. OUT_DEFAULT_PRECIS,
  317. CLIP_DEFAULT_PRECIS,
  318. DRAFT_QUALITY,
  319. DEFAULT_PITCH,
  320. "Times New Roman");
  321. WinperfInfo.LargeFont = CreateFont(14,
  322. 0,
  323. 0,
  324. 0,
  325. 400,
  326. FALSE,
  327. FALSE,
  328. FALSE,
  329. ANSI_CHARSET,
  330. OUT_DEFAULT_PRECIS,
  331. CLIP_DEFAULT_PRECIS,
  332. DRAFT_QUALITY,
  333. DEFAULT_PITCH,
  334. "Times New Roman");
  335. //
  336. // create a system timer event to call performance gathering routines by.
  337. //
  338. WinperfInfo.TimerId = SetTimer(hWnd,
  339. TIMER_ID,
  340. 1000 * DELAY_SECONDS,
  341. NULL);
  342. //
  343. // init display variables
  344. //
  345. InitPerfWindowDisplay(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  346. //
  347. // Fit the perf windows into the main window
  348. //
  349. Fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  350. if (!Fit) {
  351. //DbgPrint("FitPerfWindows Fails !\n");
  352. }
  353. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  354. CalcDrawFrame(&PerfDataList[Index]);
  355. if (!CreateMemoryContext(hDC,&PerfDataList[Index])) {
  356. MessageBox(hWnd,"Error Allocating Memory","Winperf",MB_OK);
  357. DestroyWindow(hWnd);
  358. break;
  359. }
  360. }
  361. //
  362. // init performance routines
  363. //
  364. WinperfInfo.NumberOfProcessors = InitPerfInfo();
  365. //
  366. // release the DC handle
  367. //
  368. ReleaseDC(hWnd,hDC);
  369. }
  370. break;
  371. //
  372. // re-size
  373. //
  374. case WM_SIZE:
  375. {
  376. int i;
  377. HDC hDC = GetDC(hWnd);
  378. RECT ClientRect;
  379. BOOLEAN Fit;
  380. //DbgPrint("WM_SIZE display active[0] = %i\n",(int)PerfDataList[0].Display);
  381. //
  382. // get size of cleint area
  383. //
  384. GetWindowRect(hWnd,&ClientRect);
  385. WinperfInfo.WindowPositionX = ClientRect.left;
  386. WinperfInfo.WindowPositionY = ClientRect.top;
  387. WinperfInfo.WindowSizeX = ClientRect.right - ClientRect.left;
  388. WinperfInfo.WindowSizeY = ClientRect.bottom - ClientRect.top;
  389. Fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  390. if (!Fit) {
  391. //DbgPrint("WM_SIZE error, FitPerf returns FALSE\n");
  392. }
  393. for (i=0;i<SAVE_SUBJECTS;i++) {
  394. DeleteMemoryContext(&PerfDataList[i]);
  395. CalcDrawFrame(&PerfDataList[i]);
  396. if (!CreateMemoryContext(hDC,&PerfDataList[i])) {
  397. MessageBox(hWnd,"Error Allocating Memory","Winperf",MB_OK);
  398. DestroyWindow(hWnd);
  399. break;
  400. }
  401. }
  402. //
  403. // force window to be re-painted
  404. //
  405. InvalidateRect(hWnd,NULL,TRUE);
  406. //
  407. // release the DC handle
  408. //
  409. ReleaseDC(hWnd,hDC);
  410. }
  411. break;
  412. case WM_MOVE:
  413. {
  414. HDC hDC = GetDC(hWnd);
  415. RECT ClientRect;
  416. //
  417. // get size of cleint area
  418. //
  419. GetWindowRect(hWnd,&ClientRect);
  420. WinperfInfo.WindowPositionX = ClientRect.left;
  421. WinperfInfo.WindowPositionY = ClientRect.top;
  422. WinperfInfo.WindowSizeX = ClientRect.right - ClientRect.left;
  423. WinperfInfo.WindowSizeY = ClientRect.bottom - ClientRect.top;
  424. ReleaseDC(hWnd,hDC);
  425. }
  426. break;
  427. //
  428. // command from application menu
  429. //
  430. case WM_COMMAND:
  431. switch (wParam){
  432. //
  433. // exit window
  434. //
  435. case IDM_EXIT:
  436. DestroyWindow(hWnd);
  437. break;
  438. //
  439. // about command
  440. //
  441. case IDM_SELECT:
  442. {
  443. HDC hDC = GetDC(hWnd);
  444. INT_PTR DialogResult;
  445. int Index;
  446. BOOLEAN fit;
  447. DialogResult = DialogBox(hInst,
  448. MAKEINTRESOURCE(IDM_SEL_DLG),
  449. hWnd,
  450. SelectDlgProc);
  451. if (DialogResult == DIALOG_SUCCESS) {
  452. fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  453. if (!fit) {
  454. //DbgPrint("Fit Fails\n");
  455. }
  456. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  457. DeleteMemoryContext(&PerfDataList[Index]);
  458. CalcDrawFrame(&PerfDataList[Index]);
  459. if (!CreateMemoryContext(hDC,&PerfDataList[Index])) {
  460. MessageBox(hWnd,"Error Allocating Memory","Winperf",MB_OK);
  461. DestroyWindow(hWnd);
  462. break;
  463. }
  464. }
  465. InvalidateRect(hWnd,NULL,TRUE);
  466. }
  467. ReleaseDC(hWnd,hDC);
  468. }
  469. break;
  470. default:
  471. return (DefWindowProc(hWnd, message, wParam, lParam));
  472. }
  473. break;
  474. case WM_PAINT:
  475. //
  476. // repaint the window
  477. //
  478. {
  479. int i;
  480. HDC hDC = BeginPaint(hWnd,&ps);
  481. SelectObject(hDC,GetStockObject(NULL_BRUSH));
  482. for (i=0;i<SAVE_SUBJECTS;i++) {
  483. if (PerfDataList[i].Display == TRUE) {
  484. DrawFrame(hDC,&PerfDataList[i]);
  485. //
  486. // Draw each item, for CPU items decide whether to draw
  487. // line graphs or CPU bar graphs
  488. //
  489. if (
  490. ((i < MAX_PROCESSOR) || (i == (IDM_CPU_TOTAL - IDM_CPU0))) &&
  491. (WinperfInfo.CpuStyle == CPU_STYLE_BAR)
  492. ) {
  493. DrawCpuBarGraph(hDC,&PerfDataList[i],i);
  494. } else {
  495. DrawPerfText(hDC,&PerfDataList[i],i);
  496. DrawPerfGraph(hDC,&PerfDataList[i]);
  497. }
  498. }
  499. }
  500. EndPaint(hWnd,&ps);
  501. }
  502. break;
  503. case WM_TIMER:
  504. {
  505. int i;
  506. HDC hDC = GetDC(hWnd);
  507. CalcCpuTime(PerfDataList);
  508. //
  509. // update all performance information
  510. //
  511. for (i=0;i<SAVE_SUBJECTS;i++) {
  512. if (PerfDataList[i].Display == TRUE) {
  513. //
  514. // for cpu0-7 and cpu total, check for cpu bar graph or
  515. // cpu line graph
  516. //
  517. if (
  518. ((i < MAX_PROCESSOR) || (i == (IDM_CPU_TOTAL - IDM_CPU0))) &&
  519. (WinperfInfo.CpuStyle == CPU_STYLE_BAR)
  520. ) {
  521. DrawCpuBarGraph(hDC,&PerfDataList[i],i);
  522. } else {
  523. DrawPerfText(hDC,&PerfDataList[i],i);
  524. if (PerfDataList[i].ChangeScale) {
  525. DrawPerfGraph(hDC,&PerfDataList[i]);
  526. } else {
  527. ShiftPerfGraph(hDC,&PerfDataList[i]);
  528. }
  529. }
  530. }
  531. }
  532. ReleaseDC(hWnd,hDC);
  533. }
  534. break;
  535. //
  536. // handle a double click
  537. //
  538. case WM_NCLBUTTONDBLCLK:
  539. case WM_LBUTTONDBLCLK:
  540. {
  541. DWORD WindowStyle;
  542. //
  543. // get old window style, take out caption and menu
  544. //
  545. if (!IsIconic(hWnd)) {
  546. if (WinperfInfo.DisplayMenu) {
  547. WindowStyle = GetWindowLong(hWnd,GWL_STYLE);
  548. WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU;
  549. SetMenu(hWnd,NULL);
  550. SetWindowLong(hWnd,GWL_STYLE,WindowStyle);
  551. SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  552. ShowWindow(hWnd,SW_SHOW);
  553. WinperfInfo.DisplayMode=STYLE_DISABLE_MENU;
  554. WinperfInfo.DisplayMenu = FALSE;
  555. } else {
  556. WindowStyle = GetWindowLong(hWnd,GWL_STYLE);
  557. WindowStyle = (WindowStyle & (~STYLE_DISABLE_MENU)) | STYLE_ENABLE_MENU;
  558. SetMenu(hWnd,WinperfInfo.hMenu);
  559. SetWindowLong(hWnd,GWL_STYLE,WindowStyle);
  560. SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  561. ShowWindow(hWnd,SW_SHOW);
  562. WinperfInfo.DisplayMode=STYLE_ENABLE_MENU;
  563. WinperfInfo.DisplayMenu = TRUE;
  564. }
  565. } else {
  566. DefWindowProc(hWnd, message, wParam, lParam);
  567. }
  568. }
  569. break;
  570. //
  571. // enable dragging with mouse in non-client
  572. //
  573. case WM_NCHITTEST:
  574. {
  575. lParam = DefWindowProc(hWnd, message, wParam, lParam);
  576. if ((WinperfInfo.DisplayMenu==FALSE) && (lParam == HTCLIENT)) {
  577. return(HTCAPTION);
  578. } else {
  579. return(lParam);
  580. }
  581. }
  582. break;
  583. case WM_DESTROY:
  584. {
  585. UINT Index;
  586. //
  587. // Save profile info
  588. //
  589. SaveProfileData(&WinperfInfo);
  590. //
  591. // Delete Windows Objects
  592. //
  593. KillTimer(hWnd,TIMER_ID);
  594. DeleteObject(WinperfInfo.hRedPen);
  595. DeleteObject(WinperfInfo.hGreenPen);
  596. DeleteObject(WinperfInfo.hBluePen);
  597. DeleteObject(WinperfInfo.hYellowPen);
  598. DeleteObject(WinperfInfo.hMagentaPen);
  599. DeleteObject(WinperfInfo.hDotPen);
  600. DeleteObject(WinperfInfo.hBackground);
  601. DeleteObject(WinperfInfo.hLightBrush);
  602. DeleteObject(WinperfInfo.hDarkBrush);
  603. DeleteObject(WinperfInfo.hRedBrush);
  604. DeleteObject(WinperfInfo.hGreenBrush);
  605. DeleteObject(WinperfInfo.hBlueBrush);
  606. DeleteObject(WinperfInfo.hMagentaBrush);
  607. DeleteObject(WinperfInfo.hYellowBrush);
  608. for (Index=0;Index<SAVE_SUBJECTS;Index++ ) {
  609. DeleteMemoryContext(&PerfDataList[Index]);
  610. }
  611. //
  612. // Destroy window
  613. //
  614. PostQuitMessage(0);
  615. }
  616. break;
  617. default:
  618. //
  619. // Passes message on if unproccessed
  620. //
  621. return (DefWindowProc(hWnd, message, wParam, lParam));
  622. }
  623. return 0;
  624. }
  625. INT_PTR
  626. APIENTRY SelectDlgProc(
  627. HWND hDlg,
  628. UINT message,
  629. WPARAM wParam,
  630. LPARAM lParam
  631. )
  632. /*++
  633. Routine Description:
  634. Process message for select dialog box.
  635. Arguments:
  636. hDlg - window handle of the dialog box
  637. message - type of message
  638. wParam - message-specific information
  639. lParam - message-specific information
  640. Return Value:
  641. status of operation
  642. Revision History:
  643. 03-21-91 Initial code
  644. --*/
  645. {
  646. UINT ButtonState;
  647. UINT Index;
  648. switch (message) {
  649. case WM_INITDIALOG:
  650. //
  651. // Init Buttons with PerfDataList Structure
  652. //
  653. for (Index = 0; Index< SAVE_SUBJECTS; Index++) {
  654. if (Index < MAX_PROCESSOR) {
  655. if (Index < WinperfInfo.NumberOfProcessors) {
  656. if (PerfDataList[Index].Display == TRUE) {
  657. SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,1,0);
  658. } else {
  659. SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,0,0);
  660. }
  661. } else {
  662. //
  663. // Disable display if > WinperfInfo.NumberOfProcessors
  664. //
  665. // Also Disable radio button
  666. //
  667. PerfDataList[Index].Display = FALSE;
  668. EnableWindow(GetDlgItem(hDlg,IDM_CPU0+Index),FALSE);
  669. }
  670. } else {
  671. //
  672. // Set or clear radio button based on display variable
  673. //
  674. if (PerfDataList[Index].Display == TRUE) {
  675. SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,1,0);
  676. } else {
  677. SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,0,0);
  678. }
  679. }
  680. }
  681. //
  682. // Beyond the end of the save subjects lies the cpu Style, set this to either style
  683. //
  684. if (WinperfInfo.CpuStyle == CPU_STYLE_LINE) {
  685. CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_LINE);
  686. } else {
  687. CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_BAR);
  688. }
  689. return (TRUE);
  690. case WM_COMMAND:
  691. switch(wParam) {
  692. //
  693. // end function
  694. //
  695. case IDOK:
  696. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  697. ButtonState = (UINT)SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_GETCHECK,0,0);
  698. if (ButtonState == 1) {
  699. PerfDataList[Index].Display = TRUE;
  700. WinperfInfo.DisplayElement[Index] = 1;
  701. } else {
  702. PerfDataList[Index].Display = FALSE;
  703. WinperfInfo.DisplayElement[Index] = 0;
  704. }
  705. }
  706. //
  707. // Check CPU bar graph
  708. //
  709. ButtonState = IsDlgButtonChecked(hDlg,IDM_SEL_LINE);
  710. if (ButtonState == 1) {
  711. WinperfInfo.CpuStyle = CPU_STYLE_LINE;
  712. } else {
  713. WinperfInfo.CpuStyle = CPU_STYLE_BAR;
  714. }
  715. EndDialog(hDlg, DIALOG_SUCCESS);
  716. return (TRUE);
  717. case IDCANCEL:
  718. EndDialog(hDlg, DIALOG_CANCEL );
  719. return (TRUE);
  720. //
  721. // CPU STYLE
  722. //
  723. case IDM_SEL_LINE:
  724. CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_LINE);
  725. return(TRUE);
  726. case IDM_SEL_BAR:
  727. CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_BAR);
  728. return(TRUE);
  729. }
  730. }
  731. return (FALSE);
  732. }
  733. VOID
  734. InitProfileData(
  735. PWINPERF_INFO pWinperfInfo
  736. )
  737. /*++
  738. Routine Description:
  739. Attempt tp read the following fields from the winperf.ini file
  740. Arguments:
  741. WindowPositionX - Window initial x position
  742. WindowPositionY - Window initial y position
  743. WindowSizeX - Window initial width
  744. WindowSizey - Window Initial height
  745. DisplayMode - Window initial display mode
  746. Return Value:
  747. None, values are set to default before a call to this operation. If there is a problem then
  748. default:values are left unchanged.
  749. Revision History:
  750. 02-17-91 Initial code
  751. --*/
  752. {
  753. DWORD PositionX,PositionY,SizeX,SizeY,Mode,Index,Element[SAVE_SUBJECTS],CpuStyle;
  754. UCHAR TempStr[256];
  755. PositionX = GetPrivateProfileInt("winperf","PositionX" ,pWinperfInfo->WindowPositionX,"winperf.ini");
  756. PositionY = GetPrivateProfileInt("winperf","PositionY" ,pWinperfInfo->WindowPositionY,"winperf.ini");
  757. SizeX = GetPrivateProfileInt("winperf","SizeX" ,pWinperfInfo->WindowSizeX ,"winperf.ini");
  758. SizeY = GetPrivateProfileInt("winperf","SizeY" ,pWinperfInfo->WindowSizeY ,"winperf.ini");
  759. //
  760. // read the first deiplay element with default 1
  761. //
  762. Element[0] = GetPrivateProfileInt("winperf","DisplayElement0",1,"winperf.ini");
  763. //
  764. // read the rest of the display elements with default 0
  765. //
  766. for (Index=1;Index<SAVE_SUBJECTS;Index++) {
  767. wsprintf(TempStr,"DisplayElement%i",Index);
  768. Element[Index] = GetPrivateProfileInt("winperf",TempStr,0,"winperf.ini");
  769. }
  770. Mode = GetPrivateProfileInt("winperf","DisplayMode",pWinperfInfo->DisplayMode ,"winperf.ini");
  771. CpuStyle = GetPrivateProfileInt("winperf","CpuStyle",pWinperfInfo->CpuStyle ,"winperf.ini");
  772. pWinperfInfo->WindowPositionX = PositionX;
  773. pWinperfInfo->WindowPositionY = PositionY;
  774. pWinperfInfo->WindowSizeX = SizeX;
  775. pWinperfInfo->WindowSizeY = SizeY;
  776. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  777. pWinperfInfo->DisplayElement[Index] = Element[Index];
  778. }
  779. pWinperfInfo->DisplayMode = Mode;
  780. pWinperfInfo->CpuStyle = CpuStyle;
  781. }
  782. VOID
  783. SaveProfileData(
  784. PWINPERF_INFO pWinperfInfo
  785. )
  786. /*++
  787. Routine Description:
  788. Save profile data
  789. Arguments:
  790. WindowPositionX - Window initial x position
  791. WindowPositionY - Window initial y position
  792. WindowSizeX - Window initial width
  793. WindowSizey - Window Initial height
  794. DisplayMode - Window initial display mode
  795. Return Value:
  796. None.
  797. Revision History:
  798. 02-17-91 Initial code
  799. --*/
  800. {
  801. UCHAR TempStr[50],TempName[50];
  802. UINT Index;
  803. wsprintf(TempStr,"%i",pWinperfInfo->WindowPositionX);
  804. WritePrivateProfileString("winperf","PositionX",TempStr,"winperf.ini");
  805. wsprintf(TempStr,"%i",pWinperfInfo->WindowPositionY);
  806. WritePrivateProfileString("winperf","PositionY",TempStr,"winperf.ini");
  807. wsprintf(TempStr,"%i",pWinperfInfo->WindowSizeX);
  808. WritePrivateProfileString("winperf","SizeX",TempStr,"winperf.ini");
  809. wsprintf(TempStr,"%i",pWinperfInfo->WindowSizeY);
  810. WritePrivateProfileString("winperf","SizeY",TempStr,"winperf.ini");
  811. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  812. wsprintf(TempStr,"%li",pWinperfInfo->DisplayElement[Index]);
  813. wsprintf(TempName,"DisplayElement%li",Index);
  814. WritePrivateProfileString("winperf",TempName,TempStr,"winperf.ini");
  815. }
  816. wsprintf(TempStr,"%li",pWinperfInfo->DisplayMode);
  817. WritePrivateProfileString("winperf","DisplayMode",TempStr,"winperf.ini");
  818. wsprintf(TempStr,"%li",pWinperfInfo->CpuStyle);
  819. WritePrivateProfileString("winperf","CpuStyle",TempStr,"winperf.ini");
  820. }
  821. BOOLEAN
  822. InitPerfWindowDisplay(
  823. IN HWND hWnd,
  824. IN HDC hDC,
  825. IN PDISPLAY_ITEM DisplayItems,
  826. IN ULONG NumberOfWindows
  827. )
  828. /*++
  829. Routine Description:
  830. Init All perf windows to active, init data
  831. Arguments:
  832. hDC - Screen context
  833. DisplayItems - List of display structures
  834. NumberOfWindows - Number of sub-windows
  835. Return Value:
  836. Status
  837. Revision History:
  838. 02-17-91 Initial code
  839. --*/
  840. {
  841. int Index1;
  842. UINT Index;
  843. for (Index=0;Index<NumberOfWindows;Index++) {
  844. if (WinperfInfo.DisplayElement[Index] == 0) {
  845. DisplayItems[Index].Display = FALSE;
  846. } else {
  847. DisplayItems[Index].Display = TRUE;
  848. }
  849. DisplayItems[Index].CurrentDrawingPos = 0;
  850. if (Index < MAX_PROCESSOR) {
  851. DisplayItems[Index].NumberOfElements = 3;
  852. DisplayItems[Index].Max = 100;
  853. } else if (Index == (IDM_CPU_TOTAL - IDM_CPU0)) {
  854. DisplayItems[Index].NumberOfElements = 3;
  855. DisplayItems[Index].Max = 100;
  856. } else {
  857. DisplayItems[Index].NumberOfElements = 1;
  858. }
  859. for (Index1=0;Index1<DATA_LIST_LENGTH;Index1++) {
  860. DisplayItems[Index].KernelTime[Index1] = 0;
  861. DisplayItems[Index].UserTime[Index1] = 0;
  862. DisplayItems[Index].DpcTime[Index1] = 0;
  863. DisplayItems[Index].InterruptTime[Index1] = 0;
  864. DisplayItems[Index].TotalTime[Index1] = 0;
  865. }
  866. }
  867. return(TRUE);
  868. }