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.

225 lines
5.4 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. //////////////////////////////////////////////////////////////////////
  8. //
  9. // Object.cpp
  10. //
  11. // Created by a-dcrews, Oct. 6, 1998
  12. //
  13. //////////////////////////////////////////////////////////////////////
  14. #include "HiPerStress.h"
  15. #include "Object.h"
  16. //////////////////////////////////////////////////////////////////////
  17. //
  18. // CInstance
  19. //
  20. //////////////////////////////////////////////////////////////////////
  21. CInstance::CInstance(WCHAR *wcsNameSpace, WCHAR *wcsName, IWbemClassObject *pObj, long lID)
  22. {
  23. pObj->AddRef();
  24. m_pObj = pObj;
  25. wcscpy(m_wcsNameSpace, wcsNameSpace);
  26. wcscpy(m_wcsName, wcsName);
  27. m_lID = lID;
  28. // Enumerate through the non-system object properties
  29. m_pObj->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY);
  30. BSTR bstrName = 0;
  31. VARIANT v;
  32. VariantInit(&v);
  33. // Create parameter array
  34. while (WBEM_NO_ERROR == m_pObj->Next(0, &bstrName, &v, 0, 0))
  35. {
  36. m_apParameter.Add(new CParameter(this, bstrName, v));
  37. SysFreeString(bstrName);
  38. VariantClear(&v);
  39. }
  40. m_pObj->EndEnumeration();
  41. }
  42. CInstance::~CInstance()
  43. {
  44. if (m_pObj)
  45. m_pObj->Release();
  46. }
  47. void CInstance::DumpObject(const WCHAR *wcsPrefix)
  48. {
  49. BSTR bstrName = 0;
  50. LONG vt = 0;
  51. VARIANT v;
  52. VariantInit(&v);
  53. HRESULT hRes;
  54. // Print out the object path to identify it.
  55. printf("%.*S|\n", (wcslen(wcsPrefix)-1), wcsPrefix);
  56. printf("%.*S+--Object: %S\\%S\n", (wcslen(wcsPrefix)-1),
  57. wcsPrefix, m_wcsNameSpace,
  58. m_wcsName);
  59. // Enumerate through the non-system object properties
  60. hRes = m_pObj->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY);
  61. if (FAILED(hRes))
  62. {
  63. printf("Could not begin enumerating %S\n", m_wcsName);
  64. return;
  65. }
  66. // Print out each property
  67. while (WBEM_NO_ERROR == m_pObj->Next(0, &bstrName, &v, &vt, 0))
  68. {
  69. printf("%S |--%S: ", wcsPrefix, bstrName);
  70. switch (v.vt)
  71. {
  72. case VT_NULL:
  73. printf("<NULL>\n");break;
  74. case VT_I4:
  75. printf("%d\n", V_I4(&v)); break;
  76. case VT_UI4:
  77. printf("%u\n", V_I4(&v)); break;
  78. case VT_BSTR:
  79. case VT_I8:
  80. case VT_UI8:
  81. printf("%S\n", V_BSTR(&v)); break;
  82. default:
  83. printf("Type = complex\n");
  84. }
  85. SysFreeString(bstrName);
  86. VariantClear(&v);
  87. }
  88. m_pObj->EndEnumeration();
  89. }
  90. void CInstance::DumpStats(LONG lNumRefs)
  91. {
  92. BSTR bstrName = 0;
  93. LONG vt = 0;
  94. VARIANT v;
  95. VariantInit(&v);
  96. // Print out the object path to identify it.
  97. printf(" %S\n", m_wcsName);
  98. printf("----------------------------------------------------------------------------\n");
  99. printf("Refreshes:\n");
  100. printf(" Expected: %-5d Recieved: %-5d\n", 0, lNumRefs);
  101. printf("----------------------------------------------------------------------------\n");
  102. printf(" Parameter | Initial Val | Expected Val | Final Value \n");
  103. printf("----------------------------------------------------------------------------\n");
  104. for (int i = 0; i < m_apParameter.GetSize(); i++)
  105. {
  106. m_apParameter[i]->DumpStats(lNumRefs);
  107. }
  108. printf("\n\n\n");
  109. }
  110. //////////////////////////////////////////////////////////////////////
  111. //
  112. // CParameter
  113. //
  114. //////////////////////////////////////////////////////////////////////
  115. CInstance::CParameter::CParameter(CInstance* pInst, BSTR bstrName, VARIANT vInitValue)
  116. {
  117. m_pInst = pInst;
  118. m_bstrParaName = SysAllocString(bstrName);
  119. VariantInit(&m_vInitValue);
  120. VariantCopy(&m_vInitValue, &vInitValue);
  121. m_dwNumRefs = 0;
  122. }
  123. CInstance::CParameter::~CParameter()
  124. {
  125. SysFreeString(m_bstrParaName);
  126. VariantClear(&m_vInitValue);
  127. }
  128. void CInstance::CParameter::DumpStats(LONG lRefCount)
  129. {
  130. HRESULT hRes;
  131. // Determine if this parameter is a counter by checking the qualifier set
  132. IWbemQualifierSet *pQS;
  133. hRes = m_pInst->m_pObj->GetPropertyQualifierSet(m_bstrParaName, &pQS);
  134. if (FAILED(hRes))
  135. {
  136. printf("Could not get property qualifier set\n");
  137. return;
  138. }
  139. hRes = pQS->Get(BSTR(L"countertype"), 0, 0, 0);
  140. pQS->Release();
  141. // If it found the countertype qualifier, then we output the counter info
  142. if (hRes == WBEM_S_NO_ERROR)
  143. {
  144. LONG vt;
  145. VARIANT v;
  146. VariantInit(&v);
  147. LONG f;
  148. // Get the current value
  149. m_pInst->m_pObj->Get(m_bstrParaName, 0, &v, &vt, &f);
  150. // Output based on variant type. Output is in the following format
  151. // Parameter Name, Initial Value, Tot Refreshes Rec'd, Expected value, Current Value
  152. switch (m_vInitValue.vt)
  153. {
  154. case VT_I4:
  155. {
  156. int nInitVal = V_I4(&m_vInitValue),
  157. nExpVal = nInitVal + lRefCount,
  158. nFinalVal = V_I4(&v);
  159. printf("%c%-14.14S", (nExpVal == nFinalVal)?' ':'*', m_bstrParaName);
  160. printf(" %-14d %-14d %-14d", nInitVal, nExpVal, nFinalVal);
  161. }break;
  162. case VT_UI4:
  163. {
  164. long lInitVal = V_I4(&m_vInitValue),
  165. lExpVal = lInitVal + lRefCount,
  166. lFinalVal = V_I4(&v);
  167. printf("%c%-14.14S", (lExpVal == lFinalVal)?' ':'*', m_bstrParaName);
  168. printf(" %-14u %-14u %-14u", lInitVal, lExpVal, lFinalVal);
  169. }break;
  170. case VT_BSTR:
  171. case VT_I8:
  172. case VT_UI8:
  173. {
  174. long lInitVal = _wtol(V_BSTR(&m_vInitValue)),
  175. lExpVal = lInitVal + lRefCount,
  176. lFinalVal = _wtol(V_BSTR(&v));
  177. printf("%c%-14.14S", (lExpVal == lFinalVal)?' ':'*', m_bstrParaName);
  178. printf(" %-14.13S %-14d %-14.13S", V_BSTR(&m_vInitValue), lExpVal, V_BSTR(&v));
  179. }break;
  180. default:
  181. printf(" %-14.14S", m_bstrParaName);
  182. printf(" complex %-14.14S complex ", L"0");
  183. }
  184. printf("\n");
  185. VariantClear(&v);
  186. }
  187. }