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.

245 lines
5.8 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <errno.h>
  6. #include <malloc.h>
  7. #include <stdio.h>
  8. #include "pperf.h"
  9. #include "..\pstat.h"
  10. extern UCHAR Buffer[];
  11. extern PDISPLAY_ITEM Calc1, Calc2;
  12. extern PDISPLAY_ITEM PerfGraphList;
  13. extern ULONG NumberOfProcessors;
  14. extern BOOL LazyOp;
  15. #define BufferSize 60000
  16. VOID AssignCalcId (PDISPLAY_ITEM pPerf);
  17. PDISPLAY_ITEM LookUpCalcId (IN ULONG id);
  18. VOID SnapPercent (PDISPLAY_ITEM);
  19. VOID SnapSum (PDISPLAY_ITEM);
  20. VOID InitPercent (PDISPLAY_ITEM);
  21. VOID InitSum (PDISPLAY_ITEM);
  22. ULONG StaticPercentScale = 10000;
  23. ULONG CalcSort = 300000;
  24. VOID (*InitCalc[])(PDISPLAY_ITEM) = {
  25. InitPercent, InitSum, InitPercent, InitPercent
  26. };
  27. INT_PTR
  28. CALLBACK CalcDlgProc(
  29. HWND hDlg,
  30. unsigned int message,
  31. WPARAM wParam,
  32. LPARAM lParam
  33. )
  34. {
  35. PDISPLAY_ITEM pPerf;
  36. UINT ButtonState;
  37. UINT Index, i;
  38. switch (message) {
  39. case WM_INITDIALOG:
  40. Buffer[BufferSize - 1] = 0;
  41. _snprintf (Buffer,
  42. BufferSize - 1,
  43. "A. %s", Calc1->PerfName);
  44. SetDlgItemText(hDlg, IDM_CALC_TEXTA, Buffer);
  45. _snprintf (Buffer,
  46. BufferSize - 1,
  47. "B. %s", Calc2->PerfName);
  48. SetDlgItemText(hDlg, IDM_CALC_TEXTB, Buffer);
  49. return (TRUE);
  50. case WM_COMMAND:
  51. switch(wParam) {
  52. case IDOK:
  53. if (Calc1 && Calc2) {
  54. for (i=IDM_CALC_FORM1; i <= IDM_CALC_FORM4; i++) {
  55. if (SendDlgItemMessage(hDlg,i,BM_GETCHECK,0,0)) {
  56. // found selected form type
  57. i = i - IDM_CALC_FORM1;
  58. AssignCalcId (Calc1);
  59. AssignCalcId (Calc2);
  60. pPerf = AllocateDisplayItem();
  61. pPerf->CalcPercentId[0] = Calc1->CalcId;
  62. pPerf->CalcPercentId[1] = Calc2->CalcId;
  63. pPerf->SnapParam1 = i;
  64. pPerf->IsCalc = TRUE;
  65. InitCalc[i](pPerf);
  66. SetDisplayToTrue (pPerf, CalcSort++);
  67. RefitWindows(NULL, NULL);
  68. break;
  69. }
  70. }
  71. }
  72. EndDialog(hDlg, DIALOG_SUCCESS);
  73. return (TRUE);
  74. case IDCANCEL:
  75. EndDialog(hDlg, DIALOG_CANCEL );
  76. return (TRUE);
  77. }
  78. }
  79. return (FALSE);
  80. }
  81. VOID
  82. AssignCalcId (
  83. IN OUT PDISPLAY_ITEM pPerf
  84. )
  85. {
  86. PDISPLAY_ITEM p;
  87. ULONG l;
  88. if (pPerf->CalcId) {
  89. return ;
  90. }
  91. l = 0;
  92. for (p=PerfGraphList; p; p=p->Next) {
  93. if (p->CalcId > l) {
  94. l = p->CalcId;
  95. }
  96. }
  97. pPerf->CalcId = l + 1;
  98. pPerf->DispName[sizeof(pPerf->DispName) - 1] = 0;
  99. _snprintf (pPerf->DispName,
  100. sizeof(pPerf->DispName) - 1,
  101. "%d. %s", l+1, pPerf->PerfName);
  102. pPerf->DispNameLen = strlen(pPerf->DispName);
  103. }
  104. PDISPLAY_ITEM
  105. LookUpCalcId (
  106. IN ULONG id
  107. )
  108. {
  109. PDISPLAY_ITEM p;
  110. for (p=PerfGraphList; p; p=p->Next) {
  111. if (p->CalcId == id) {
  112. return p;
  113. }
  114. }
  115. return NULL;
  116. }
  117. VOID
  118. InitPercent (
  119. IN OUT PDISPLAY_ITEM pPerf
  120. )
  121. {
  122. // for now use same type
  123. _snprintf (pPerf->PerfName,
  124. sizeof(pPerf->PerfName) - 1,
  125. "%d %%of %d",
  126. Calc1->CalcId, Calc2->CalcId);
  127. pPerf->PerfName[sizeof(pPerf->PerfName) - 1] = 0;
  128. pPerf->SnapData = SnapPercent;
  129. pPerf->IsPercent = TRUE;
  130. pPerf->AutoTotal = FALSE;
  131. pPerf->MaxToUse = &StaticPercentScale;
  132. pPerf->DisplayMode= DISPLAY_MODE_TOTAL;
  133. }
  134. VOID
  135. InitSum (
  136. IN OUT PDISPLAY_ITEM pPerf
  137. )
  138. {
  139. // for now use same type
  140. _snprintf (pPerf->PerfName,
  141. sizeof(pPerf->PerfName) - 1,
  142. "Sum %d+%d",
  143. Calc1->CalcId, Calc2->CalcId);
  144. pPerf->PerfName[sizeof(pPerf->PerfName) - 1] = 0;
  145. pPerf->SnapData = SnapSum;
  146. }
  147. VOID
  148. SnapPercent (
  149. IN OUT PDISPLAY_ITEM pPerf
  150. )
  151. {
  152. PDISPLAY_ITEM p1, p2;
  153. ULONG i, l, l1, l2;
  154. p1 = pPerf->CalcPercent[0];
  155. p2 = pPerf->CalcPercent[1];
  156. if (p1 == NULL || p2 == NULL) {
  157. p1 = pPerf->CalcPercent[0] = LookUpCalcId (pPerf->CalcPercentId[0]);
  158. p2 = pPerf->CalcPercent[1] = LookUpCalcId (pPerf->CalcPercentId[1]);
  159. if (p1 == NULL || p2 == NULL) {
  160. LazyOp = TRUE;
  161. pPerf->DeleteMe = TRUE;
  162. return;
  163. }
  164. }
  165. l1 = p1->DataList[0][0];
  166. l2 = p2->DataList[0][0];
  167. if (l1 > 0x60000) {
  168. l2 = l2 / 10000;
  169. } else {
  170. l1 = l1 * 10000;
  171. }
  172. if (l2) {
  173. pPerf->CurrentDataPoint[0] = l1 / l2;
  174. } else {
  175. pPerf->CurrentDataPoint[0] = 0;
  176. }
  177. }
  178. VOID
  179. SnapSum (
  180. IN OUT PDISPLAY_ITEM pPerf
  181. )
  182. {
  183. PDISPLAY_ITEM p1, p2;
  184. ULONG i, l, l1, l2;
  185. p1 = pPerf->CalcPercent[0];
  186. p2 = pPerf->CalcPercent[1];
  187. if (p1 == NULL || p2 == NULL) {
  188. p1 = pPerf->CalcPercent[0] = LookUpCalcId (pPerf->CalcPercentId[0]);
  189. p2 = pPerf->CalcPercent[1] = LookUpCalcId (pPerf->CalcPercentId[1]);
  190. if (p1 == NULL || p2 == NULL) {
  191. LazyOp = TRUE;
  192. pPerf->DeleteMe = TRUE;
  193. return;
  194. }
  195. }
  196. for (i=0; i < NumberOfProcessors; i++) {
  197. pPerf->CurrentDataPoint[i+1] =
  198. p1->CurrentDataPoint[i+1] + p2->CurrentDataPoint[i+1];
  199. }
  200. }