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.

337 lines
7.0 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. ///////////////////////////////////////////////////////////////////
  8. //
  9. // CRefTreeMain.cpp
  10. //
  11. // Created by a-dcrews, Oct. 6, 1998
  12. //
  13. ///////////////////////////////////////////////////////////////////
  14. #include "HiPerStress.h"
  15. #include "Main.h"
  16. ///////////////////////////////////////////////////////////////////
  17. //
  18. // CMain
  19. //
  20. ///////////////////////////////////////////////////////////////////
  21. CMain::CMain()
  22. {
  23. }
  24. CMain::~CMain()
  25. {
  26. m_apRootRef.RemoveAll();
  27. }
  28. BOOL CMain::Create()
  29. {
  30. return TRUE;
  31. }
  32. ///////////////////////////////////////////////////////////////////
  33. //
  34. // CRefTreeMain
  35. //
  36. ///////////////////////////////////////////////////////////////////
  37. CRefTreeMain::CRefTreeMain()
  38. {
  39. }
  40. CRefTreeMain::~CRefTreeMain()
  41. {
  42. m_apAgent.RemoveAll();
  43. }
  44. BOOL CRefTreeMain::Create(WCHAR *wcsRoot)
  45. ////////////////////////////////////////////////////////////////////
  46. //
  47. // Create locator and all root refreshers
  48. //
  49. ////////////////////////////////////////////////////////////////////
  50. {
  51. if (!CMain::Create())
  52. return FALSE;
  53. // Create event
  54. m_hRefreshEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  55. // Create all root refreshers
  56. HKEY hKey;
  57. WCHAR wcsSubKey[512];
  58. DWORD dwIndex = 0,
  59. dwSize = 512,
  60. dwSubKey = dwSize;
  61. // Enumerate all keys
  62. HRESULT hRes = RegOpenKeyEx(HKEY_CURRENT_USER, wcsRoot, 0, KEY_READ, &hKey);
  63. while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, wcsSubKey, &dwSubKey, 0, NULL, 0, NULL))
  64. {
  65. // Look for refreshers
  66. switch(*(_wcsupr(wcsSubKey)))
  67. {
  68. case L'R':
  69. {
  70. WCHAR wcsRefRoot[1024];
  71. swprintf(wcsRefRoot, L"%s%s\\", wcsRoot, wcsSubKey);
  72. CRefresher *pRef = CreateChildRefresher(wcsRefRoot);
  73. m_apRootRef.Add(pRef);
  74. }
  75. }
  76. dwSubKey = dwSize;
  77. }
  78. RegCloseKey(hKey);
  79. return TRUE;
  80. }
  81. CRefresher* CRefTreeMain::CreateChildRefresher(WCHAR *wcsRegPath)
  82. ////////////////////////////////////////////////////////////////////
  83. //
  84. // Create refresher hierarchy and the stress object
  85. //
  86. ////////////////////////////////////////////////////////////////////
  87. {
  88. CRefresher *pRef = new CRefresher;
  89. if (!pRef->Create())
  90. {
  91. delete pRef;
  92. return NULL;
  93. }
  94. HKEY hKey;
  95. HRESULT hRes = RegOpenKeyEx(HKEY_CURRENT_USER, wcsRegPath, 0,
  96. KEY_READ, &hKey);
  97. if (hRes != ERROR_SUCCESS)
  98. {
  99. printf("**ERROR** Could not open the registry key: %s\n", wcsRegPath);
  100. delete pRef;
  101. return NULL;
  102. }
  103. AddChildren(hKey, wcsRegPath, pRef);
  104. SetStressInfo(hKey, pRef);
  105. RegCloseKey(hKey);
  106. return pRef;
  107. }
  108. BOOL CRefTreeMain::AddChildren(HKEY hKey, WCHAR *wcsRegPath, CRefresher *pRef)
  109. ////////////////////////////////////////////////////////////////////
  110. //
  111. // Add all child objects and refreshers
  112. //
  113. ////////////////////////////////////////////////////////////////////
  114. {
  115. WCHAR wcsSubKey[1024];
  116. const DWORD dwSize = 1024;
  117. DWORD dwIndex = 0,
  118. dwSubKey = dwSize;
  119. while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, wcsSubKey, &dwSubKey, 0, NULL, 0, NULL))
  120. {
  121. WCHAR wch;
  122. swscanf(wcsSubKey, L"%c", &wch);
  123. WCHAR wcsNewPath[1024];
  124. swprintf(wcsNewPath, L"%s%s\\", wcsRegPath, wcsSubKey);
  125. switch (*(_wcsupr(&wch)))
  126. {
  127. case L'R':
  128. if (!pRef->AddRefresher(CreateChildRefresher(wcsNewPath)))
  129. return FALSE;
  130. break;
  131. case L'O':
  132. if (!AddObject(wcsNewPath, pRef))
  133. return FALSE;
  134. break;
  135. }
  136. dwSubKey = dwSize;
  137. }
  138. return TRUE;
  139. }
  140. BOOL CRefTreeMain::AddObject(WCHAR *wcsNewPath, CRefresher *pRef)
  141. ////////////////////////////////////////////////////////////////////
  142. //
  143. // Obtain object and add it to refresher
  144. //
  145. ////////////////////////////////////////////////////////////////////
  146. {
  147. HRESULT hRes;
  148. HKEY hKey;
  149. // Open the object's key
  150. hRes = RegOpenKeyEx(HKEY_CURRENT_USER, wcsNewPath, 0, KEY_READ, &hKey);
  151. if (hRes != ERROR_SUCCESS)
  152. {
  153. printf("**ERROR** Could not open the registry key: %s\n", wcsNewPath);
  154. return FALSE;
  155. }
  156. WCHAR wcsName[512],
  157. wcsNameSpace[1024];
  158. DWORD dwType,
  159. dwName = 512,
  160. dwNameSpace = 1024;
  161. // Get the name of the object
  162. hRes = RegQueryValueEx (hKey, 0, 0, &dwType,
  163. (LPBYTE)wcsName, &dwName);
  164. if (hRes != ERROR_SUCCESS)
  165. {
  166. printf("**ERROR** Could not open the registry key: %S%S\n", wcsNewPath, L"<default>");
  167. return FALSE;
  168. }
  169. // Get the name of the namespace
  170. hRes = RegQueryValueEx (hKey, L"NameSpace", 0, &dwType,
  171. (LPBYTE)wcsNameSpace, &dwNameSpace);
  172. if (hRes != ERROR_SUCCESS)
  173. {
  174. printf("**ERROR** Could not open the registry key: %s\n", wcsNewPath);
  175. return FALSE;
  176. }
  177. RegCloseKey(hKey);
  178. return pRef->AddObject(wcsNameSpace, wcsName);
  179. }
  180. BOOL CRefTreeMain::SetStressInfo(HKEY hKey, CRefresher *pRef)
  181. ////////////////////////////////////////////////////////////////////
  182. //
  183. // Get the stress information
  184. //
  185. ////////////////////////////////////////////////////////////////////
  186. {
  187. DWORD dwIterations = 0,
  188. dwWait = 0,
  189. dwType = 0,
  190. dwSize = 1024;
  191. // Get the number of iterations for this refresher
  192. RegQueryValueEx (hKey, L"Iterations", 0, &dwType,
  193. (LPBYTE)&dwIterations, &dwSize);
  194. dwSize = 4;
  195. // Get the wait period between iterations
  196. RegQueryValueEx (hKey, L"Wait", 0, &dwType,
  197. (LPBYTE)&dwWait, &dwSize);
  198. // Create the stress object and add it to the array
  199. CBasicRefreshAgent *pAgent = new CBasicRefreshAgent;
  200. pAgent->Create(pRef, dwIterations, dwWait, m_hRefreshEvent);
  201. m_apAgent.Add(pAgent);
  202. return TRUE;
  203. }
  204. BOOL CRefTreeMain::Go()
  205. ////////////////////////////////////////////////////////////////////
  206. //
  207. // Print the refresher tree with all of the object parameters
  208. // and values. Start the threads, wait for them all to terminate,
  209. // and then print out the refresher tree and parameters again.
  210. //
  211. ////////////////////////////////////////////////////////////////////
  212. {
  213. DumpTree();
  214. printf("\nStressing...");
  215. DWORD dwFinish,
  216. dwStart = GetTickCount();
  217. for (int i = 0; i < m_apAgent.GetSize(); i++)
  218. m_apAgent[i]->BeginStress();
  219. WaitForSingleObject(m_hRefreshEvent, INFINITE);
  220. dwFinish = GetTickCount();
  221. printf("Done Stressing.\n\n\n");
  222. DumpTree();
  223. DumpStats(dwFinish - dwStart);
  224. return TRUE;
  225. }
  226. void CRefTreeMain::DumpTree()
  227. {
  228. for (int i = 0; i < m_apRootRef.GetSize(); i++)
  229. {
  230. WCHAR wcsPrefix[16];
  231. if (i < (m_apRootRef.GetSize() - 1))
  232. wcscpy(wcsPrefix, L"|");
  233. else
  234. wcscpy(wcsPrefix, L" ");
  235. m_apRootRef[i]->DumpTree(wcsPrefix);
  236. printf("%S\n", wcsPrefix);
  237. }
  238. }
  239. void CRefTreeMain::DumpStats(DWORD dwDelta)
  240. {
  241. printf("\n\n\n");
  242. printf(" Refresh Stats\n");
  243. printf("==========================================================================\n");
  244. printf(" Elapsed Time: %d msec\n", dwDelta);
  245. printf("==========================================================================\n\n\n");
  246. for (int i = 0; i < m_apRootRef.GetSize(); i++)
  247. m_apRootRef[i]->DumpStats();
  248. printf("\n\n");
  249. }
  250. ///////////////////////////////////////////////////////////////////
  251. //
  252. // CRefTreeMain
  253. //
  254. ///////////////////////////////////////////////////////////////////
  255. CPoundMain::CPoundMain(long lNumRefs)
  256. {
  257. m_lNumRefs = lNumRefs;
  258. }
  259. CPoundMain::~CPoundMain()
  260. {
  261. }
  262. BOOL CPoundMain::Create()
  263. {
  264. CMain::Create();
  265. return TRUE;
  266. }
  267. BOOL CPoundMain::Go()
  268. {
  269. return TRUE;
  270. }