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.

158 lines
4.8 KiB

  1. /*==========================================================================*\
  2. Module: perf.cpp
  3. Copyright Microsoft Corporation 1998, All Rights Reserved.
  4. Author: AWetmore
  5. Descriptions: Perf Object Definitions.
  6. \*==========================================================================*/
  7. #include "stdafx.h"
  8. #include "perf.h"
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Perf object definitions.
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. PerfLibrary * g_cplNtfsDrv = NULL;
  15. PerfObjectDefinition * g_cpodNtfsDrv = NULL;
  16. //////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Global flag for updating perf counters.
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. BOOL g_fPerfCounters = FALSE;
  22. DWORD g_dwPerfInterval = DEFAULT_PERF_UPDATE_INTERVAL;
  23. //$--InitializePerformanceStatistics-------------------------------------------
  24. //
  25. // This function initializes the perf counters defined above. It also checks
  26. // the registry to see if we want to monitor the perf counters.
  27. //
  28. //-----------------------------------------------------------------------------
  29. BOOL InitializePerformanceStatistics ()
  30. {
  31. HKEY hKey = NULL;
  32. LONG status = 0;
  33. DWORD size = MAX_PATH;
  34. DWORD type = REG_DWORD;
  35. DWORD fPerf = 0;
  36. DWORD msec = 0;
  37. //
  38. // Check the registry to see if we want to monitor the perf counters.
  39. //
  40. status = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  41. "SYSTEM\\CurrentControlSet\\Services\\NtfsDrv\\Performance",
  42. 0L,
  43. KEY_ALL_ACCESS,
  44. &hKey);
  45. if (status != ERROR_SUCCESS)
  46. goto Exit;
  47. #if 0
  48. status = RegQueryValueEx (hKey,
  49. "EnablePerfCounters",
  50. NULL,
  51. &type,
  52. (LPBYTE)&fPerf,
  53. &size);
  54. if (status != ERROR_SUCCESS || 0 == fPerf)
  55. goto Exit;
  56. //
  57. // Check the desired update period.
  58. //
  59. type = REG_DWORD;
  60. status = RegQueryValueEx (hKey,
  61. "UpdateInterval",
  62. NULL,
  63. &type,
  64. (LPBYTE)&msec,
  65. &size);
  66. if (status == ERROR_SUCCESS)
  67. {
  68. // make sure 0 < msec <= 0x7FFFFFFF
  69. if (msec > 0 && !(msec & 0x80000000) && type == REG_DWORD)
  70. g_dwPerfInterval = msec;
  71. }
  72. #endif
  73. //
  74. // Initialize the perf counters.
  75. //
  76. g_cplNtfsDrv = new PerfLibrary (L"NTFSDrv");
  77. if (!g_cplNtfsDrv)
  78. goto Exit;
  79. g_cpodNtfsDrv = g_cplNtfsDrv->AddPerfObjectDefinition (L"NTFSDRV_OBJ", OBJECT_NTFSDRV, TRUE);
  80. if (!g_cpodNtfsDrv)
  81. goto Exit;
  82. if (!g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_QUEUE_LENGTH, PERF_COUNTER_RAWCOUNT) ||
  83. !g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_NUM_ALLOCS, PERF_COUNTER_RAWCOUNT) ||
  84. !g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_NUM_DELETES, PERF_COUNTER_RAWCOUNT) ||
  85. !g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_NUM_ENUMERATED, PERF_COUNTER_RAWCOUNT) ||
  86. !g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_MSG_BODIES_OPEN, PERF_COUNTER_RAWCOUNT) ||
  87. !g_cpodNtfsDrv->AddPerfCounterDefinition(NTFSDRV_MSG_STREAMS_OPEN, PERF_COUNTER_RAWCOUNT))
  88. {
  89. goto Exit;
  90. }
  91. g_fPerfCounters = g_cplNtfsDrv->Init();
  92. Exit:
  93. if (hKey)
  94. CloseHandle (hKey);
  95. if (!g_fPerfCounters && g_cplNtfsDrv)
  96. {
  97. delete g_cplNtfsDrv;
  98. g_cplNtfsDrv = NULL;
  99. g_cpodNtfsDrv = NULL;
  100. }
  101. return g_fPerfCounters;
  102. }
  103. //$--ShutdownPerformanceStatistics--------------------------------------------
  104. //
  105. // This function shuts down the perf objects.
  106. //
  107. //-----------------------------------------------------------------------------
  108. void ShutdownPerformanceStatistics ()
  109. {
  110. if (g_cplNtfsDrv)
  111. {
  112. delete g_cplNtfsDrv;
  113. g_cplNtfsDrv = NULL;
  114. g_cpodNtfsDrv = NULL;
  115. }
  116. }
  117. //$--CreatePerfObjInstance-----------------------------------------------------
  118. //
  119. // This function relays the creation of perf object instance to the global
  120. // perf object definition.
  121. //
  122. //-----------------------------------------------------------------------------
  123. PerfObjectInstance * CreatePerfObjInstance (LPCWSTR pwstrInstanceName)
  124. {
  125. PerfObjectInstance * ppoi = NULL;
  126. if (g_cpodNtfsDrv)
  127. ppoi = g_cpodNtfsDrv->AddPerfObjectInstance (pwstrInstanceName);
  128. return ppoi;
  129. }