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.

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