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.

237 lines
7.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: perftest.cpp
  8. //
  9. // Contents: performance suite
  10. //
  11. // History: 04-Dec-1997 pberkman created
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "global.hxx"
  15. DWORD dwTotal = 0;
  16. DWORD dwExpectedError = 0;
  17. DWORD cPasses = 1;
  18. BOOL fCheckExpectedError = FALSE;
  19. BOOL fVerbose = FALSE;
  20. WCHAR *pwszInFile = NULL;
  21. GUID gAuthCode = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  22. GUID gDriver = DRIVER_ACTION_VERIFY;
  23. GUID gCertProvider = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  24. HANDLE *pahThreads = NULL;
  25. DWORD cThreads = 1;
  26. ThreadData *pasThreads = NULL;
  27. extern "C" int __cdecl wmain(int argc, WCHAR **wargv)
  28. {
  29. int iRet;
  30. cWArgv_ *pArgs;
  31. BOOL fFailed;
  32. COleDateTime tStart;
  33. COleDateTime tEnd;
  34. COleDateTimeSpan tsTotal;
  35. PFN_TEST pfnTest;
  36. DWORD i;
  37. iRet = 0;
  38. pfnTest = NULL;
  39. if (!(pArgs = new cWArgv_((HINSTANCE)GetModuleHandle(NULL), &fFailed)))
  40. {
  41. goto MemoryError;
  42. }
  43. if (fFailed)
  44. {
  45. goto MemoryError;
  46. }
  47. pArgs->AddUsageText(IDS_USAGETEXT_USAGE, IDS_USAGETEXT_OPTIONS,
  48. IDS_USAGETEXT_CMDFILE, IDS_USAGETEXT_ADD,
  49. IDS_USAGETEXT_OPTPARAM);
  50. pArgs->Add2List(IDS_PARAM_HELP, IDS_PARAMTEXT_HELP, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  51. pArgs->Add2List(IDS_PARAM_VERBOSE, IDS_PARAMTEXT_VERBOSE, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  52. pArgs->Add2List(IDS_PARAM_EXPERROR, IDS_PARAMTEXT_EXPERROR, WARGV_VALUETYPE_DWORDH, (void *)0);
  53. pArgs->Add2List(IDS_PARAM_NOTHREADS,IDS_PARAMTEXT_NOTHREADS,WARGV_VALUETYPE_DWORDD, (void *)1);
  54. pArgs->Add2List(IDS_PARAM_NOPASSES, IDS_PARAMTEXT_NOPASSES, WARGV_VALUETYPE_DWORDD, (void *)2);
  55. pArgs->Add2List(IDS_PARAM_WVTCAT, IDS_PARAMTEXT_WVTCAT, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  56. pArgs->Add2List(IDS_PARAM_WVTCERT, IDS_PARAMTEXT_WVTCERT, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  57. pArgs->Add2List(IDS_PARAM_WVTFILE, IDS_PARAMTEXT_WVTFILE, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  58. pArgs->Add2List(IDS_PARAM_CATADD, IDS_PARAMTEXT_CATADD, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  59. pArgs->Add2List(IDS_PARAM_CRYPTHASH,IDS_PARAMTEXT_CRYPTHASH,WARGV_VALUETYPE_BOOL, (void *)FALSE);
  60. pArgs->Add2List(IDS_PARAM_HASHSHA1, IDS_PARAMTEXT_HASHSHA1, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  61. pArgs->Fill(argc, wargv);
  62. if (!(pArgs->Fill(argc, wargv)) ||
  63. (pArgs->GetValue(IDS_PARAM_HELP)))
  64. {
  65. wprintf(L"%s\n", pArgs->GetUsageString());
  66. goto NeededHelp;
  67. }
  68. pwszInFile = pArgs->GetFileName();
  69. fVerbose = (BOOL)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_VERBOSE));
  70. cThreads = (DWORD)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_NOTHREADS));
  71. cPasses = (DWORD)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_NOPASSES));
  72. if (!(pwszInFile))
  73. {
  74. pwszInFile = L"*.*";
  75. }
  76. if (pArgs->IsSet(IDS_PARAM_EXPERROR))
  77. {
  78. dwExpectedError = (DWORD)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_EXPERROR));
  79. fCheckExpectedError = TRUE;
  80. }
  81. if (cThreads < 1)
  82. {
  83. wprintf(L"%s\n", pArgs->GetUsageString());
  84. goto NeededHelp;
  85. }
  86. if (!(pasThreads = new ThreadData[cThreads]))
  87. {
  88. goto MemoryError;
  89. }
  90. if (!(pahThreads = new HANDLE[cThreads]))
  91. {
  92. goto MemoryError;
  93. }
  94. memset(pasThreads, 0x00, sizeof(ThreadData) * cThreads);
  95. if (pArgs->GetValue(IDS_PARAM_WVTCAT))
  96. {
  97. pfnTest = TestWVTCat;
  98. }
  99. else if (pArgs->GetValue(IDS_PARAM_WVTCERT))
  100. {
  101. pfnTest = TestWVTCert;
  102. }
  103. else if (pArgs->GetValue(IDS_PARAM_WVTFILE))
  104. {
  105. pfnTest = TestWVTFile;
  106. }
  107. else if (pArgs->GetValue(IDS_PARAM_CATADD))
  108. {
  109. pfnTest = TestCatAdd;
  110. }
  111. else if (pArgs->GetValue(IDS_PARAM_CRYPTHASH))
  112. {
  113. pfnTest = TestCryptHash;
  114. if (pArgs->GetValue(IDS_PARAM_HASHSHA1))
  115. {
  116. for (i = 0; i < cThreads; i++)
  117. {
  118. pasThreads[i].dwPassThrough = PASSTHROUGH_SHA1;
  119. }
  120. }
  121. }
  122. if (!(pfnTest))
  123. {
  124. wprintf(L"%s\n", pArgs->GetUsageString());
  125. goto NeededHelp;
  126. }
  127. for (i = 0; i < cThreads; i++)
  128. {
  129. pasThreads[i].hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)pfnTest,
  130. &pasThreads[i], CREATE_SUSPENDED, &pasThreads[i].dwId);
  131. if (!(pasThreads[i].hThread))
  132. {
  133. goto CreateThreadFailed;
  134. }
  135. pahThreads[i] = pasThreads[i].hThread;
  136. }
  137. //
  138. // start our timer
  139. //
  140. tStart = COleDateTime::GetCurrentTime();
  141. for (i = 0; i < cThreads; i++)
  142. {
  143. ResumeThread(pasThreads[i].hThread);
  144. }
  145. //
  146. // wait to finish
  147. //
  148. WaitForMultipleObjects(cThreads, pahThreads, TRUE, INFINITE);
  149. //
  150. // stop our timer
  151. //
  152. tEnd = COleDateTime::GetCurrentTime();
  153. tsTotal = tEnd - tStart;
  154. for (i = 0; i < cThreads; i++)
  155. {
  156. dwTotal += pasThreads[i].dwTotalProcessed;
  157. printf("\nThread #%d:", i + 1);
  158. printf("\n Processing time: %s", (LPCSTR)pasThreads[i].tsTotal.Format("%D:%H:%M:%S"));
  159. printf("\n Total processed: %ld", pasThreads[i].dwTotalProcessed);
  160. printf("\n Average seconds per: %f", (double)pasThreads[i].tsTotal.GetTotalSeconds() /
  161. (double)pasThreads[i].dwTotalProcessed);
  162. }
  163. printf("\nOverall:");
  164. printf("\n Processing time: %s", (LPCSTR)tsTotal.Format("%D:%H:%M:%S"));
  165. printf("\n Total processed: %ld", dwTotal);
  166. printf("\n Average seconds per: %f", (double)tsTotal.GetTotalSeconds() / (double)dwTotal);
  167. printf("\n");
  168. iRet = 0;
  169. CommonReturn:
  170. if (pasThreads)
  171. {
  172. for (i = 0; i < cThreads; i++)
  173. {
  174. if (pasThreads[i].hThread)
  175. {
  176. CloseHandle(pasThreads[i].hThread);
  177. }
  178. }
  179. delete pasThreads;
  180. }
  181. DELETE_OBJECT(pArgs);
  182. DELETE_OBJECT(pahThreads);
  183. return(iRet);
  184. ErrorReturn:
  185. iRet = 1;
  186. goto CommonReturn;
  187. TRACE_ERROR_EX(DBG_SS_APP, MemoryError);
  188. TRACE_ERROR_EX(DBG_SS_APP, NeededHelp);
  189. TRACE_ERROR_EX(DBG_SS_APP, CreateThreadFailed);
  190. }