Source code of Windows XP (NT5)
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.

351 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. CalcPerf.c
  5. Abstract:
  6. calculate perfoemance statistics
  7. Author:
  8. Environment:
  9. Win32
  10. Revision History:
  11. 10-20-91 Initial version
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <assert.h>
  18. #include "calcperf.h"
  19. SYSTEM_VDM_INSTEMUL_INFO PerfInfo;
  20. SYSTEM_VDM_INSTEMUL_INFO PreviousPerfInfo;
  21. //
  22. // make the maximum for pages available a "grow only" max. (since the
  23. // amount of memory in a machine is limited. Set to 1 Mbytes here.
  24. //
  25. ULONG PgAvailMax = 16384;
  26. ULONG PreviousInterruptCount;
  27. ULONG InterruptCount;
  28. ULONG
  29. InitPerfInfo()
  30. /*++
  31. Routine Description:
  32. Initialize data for perf measurements
  33. Arguments:
  34. None
  35. Return Value:
  36. Number of system processors (0 if error)
  37. Revision History:
  38. 10-21-91 Initial code
  39. --*/
  40. {
  41. NTSTATUS Status;
  42. Status = NtQuerySystemInformation(
  43. SystemVdmInstemulInformation,
  44. &PerfInfo,
  45. sizeof(PerfInfo),
  46. NULL
  47. );
  48. if ( !NT_SUCCESS(Status) ) {
  49. ExitProcess(1);
  50. }
  51. PreviousPerfInfo = PerfInfo;
  52. return(0);
  53. }
  54. BOOL
  55. CalcCpuTime(
  56. PDISPLAY_ITEM PerfListItem
  57. )
  58. /*++
  59. Routine Description:
  60. calculate and return %cpu time and time periods
  61. Arguments:
  62. None
  63. Return Value:
  64. Revision History:
  65. 10-21-91 Initial code
  66. --*/
  67. {
  68. NTSTATUS Status;
  69. Status = NtQuerySystemInformation(
  70. SystemVdmInstemulInformation,
  71. &PerfInfo,
  72. sizeof(PerfInfo),
  73. NULL
  74. );
  75. if ( !NT_SUCCESS(Status) ) {
  76. ExitProcess(1);
  77. }
  78. PerfListItem[IX_PUSHF].ChangeScale = UpdatePerfInfo(
  79. &PerfListItem[IX_PUSHF].TotalTime[0],
  80. delta(OpcodePUSHF),
  81. &PerfListItem[IX_PUSHF].Max);
  82. PerfListItem[IX_POPF].ChangeScale = UpdatePerfInfo(
  83. &PerfListItem[IX_POPF].TotalTime[0],
  84. delta(OpcodePOPF),
  85. &PerfListItem[IX_POPF].Max);
  86. PerfListItem[IX_IRET].ChangeScale = UpdatePerfInfo(
  87. &PerfListItem[IX_IRET].TotalTime[0],
  88. delta(OpcodeIRET),
  89. &PerfListItem[IX_IRET].Max);
  90. PerfListItem[IX_HLT].ChangeScale = UpdatePerfInfo(
  91. &PerfListItem[IX_HLT].TotalTime[0],
  92. delta(OpcodeHLT),
  93. &PerfListItem[IX_HLT].Max);
  94. PerfListItem[IX_CLI].ChangeScale = UpdatePerfInfo(
  95. &PerfListItem[IX_CLI].TotalTime[0],
  96. delta(OpcodeCLI),
  97. &PerfListItem[IX_CLI].Max);
  98. PerfListItem[IX_STI].ChangeScale = UpdatePerfInfo(
  99. &PerfListItem[IX_STI].TotalTime[0],
  100. delta(OpcodeSTI),
  101. &PerfListItem[IX_STI].Max);
  102. PerfListItem[IX_BOP].ChangeScale = UpdatePerfInfo(
  103. &PerfListItem[IX_BOP].TotalTime[0],
  104. delta(BopCount),
  105. &PerfListItem[IX_BOP].Max);
  106. PerfListItem[IX_SEGNOTP].ChangeScale = UpdatePerfInfo(
  107. &PerfListItem[IX_SEGNOTP].TotalTime[0],
  108. delta(SegmentNotPresent),
  109. &PerfListItem[IX_SEGNOTP].Max);
  110. PerfListItem[IX_VDMOPCODEF].ChangeScale = UpdatePerfInfo(
  111. &PerfListItem[IX_VDMOPCODEF].TotalTime[0],
  112. delta(VdmOpcode0F),
  113. &PerfListItem[IX_VDMOPCODEF].Max);
  114. PerfListItem[IX_INB].ChangeScale = UpdatePerfInfo(
  115. &PerfListItem[IX_INB].TotalTime[0],
  116. delta(OpcodeINB),
  117. &PerfListItem[IX_INB].Max);
  118. PerfListItem[IX_INW].ChangeScale = UpdatePerfInfo(
  119. &PerfListItem[IX_INW].TotalTime[0],
  120. delta(OpcodeINW),
  121. &PerfListItem[IX_INW].Max);
  122. PerfListItem[IX_OUTB].ChangeScale = UpdatePerfInfo(
  123. &PerfListItem[IX_OUTB].TotalTime[0],
  124. delta(OpcodeOUTB),
  125. &PerfListItem[IX_OUTB].Max);
  126. PerfListItem[IX_OUTW].ChangeScale = UpdatePerfInfo(
  127. &PerfListItem[IX_OUTW].TotalTime[0],
  128. delta(OpcodeOUTW),
  129. &PerfListItem[IX_OUTW].Max);
  130. PerfListItem[IX_INSW].ChangeScale = UpdatePerfInfo(
  131. &PerfListItem[IX_INSW].TotalTime[0],
  132. delta(OpcodeINSW),
  133. &PerfListItem[IX_INSW].Max);
  134. PerfListItem[IX_OUTSB].ChangeScale = UpdatePerfInfo(
  135. &PerfListItem[IX_OUTSB].TotalTime[0],
  136. delta(OpcodeOUTSB),
  137. &PerfListItem[IX_OUTSB].Max);
  138. PerfListItem[IX_OUTSW].ChangeScale = UpdatePerfInfo(
  139. &PerfListItem[IX_OUTSW].TotalTime[0],
  140. delta(OpcodeOUTSW),
  141. &PerfListItem[IX_OUTSW].Max);
  142. PreviousPerfInfo = PerfInfo;
  143. return(TRUE);
  144. }
  145. BOOL
  146. UpdatePerfInfo(
  147. PULONG DataPointer,
  148. ULONG NewDataValue,
  149. PULONG OldMaxValue
  150. )
  151. /*++
  152. Routine Description:
  153. Shift array of DATA_LIST_LENGTH USORTS and add the new value to the
  154. start of list
  155. Arguments:
  156. DataPointer - Pointer to the start of a DATA_LIST_LENGTH array
  157. NewDataValue - Data element to be added
  158. OldMaxValue - Scale value
  159. Return Value:
  160. TRUE is MaxValue must be increased or decreased
  161. Revision History:
  162. 10-21-91 Initial code
  163. --*/
  164. {
  165. ULONG Index;
  166. ULONG ScanMax;
  167. //
  168. // Shift DataArray while keeping track of the max value
  169. //
  170. //
  171. // Set temp max to 100 to init a minimum maximum
  172. //
  173. ScanMax = 100;
  174. for (Index=DATA_LIST_LENGTH-1;Index>=1;Index--) {
  175. DataPointer[Index] = DataPointer[Index-1];
  176. if (DataPointer[Index] > ScanMax) {
  177. ScanMax = DataPointer[Index];
  178. }
  179. }
  180. //
  181. // add and check first value
  182. //
  183. DataPointer[0] = NewDataValue;
  184. if (NewDataValue > ScanMax) {
  185. ScanMax = NewDataValue;
  186. }
  187. //
  188. // If OldMaxValue = NULL then do not do a max limit check
  189. //
  190. if (OldMaxValue == NULL) {
  191. return(FALSE);
  192. }
  193. //
  194. // If Max values changed then undate the new max
  195. // value and return TRUE.
  196. //
  197. if (ScanMax != *OldMaxValue) {
  198. *OldMaxValue = ScanMax;
  199. return(TRUE);
  200. }
  201. return(FALSE);
  202. }
  203. VOID
  204. InitListData(
  205. PDISPLAY_ITEM PerfListItem,
  206. ULONG NumberOfItems
  207. )
  208. /*++
  209. Routine Description:
  210. Init all perf data structures
  211. Arguments:
  212. PerfListItem - array of all perf categories
  213. NumberOfItems - Number of items to init
  214. Return Value:
  215. Revision History:
  216. 10-21-91 Initial code
  217. --*/
  218. {
  219. ULONG ListIndex,DataIndex;
  220. for (ListIndex=0;ListIndex<NumberOfItems;ListIndex++) {
  221. PerfListItem[ListIndex].Max = 100;
  222. PerfListItem[ListIndex].ChangeScale = FALSE;
  223. for (DataIndex=0;DataIndex<DATA_LIST_LENGTH;DataIndex++) {
  224. PerfListItem[ListIndex].TotalTime[DataIndex] = 0;
  225. PerfListItem[ListIndex].KernelTime[DataIndex] = 0;
  226. PerfListItem[ListIndex].UserTime[DataIndex] = 0;
  227. }
  228. }
  229. }