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.

221 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. perfmem.c
  5. Abstract:
  6. This file implements an Performance Object that presents
  7. System Memory Performance Object
  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 <ntmmapi.h>
  19. #include <windows.h>
  20. #include <winperf.h>
  21. #include <ntprfctr.h>
  22. #include <perfutil.h>
  23. #include "perfos.h"
  24. #include "perfosmc.h"
  25. #include "datamem.h"
  26. DWORD APIENTRY
  27. CollectMemoryObjectData (
  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 XXX 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. NTSTATUS Status;
  59. DWORD TotalLen; // Length of the total return block
  60. PMEMORY_DATA_DEFINITION pMemoryDataDefinition;
  61. SYSTEM_FILECACHE_INFORMATION FileCache;
  62. PMEMORY_COUNTER_DATA pMCD;
  63. DWORD LocalPageSize;
  64. pMemoryDataDefinition = (MEMORY_DATA_DEFINITION *) *lppData;
  65. //
  66. // Check for enough space for memory data block
  67. //
  68. TotalLen = sizeof(MEMORY_DATA_DEFINITION) +
  69. sizeof(MEMORY_COUNTER_DATA);
  70. TotalLen = QWORD_MULTIPLE (TotalLen);
  71. if ( *lpcbTotalBytes < TotalLen ) {
  72. *lpcbTotalBytes = (DWORD) 0;
  73. *lpNumObjectTypes = (DWORD) 0;
  74. return ERROR_MORE_DATA;
  75. }
  76. #ifdef DBG
  77. STARTTIMING;
  78. #endif
  79. Status = NtQuerySystemInformation(
  80. SystemFileCacheInformation,
  81. &FileCache,
  82. sizeof(FileCache),
  83. NULL
  84. );
  85. if (!NT_SUCCESS(Status)) {
  86. if (hEventLog != NULL) {
  87. ReportEvent (hEventLog,
  88. EVENTLOG_WARNING_TYPE,
  89. 0,
  90. PERFOS_UNABLE_QUERY_FILE_CACHE_INFO,
  91. NULL,
  92. 0,
  93. sizeof(DWORD),
  94. NULL,
  95. (LPVOID)&Status);
  96. }
  97. memset (&FileCache, 0, sizeof(FileCache));
  98. }
  99. #ifdef DBG
  100. ENDTIMING (("PERFMEM: %d takes %I64u ms\n", __LINE__, diff));
  101. #endif
  102. //
  103. // Define memory data block
  104. //
  105. memcpy (pMemoryDataDefinition,
  106. &MemoryDataDefinition,
  107. sizeof(MEMORY_DATA_DEFINITION));
  108. //
  109. // Format and collect memory data
  110. //
  111. LocalPageSize = BasicInfo.PageSize;
  112. pMCD = (PMEMORY_COUNTER_DATA)&pMemoryDataDefinition[1];
  113. pMCD->CounterBlock.ByteLength = QWORD_MULTIPLE(sizeof (MEMORY_COUNTER_DATA));
  114. pMCD->AvailablePages = SysPerfInfo.AvailablePages;
  115. pMCD->AvailablePages *= LocalPageSize; // display as bytes
  116. pMCD->AvailableKBytes = pMCD->AvailablePages / 1024;
  117. pMCD->AvailableMBytes = pMCD->AvailableKBytes / 1024;
  118. pMCD->CommittedPages = SysPerfInfo.CommittedPages;
  119. pMCD->CommittedPages *= LocalPageSize;
  120. pMCD->CommitList = SysPerfInfo.CommitLimit;
  121. pMCD->CommitList *= LocalPageSize;
  122. pMCD->PageFaults = SysPerfInfo.PageFaultCount;
  123. pMCD->WriteCopies = SysPerfInfo.CopyOnWriteCount;
  124. pMCD->TransitionFaults = SysPerfInfo.TransitionCount;
  125. pMCD->CacheFaults = FileCache.PageFaultCount;
  126. pMCD->DemandZeroFaults = SysPerfInfo.DemandZeroCount;
  127. pMCD->Pages = SysPerfInfo.PageReadCount +
  128. SysPerfInfo.DirtyPagesWriteCount;
  129. pMCD->PagesInput = SysPerfInfo.PageReadCount;
  130. pMCD->PageReads = SysPerfInfo.PageReadIoCount;
  131. pMCD->DirtyPages = SysPerfInfo.DirtyPagesWriteCount;
  132. pMCD->DirtyWrites = SysPerfInfo.DirtyWriteIoCount;
  133. pMCD->PagedPool = SysPerfInfo.PagedPoolPages;
  134. pMCD->PagedPool *= LocalPageSize;
  135. pMCD->NonPagedPool = SysPerfInfo.NonPagedPoolPages;
  136. pMCD->NonPagedPool *= LocalPageSize;
  137. pMCD->PagedPoolAllocs = SysPerfInfo.PagedPoolAllocs -
  138. SysPerfInfo.PagedPoolFrees;
  139. pMCD->NonPagedPoolAllocs = SysPerfInfo.NonPagedPoolAllocs -
  140. SysPerfInfo.NonPagedPoolFrees;
  141. pMCD->FreeSystemPtes = SysPerfInfo.FreeSystemPtes;
  142. pMCD->CacheBytes = FileCache.CurrentSize;
  143. pMCD->PeakCacheBytes = FileCache.PeakSize;
  144. pMCD->ResidentPagedPoolBytes = SysPerfInfo.ResidentPagedPoolPage;
  145. pMCD->ResidentPagedPoolBytes *= LocalPageSize;
  146. pMCD->TotalSysCodeBytes = SysPerfInfo.TotalSystemCodePages;
  147. pMCD->TotalSysCodeBytes *= LocalPageSize;
  148. pMCD->ResidentSysCodeBytes = SysPerfInfo.ResidentSystemCodePage;
  149. pMCD->ResidentSysCodeBytes *= LocalPageSize;
  150. pMCD->TotalSysDriverBytes = SysPerfInfo.TotalSystemDriverPages;
  151. pMCD->TotalSysDriverBytes *= LocalPageSize;
  152. pMCD->ResidentSysDriverBytes = SysPerfInfo.ResidentSystemDriverPage;
  153. pMCD->ResidentSysDriverBytes *= LocalPageSize;
  154. pMCD->ResidentSysCacheBytes = SysPerfInfo.ResidentSystemCachePage;
  155. pMCD->ResidentSysCacheBytes *= LocalPageSize;
  156. pMCD->TransitionRePurpose = FileCache.TransitionRePurposeCount;
  157. // This is reported as a percentage of CommittedPages/CommitLimit.
  158. // these value return a value in "page" units. Since this is a
  159. // fraction, the page size (i.e. converting pages to bytes) will
  160. // cancel out and as such can be ignored, saving some CPU cycles
  161. //
  162. pMCD->CommitBytesInUse = (ULONG)SysPerfInfo.CommittedPages;
  163. pMCD->CommitBytesLimit = (ULONG)SysPerfInfo.CommitLimit;
  164. #if 0 // no longer supported
  165. // load the VLM counters - this should really be removed period.
  166. pMCD->SystemVlmCommitCharge = 0;
  167. pMCD->SystemVlmPeakCommitCharge = 0;
  168. pMCD->SystemVlmSharedCommitCharge = 0;
  169. #endif
  170. *lpcbTotalBytes =
  171. pMemoryDataDefinition->MemoryObjectType.TotalByteLength =
  172. (DWORD) QWORD_MULTIPLE(((LPBYTE) (& pMCD[1])) - (LPBYTE) pMemoryDataDefinition);
  173. * lppData = (LPVOID) (((LPBYTE) pMemoryDataDefinition) + * lpcbTotalBytes);
  174. *lpNumObjectTypes = 1;
  175. #ifdef DBG
  176. ENDTIMING (("PERFMEM: %d takes %I64u ms total\n", __LINE__, diff));
  177. #endif
  178. return ERROR_SUCCESS;
  179. }