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.

238 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. perfexpr.c
  5. Abstract:
  6. This file implements an Performance Object that presents
  7. Extended Process performance object data
  8. Created:
  9. Bob Watson 22-Oct-1996
  10. Revision History
  11. --*/
  12. //
  13. // Include Files
  14. //
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <winperf.h>
  20. #include <ntprfctr.h>
  21. #define PERF_HEAP hLibHeap
  22. #include <perfutil.h>
  23. #include "perfsprc.h"
  24. #include "perfmsg.h"
  25. #include "dataexpr.h"
  26. DWORD APIENTRY
  27. CollectExProcessObjectData (
  28. IN OUT LPVOID *lppData,
  29. IN OUT LPDWORD lpcbTotalBytes,
  30. IN OUT LPDWORD lpNumObjectTypes
  31. )
  32. /*++
  33. Routine Description:
  34. This routine will return the data for the processor object
  35. Arguments:
  36. IN OUT LPVOID *lppData
  37. IN: pointer to the address of the buffer to receive the completed
  38. PerfDataBlock and subordinate structures. This routine will
  39. append its data to the buffer starting at the point referenced
  40. by *lppData.
  41. OUT: points to the first byte after the data structure added by this
  42. routine. This routine updated the value at lppdata after appending
  43. its data.
  44. IN OUT LPDWORD lpcbTotalBytes
  45. IN: the address of the DWORD that tells the size in bytes of the
  46. buffer referenced by the lppData argument
  47. OUT: the number of bytes added by this routine is writted to the
  48. DWORD pointed to by this argument
  49. IN OUT LPDWORD NumObjectTypes
  50. IN: the address of the DWORD to receive the number of objects added
  51. by this routine
  52. OUT: the number of objects added by this routine is writted to the
  53. DWORD pointed to by this argument
  54. Returns:
  55. 0 if successful, else Win 32 error code of failure
  56. --*/
  57. {
  58. DWORD TotalLen; // Length of the total return block
  59. DWORD NumExProcessInstances;
  60. PPROCESS_VA_INFO pThisProcess; // pointer to current process
  61. PERF_INSTANCE_DEFINITION *pPerfInstanceDefinition;
  62. EXPROCESS_DATA_DEFINITION *pExProcessDataDefinition;
  63. PEXPROCESS_COUNTER_DATA pECD;
  64. if (pProcessVaInfo) { // process only if a buffer is available
  65. pExProcessDataDefinition = (EXPROCESS_DATA_DEFINITION *)*lppData;
  66. // check for sufficient space in buffer for at least one entry
  67. TotalLen = sizeof(EXPROCESS_DATA_DEFINITION) +
  68. sizeof(PERF_INSTANCE_DEFINITION) +
  69. (MAX_PROCESS_NAME_LENGTH + 1) * sizeof (WCHAR) +
  70. sizeof(EXPROCESS_COUNTER_DATA);
  71. if (*lpcbTotalBytes < TotalLen) {
  72. *lpcbTotalBytes = 0;
  73. *lpNumObjectTypes = 0;
  74. return ERROR_MORE_DATA;
  75. }
  76. // copy process data block to buffer
  77. memcpy (pExProcessDataDefinition,
  78. &ExProcessDataDefinition,
  79. sizeof(EXPROCESS_DATA_DEFINITION));
  80. NumExProcessInstances = 0;
  81. pThisProcess = pProcessVaInfo;
  82. TotalLen = sizeof(EXPROCESS_DATA_DEFINITION);
  83. pPerfInstanceDefinition = (PERF_INSTANCE_DEFINITION *)
  84. &pExProcessDataDefinition[1];
  85. while (pThisProcess) {
  86. // see if this instance will fit
  87. TotalLen += sizeof (PERF_INSTANCE_DEFINITION) +
  88. (MAX_PROCESS_NAME_LENGTH + 1) * sizeof (WCHAR) +
  89. sizeof (DWORD) +
  90. sizeof (EXPROCESS_COUNTER_DATA);
  91. if (*lpcbTotalBytes < TotalLen) {
  92. *lpcbTotalBytes = 0;
  93. *lpNumObjectTypes = 0;
  94. return ERROR_MORE_DATA;
  95. }
  96. MonBuildInstanceDefinition (pPerfInstanceDefinition,
  97. (PVOID *) &pECD,
  98. 0,
  99. 0,
  100. (DWORD)-1,
  101. pThisProcess->pProcessName->Buffer);
  102. NumExProcessInstances++;
  103. pECD->CounterBlock.ByteLength = QWORD_MULTIPLE(sizeof (EXPROCESS_COUNTER_DATA));
  104. // load counters from the process va data structure
  105. pECD->ProcessId = pThisProcess->dwProcessId;
  106. pECD->ImageReservedBytes = pThisProcess->ImageReservedBytes;
  107. pECD->ImageFreeBytes = pThisProcess->ImageFreeBytes;
  108. pECD->ReservedBytes = pThisProcess->ReservedBytes;
  109. pECD->FreeBytes = pThisProcess->FreeBytes;
  110. pECD->CommitNoAccess = pThisProcess->MappedCommit[NOACCESS];
  111. pECD->CommitReadOnly = pThisProcess->MappedCommit[READONLY];
  112. pECD->CommitReadWrite = pThisProcess->MappedCommit[READWRITE];
  113. pECD->CommitWriteCopy = pThisProcess->MappedCommit[WRITECOPY];
  114. pECD->CommitExecute = pThisProcess->MappedCommit[EXECUTE];
  115. pECD->CommitExecuteRead = pThisProcess->MappedCommit[EXECUTEREAD];
  116. pECD->CommitExecuteWrite = pThisProcess->MappedCommit[EXECUTEREADWRITE];
  117. pECD->CommitExecuteWriteCopy = pThisProcess->MappedCommit[EXECUTEWRITECOPY];
  118. pECD->ReservedNoAccess = pThisProcess->PrivateCommit[NOACCESS];
  119. pECD->ReservedReadOnly = pThisProcess->PrivateCommit[READONLY];
  120. pECD->ReservedReadWrite = pThisProcess->PrivateCommit[READWRITE];
  121. pECD->ReservedWriteCopy = pThisProcess->PrivateCommit[WRITECOPY];
  122. pECD->ReservedExecute = pThisProcess->PrivateCommit[EXECUTE];
  123. pECD->ReservedExecuteRead = pThisProcess->PrivateCommit[EXECUTEREAD];
  124. pECD->ReservedExecuteWrite = pThisProcess->PrivateCommit[EXECUTEREADWRITE];
  125. pECD->ReservedExecuteWriteCopy = pThisProcess->PrivateCommit[EXECUTEWRITECOPY];
  126. pECD->UnassignedNoAccess = pThisProcess->OrphanTotals.CommitVector[NOACCESS];
  127. pECD->UnassignedReadOnly = pThisProcess->OrphanTotals.CommitVector[READONLY];
  128. pECD->UnassignedReadWrite = pThisProcess->OrphanTotals.CommitVector[READWRITE];
  129. pECD->UnassignedWriteCopy = pThisProcess->OrphanTotals.CommitVector[WRITECOPY];
  130. pECD->UnassignedExecute = pThisProcess->OrphanTotals.CommitVector[EXECUTE];
  131. pECD->UnassignedExecuteRead = pThisProcess->OrphanTotals.CommitVector[EXECUTEREAD];
  132. pECD->UnassignedExecuteWrite = pThisProcess->OrphanTotals.CommitVector[EXECUTEREADWRITE];
  133. pECD->UnassignedExecuteWriteCopy = pThisProcess->OrphanTotals.CommitVector[EXECUTEWRITECOPY];
  134. pECD->ImageTotalNoAccess = pThisProcess->MemTotals.CommitVector[NOACCESS];
  135. pECD->ImageTotalReadOnly = pThisProcess->MemTotals.CommitVector[READONLY];
  136. pECD->ImageTotalReadWrite = pThisProcess->MemTotals.CommitVector[READWRITE];
  137. pECD->ImageTotalWriteCopy = pThisProcess->MemTotals.CommitVector[WRITECOPY];
  138. pECD->ImageTotalExecute = pThisProcess->MemTotals.CommitVector[EXECUTE];
  139. pECD->ImageTotalExecuteRead = pThisProcess->MemTotals.CommitVector[EXECUTEREAD];
  140. pECD->ImageTotalExecuteWrite = pThisProcess->MemTotals.CommitVector[EXECUTEREADWRITE];
  141. pECD->ImageTotalExecuteWriteCopy = pThisProcess->MemTotals.CommitVector[EXECUTEWRITECOPY];
  142. pPerfInstanceDefinition = (PERF_INSTANCE_DEFINITION *)&pECD[1];
  143. pThisProcess = pThisProcess->pNextProcess; // point to next process
  144. } // end while not at end of list
  145. } // end if valid process info buffer
  146. else {
  147. // pProcessVaInfo is NULL. Initialize the DataDef and return
  148. // with no data
  149. pExProcessDataDefinition = (EXPROCESS_DATA_DEFINITION *)*lppData;
  150. TotalLen = sizeof(EXPROCESS_DATA_DEFINITION) +
  151. sizeof (PERF_INSTANCE_DEFINITION) +
  152. (MAX_PROCESS_NAME_LENGTH + 1) * sizeof (WCHAR) +
  153. sizeof (DWORD) +
  154. sizeof (EXPROCESS_COUNTER_DATA);
  155. if (*lpcbTotalBytes < TotalLen) {
  156. *lpcbTotalBytes = 0;
  157. *lpNumObjectTypes = 0;
  158. return ERROR_MORE_DATA;
  159. }
  160. // copy process data block to buffer
  161. memcpy (pExProcessDataDefinition,
  162. &ExProcessDataDefinition,
  163. sizeof(EXPROCESS_DATA_DEFINITION));
  164. NumExProcessInstances = 0;
  165. pPerfInstanceDefinition = (PERF_INSTANCE_DEFINITION *)
  166. &pExProcessDataDefinition[1];
  167. }
  168. pExProcessDataDefinition->ExProcessObjectType.NumInstances =
  169. NumExProcessInstances;
  170. *lpcbTotalBytes =
  171. pExProcessDataDefinition->ExProcessObjectType.TotalByteLength =
  172. QWORD_MULTIPLE(
  173. (DWORD)((PCHAR) pPerfInstanceDefinition -
  174. (PCHAR) pExProcessDataDefinition));
  175. *lppData = (LPVOID) ((PCHAR) pExProcessDataDefinition + *lpcbTotalBytes);
  176. *lpNumObjectTypes = 1;
  177. return ERROR_SUCCESS;
  178. }