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.

134 lines
3.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1999.
  5. //
  6. // File : PERFOBJ.HXX
  7. //
  8. // Contents : Performance Data Object
  9. //
  10. // Classes : CPerfMon
  11. //
  12. // History: 22-Mar-94 t-joshh Created
  13. // 14-Jan-98 dlee Cleanup
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <bitfield.hxx>
  18. #include <smem.hxx>
  19. #include <perfci.hxx>
  20. #include <secutil.hxx>
  21. //----------------------------------------------------------------------------
  22. //
  23. // Performance Data's format in Shared Memory
  24. //
  25. // --------------------------------------------------------------------------------
  26. // | | | | | | | ... | | | ....
  27. // | | | | | | | | | |
  28. // --------------------------------------------------------------------------------
  29. // \ /\ /\ /\ /\ /\ / \ /\ /
  30. // (int) (BYTES)(2INT) (int) 31*(WCHAR) (DWORD) (DWORD) (int) <-- Size
  31. // No. of Empty Seq.No No. of Name of Counter ...... Counter No. of
  32. // Instance Slot Reservd CPerfMon CPerfMon CPerfMon
  33. // Object Object Object
  34. // Attached Attached
  35. // \_________ One CPerfMon Object____________/\___ Another one
  36. //
  37. //
  38. //
  39. //----------------------------------------------------------------------------
  40. #if (CIDBG==1)
  41. DECLARE_DEBUG(Perf);
  42. #define PerfDebugOut( x ) PerfInlineDebugOut x
  43. #else // CIDBG == 0
  44. #define PerfDebugOut( x )
  45. #endif // CIDBG == 1
  46. class CNamedMutex;
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Class: CPerfMon
  50. //
  51. // Purpose: Performance Object
  52. //
  53. // History: 22-Mar-94 t-joshh Created
  54. //
  55. //----------------------------------------------------------------------------
  56. class CPerfMon
  57. {
  58. public:
  59. CPerfMon( const WCHAR * wszInstanceName );
  60. ~CPerfMon();
  61. DWORD GetCurrValue( ULONG iCounter )
  62. {
  63. return * ComputeAddress( iCounter );
  64. }
  65. void Update( ULONG iCounter, DWORD dwValue )
  66. {
  67. DWORD * pdw = ComputeAddress( iCounter );
  68. InterlockedExchange( (long *) pdw, dwValue );
  69. }
  70. void Increment( ULONG iCounter )
  71. {
  72. DWORD * pdw = ComputeAddress( iCounter );
  73. InterlockedIncrement( (long *) pdw );
  74. }
  75. void Decrement( ULONG iCounter )
  76. {
  77. DWORD * pdw = ComputeAddress( iCounter );
  78. InterlockedDecrement( (long *) pdw );
  79. }
  80. private:
  81. DWORD * ComputeAddress( ULONG iCounter )
  82. {
  83. Win4Assert( 0 != _pdwSharedMemory );
  84. iCounter /= 2;
  85. Win4Assert( iCounter > 0 && iCounter <= _cCounters );
  86. iCounter--;
  87. return _pdwSharedMemory + iCounter;
  88. }
  89. DWORD * _pdwSharedMemory;
  90. ULONG _cCounters;
  91. int * _pcCount;
  92. BYTE * _pbBitfield;
  93. UINT * _pSeqNo;
  94. int _iWhichSlot;
  95. int * _piNumberAttach;
  96. CNamedSharedMem _SharedMemObj;
  97. XPtr<CNamedMutex> _xPerfMutex;
  98. };
  99. void ComputeCIPerfmonVars( ULONG & cMaxCats, ULONG & cbCatBitfield,
  100. ULONG & cbPerfHeader, ULONG & cbSharedMem );
  101. const unsigned cbTotalCounters = ( FILTER_TOTAL_NUM_COUNTERS +
  102. CI_TOTAL_NUM_COUNTERS ) * sizeof DWORD;
  103. const ULONG cbPerfCatalogSlot = sizeof( int ) +
  104. ( CI_PERF_MAX_CATALOG_LEN * sizeof WCHAR ) +
  105. cbTotalCounters;