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.

229 lines
7.1 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. PERFTHRD.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. #include <process.h>
  11. #include <WinMgmtR.h>
  12. #include "ntreg.h"
  13. #include "perfthrd.h"
  14. #include "adaputil.h"
  15. CPerfThread::CPerfThread( CAdapPerfLib* pPerfLib ) : CAdapThread( pPerfLib )
  16. ////////////////////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Constructor
  19. //
  20. ////////////////////////////////////////////////////////////////////////////////////////////
  21. {
  22. CNTRegistry reg;
  23. if ( CNTRegistry::no_error == reg.Open( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\WBEM\\CIMOM" ) )
  24. {
  25. long lError = reg.GetDWORD( L"ADAPPerflibTimeout", &m_dwPerflibTimeoutSec );
  26. if ( CNTRegistry::no_error == lError )
  27. {
  28. // This is what we want
  29. }
  30. else if ( CNTRegistry::not_found == lError )
  31. {
  32. // Not set, so add it
  33. reg.SetDWORD( L"ADAPPerflibTimeout", PERFTHREAD_DEFAULT_TIMEOUT );
  34. m_dwPerflibTimeoutSec = PERFTHREAD_DEFAULT_TIMEOUT;
  35. }
  36. else
  37. {
  38. // Unknown error, continue with default value
  39. m_dwPerflibTimeoutSec = PERFTHREAD_DEFAULT_TIMEOUT;
  40. }
  41. }
  42. else
  43. {
  44. m_dwPerflibTimeoutSec = PERFTHREAD_DEFAULT_TIMEOUT;
  45. }
  46. }
  47. HRESULT CPerfThread::Open( CAdapPerfLib* pLib )
  48. ////////////////////////////////////////////////////////////////////////////////////////////
  49. //
  50. // Open creates a new open request object using the CAdapPerfLib parameter. It then queues
  51. // it up and waits for PERFTHREAD_TIMEOUT milliseconds. If the operation has not returned
  52. // in time, then ...
  53. //
  54. ////////////////////////////////////////////////////////////////////////////////////////////
  55. {
  56. HRESULT hr = WBEM_E_FAILED;
  57. try
  58. {
  59. // Create new request object
  60. // =========================
  61. CPerfOpenRequest* pRequest = new CPerfOpenRequest;
  62. if ( NULL == pRequest ) return WBEM_E_OUT_OF_MEMORY;
  63. CAdapReleaseMe armRequest( pRequest );
  64. // Queue the request and return
  65. // ============================
  66. if (FAILED(hr = Enqueue( pRequest ))) return hr;
  67. // Wait for the call to return
  68. // ===========================
  69. switch ( WaitForSingleObject( pRequest->GetWhenDoneHandle(), ( m_dwPerflibTimeoutSec * 1000 ) ) )
  70. {
  71. case WAIT_OBJECT_0:
  72. {
  73. // SUCCESS: Call returned before it timed-out
  74. // ==========================================
  75. hr = pRequest->GetHRESULT();
  76. }break;
  77. case WAIT_TIMEOUT:
  78. {
  79. pLib->SetStatus( ADAP_PERFLIB_IS_INACTIVE );
  80. hr = WBEM_E_FAILED; //Reset();
  81. if (!pLib->GetEventLogCalled())
  82. {
  83. pLib->SetEventLogCalled(TRUE);
  84. CAdapUtility::NTLogEvent( EVENTLOG_WARNING_TYPE, WBEM_MC_ADAP_PERFLIB_FUNCTION_TIMEOUT, (LPCWSTR)pLib->GetServiceName(), L"open" );
  85. }
  86. }
  87. }
  88. }
  89. catch(...)
  90. {
  91. ERRORTRACE( ( LOG_WMIADAP, "CPerfThread::Open() failed due to out of memory exception.\n" ) );
  92. hr = WBEM_E_FAILED;
  93. }
  94. return hr;
  95. }
  96. HRESULT CPerfThread::GetPerfBlock( CAdapPerfLib* pLib, PERF_OBJECT_TYPE** ppData,
  97. DWORD* pdwBytes, DWORD* pdwNumObjTypes, BOOL fCostly )
  98. {
  99. if (NULL == ppData || NULL == pdwBytes || NULL == pdwNumObjTypes) return WBEM_E_INVALID_PARAMETER;
  100. HRESULT hr = WBEM_E_FAILED;
  101. try
  102. {
  103. CPerfCollectRequest* pRequest = new CPerfCollectRequest( fCostly );
  104. if (NULL == pRequest) return WBEM_E_OUT_OF_MEMORY;
  105. CAdapReleaseMe armRequest( pRequest );
  106. if (FAILED(hr = Enqueue( pRequest ))) return hr;
  107. switch ( WaitForSingleObject( pRequest->GetWhenDoneHandle(), ( m_dwPerflibTimeoutSec * 1000 ) ) )
  108. {
  109. case WAIT_OBJECT_0:
  110. {
  111. hr = pRequest->GetHRESULT();
  112. pRequest->GetData( ppData, pdwBytes, pdwNumObjTypes );
  113. if (FAILED(hr)){
  114. pLib->SetStatus( ADAP_PERFLIB_FAILED );
  115. }
  116. }break;
  117. case WAIT_TIMEOUT:
  118. {
  119. pLib->SetStatus( ADAP_PERFLIB_IS_INACTIVE );
  120. hr = WBEM_E_FAILED; //Reset();
  121. if (!pLib->GetEventLogCalled())
  122. {
  123. pLib->SetEventLogCalled(TRUE);
  124. CAdapUtility::NTLogEvent( EVENTLOG_WARNING_TYPE, WBEM_MC_ADAP_BAD_PERFLIB_TIMEOUT, (LPCWSTR)pLib->GetServiceName(), L"collect" );
  125. }
  126. }break;
  127. }
  128. }
  129. catch(...)
  130. {
  131. // DEVDEV
  132. // should se call pLib->SetStatus(SOMETHING); ?
  133. //
  134. ERRORTRACE( ( LOG_WMIADAP, "CPerfThread::GetPerfBlock() failed due to out of memory exception.\n" ) );
  135. return WBEM_E_OUT_OF_MEMORY;
  136. }
  137. return hr;
  138. }
  139. HRESULT CPerfThread::Close( CAdapPerfLib* pLib )
  140. {
  141. HRESULT hr = WBEM_E_FAILED;
  142. try
  143. {
  144. CPerfCloseRequest* pRequest = new CPerfCloseRequest;
  145. if (NULL == pRequest) return WBEM_E_OUT_OF_MEMORY;
  146. CAdapReleaseMe armRequest( pRequest );
  147. if (FAILED(hr = Enqueue( pRequest ))) return hr;
  148. switch ( WaitForSingleObject( pRequest->GetWhenDoneHandle(), ( m_dwPerflibTimeoutSec * 1000 ) ) )
  149. {
  150. case WAIT_OBJECT_0:
  151. {
  152. hr = pRequest->GetHRESULT();
  153. }break;
  154. case WAIT_TIMEOUT:
  155. {
  156. pLib->SetStatus( ADAP_PERFLIB_IS_INACTIVE );
  157. hr = WBEM_E_FAILED; //Reset();
  158. if (!pLib->GetEventLogCalled())
  159. {
  160. pLib->SetEventLogCalled(TRUE);
  161. CAdapUtility::NTLogEvent( EVENTLOG_WARNING_TYPE, WBEM_MC_ADAP_BAD_PERFLIB_TIMEOUT, (LPCWSTR)pLib->GetServiceName(), L"close" );
  162. }
  163. }break;
  164. }
  165. }
  166. catch(...)
  167. {
  168. ERRORTRACE( ( LOG_WMIADAP, "CPerfThread::Close() failed due to out of memory exception.\n" ) );
  169. hr = WBEM_E_OUT_OF_MEMORY;
  170. }
  171. return hr;
  172. }
  173. HRESULT CPerfOpenRequest::Execute( CAdapPerfLib* pPerfLib )
  174. {
  175. // Call the open function in the perflib
  176. // =====================================
  177. m_hrReturn = pPerfLib->_Open();
  178. return m_hrReturn;
  179. }
  180. HRESULT CPerfCollectRequest::Execute( CAdapPerfLib* pPerfLib )
  181. {
  182. // Call the collect function in the perflib
  183. // ========================================
  184. m_hrReturn = pPerfLib->_GetPerfBlock( &m_pData, &m_dwBytes, &m_dwNumObjTypes, m_fCostly );
  185. return m_hrReturn;
  186. }
  187. HRESULT CPerfCloseRequest::Execute( CAdapPerfLib* pPerfLib )
  188. {
  189. // Call the open function in the perflib
  190. // =====================================
  191. m_hrReturn = pPerfLib->_Close();
  192. return m_hrReturn;
  193. }