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.

474 lines
10 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bmoutput.cxx
  7. //
  8. // Contents: output class for benchmark results
  9. //
  10. // Classes: CTestOutput
  11. //
  12. // Functions:
  13. //
  14. // History: 30-June-93 t-martig Created
  15. // 15-Aug-94 davidfie Make ASCII/Unicode for chicago
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <benchmrk.hxx>
  19. #include <bmoutput.hxx>
  20. //+-------------------------------------------------------------------
  21. //
  22. // Member: CTestOutput::CTestOutput, public
  23. //
  24. // Synopsis: Generates output file
  25. //
  26. // History: 30-June-93 t-martig Created
  27. //
  28. //--------------------------------------------------------------------
  29. CTestOutput::CTestOutput (LPTSTR lpszFileName)
  30. {
  31. #ifdef UNICODE
  32. char szFileName[80];
  33. wcstombs (szFileName, lpszFileName, wcslen(lpszFileName)+1);
  34. fpOut = fopen (szFileName, "wt");
  35. #else
  36. fpOut = fopen (lpszFileName, "wt");
  37. #endif
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: CTestOutput::~CTestOutput, public
  42. //
  43. // Synopsis: Closes output file
  44. //
  45. // History: 30-June-93 t-martig Created
  46. //
  47. //--------------------------------------------------------------------
  48. CTestOutput::~CTestOutput ()
  49. {
  50. if (fpOut)
  51. fclose (fpOut);
  52. }
  53. //+-------------------------------------------------------------------
  54. //
  55. // Member: CTestOutput::Flush, public
  56. //
  57. // Synopsis: flushes the buffers associated with the output file
  58. //
  59. // History: 30-June-93 t-martig Created
  60. //
  61. //--------------------------------------------------------------------
  62. void CTestOutput::Flush(void)
  63. {
  64. fflush (fpOut);
  65. }
  66. //+-------------------------------------------------------------------
  67. //
  68. // Member: CTestOutput::WriteTextString, public
  69. //
  70. // Synopsis: Writes a TEXT format string to output file
  71. //
  72. // Parameters: [lpswzString] String to be printed
  73. //
  74. // History: 30-June-93 t-martig Created
  75. //
  76. //--------------------------------------------------------------------
  77. void CTestOutput::WriteTextString (LPTSTR lpszString)
  78. {
  79. WriteString(lpszString);
  80. }
  81. //+-------------------------------------------------------------------
  82. //
  83. // Member: CTestOutput::WriteString, public
  84. //
  85. // Synopsis: Writes string to output file
  86. //
  87. // Parameters: [lpszString] String to be printed
  88. //
  89. // History: 30-June-93 t-martig Created
  90. //
  91. //--------------------------------------------------------------------
  92. void CTestOutput::WriteString (LPTSTR lpszString)
  93. {
  94. #ifdef UNICODE
  95. char *fmt = "%ws";
  96. #else
  97. char *fmt = "%s";
  98. #endif
  99. if (!fpOut)
  100. return;
  101. fprintf (fpOut, fmt, lpszString);
  102. }
  103. //+-------------------------------------------------------------------
  104. //
  105. // Member: CTestOutput::WriteLong, public
  106. //
  107. // Synopsis: Writes long to output file
  108. //
  109. // Parameters: [lpswzString] String to be printed
  110. //
  111. // History: 30-June-93 t-martig Created
  112. //
  113. //--------------------------------------------------------------------
  114. void CTestOutput::WriteLong (ULONG l)
  115. {
  116. if (!fpOut)
  117. return;
  118. fprintf (fpOut, "%lu", l);
  119. }
  120. //+-------------------------------------------------------------------
  121. //
  122. // Member: CTestOutput::WriteConfigEntry, public
  123. //
  124. // Synopsis: Writes string from config file to output file
  125. //
  126. // Parameters: [input] Input class (config file)
  127. // [lpszSection] Section name of entry to be printed
  128. // [lpszEntry] Entry name to be printed
  129. // [lpszDefault] Default string in case entry does
  130. // not exist
  131. //
  132. // History: 30-June-93 t-martig Created
  133. //
  134. //--------------------------------------------------------------------
  135. void CTestOutput::WriteConfigEntry (CTestInput &input, LPTSTR lpszSection,
  136. LPTSTR lpszEntry, LPTSTR lpszDefault)
  137. {
  138. TCHAR destName[160];
  139. if (!fpOut)
  140. return;
  141. input.GetConfigString (lpszSection, lpszEntry, lpszDefault,
  142. destName, sizeof(destName)/sizeof(TCHAR));
  143. WriteString (destName);
  144. }
  145. //+-------------------------------------------------------------------
  146. //
  147. // Member: CTestOutput::WriteSectionHeader, public
  148. //
  149. // Synopsis: Writes general test section header to output file
  150. //
  151. // Parameters: [lpszTestName] General test name (from
  152. // [TestClass].Name(),like "OLE")
  153. // [lpszSectionName] Specific test name (like
  154. // "Object Bind Test")
  155. // [input] .ini file class
  156. //
  157. // History: 30-June-93 t-martig Created
  158. //
  159. //--------------------------------------------------------------------
  160. void CTestOutput::WriteSectionHeader (LPTSTR lpszTestName,
  161. LPTSTR lpszSectionName, CTestInput &input)
  162. {
  163. if (!fpOut)
  164. return;
  165. if (!lpszSectionName)
  166. lpszSectionName = TEXT("");
  167. if (g_fFullInfo)
  168. {
  169. #ifdef UNICODE
  170. char *fmt = "\n\n%ws - %ws\n\nComments:\t";
  171. #else
  172. char *fmt = "\n\n%s - %s\n\nComments:\t";
  173. #endif
  174. // we conditionally skip writing the comment to make it
  175. // easier to format for excel.
  176. fprintf (fpOut, fmt, lpszTestName, lpszSectionName);
  177. WriteConfigEntry (input, lpszTestName, TEXT("comment"));
  178. fprintf (fpOut, "\n");
  179. }
  180. else
  181. {
  182. #ifdef UNICODE
  183. char *fmt = "\n\n%ws\n";
  184. #else
  185. char *fmt = "\n\n%s\n";
  186. #endif
  187. fprintf (fpOut, fmt, lpszSectionName);
  188. }
  189. }
  190. //+-------------------------------------------------------------------
  191. //
  192. // Member: CTestOutput::WriteResult, public
  193. //
  194. // Synopsis: Writes test result line to output file, in the form
  195. // "Create moniker <tab> 30800"
  196. //
  197. // Parameters: [lpszMeasurementName] Name of result (like
  198. // "Create moniker"
  199. // [ulTime] Measured time in microseconds
  200. //
  201. // History: 30-June-93 t-martig Created
  202. //
  203. //--------------------------------------------------------------------
  204. void CTestOutput::WriteResult (LPTSTR lpszMeasurementName, ULONG ulTime)
  205. {
  206. if (fpOut)
  207. {
  208. WriteString (lpszMeasurementName);
  209. fprintf (fpOut, "\t");
  210. if (ulTime == NOTAVAIL)
  211. {
  212. fprintf (fpOut, "n/a\n");
  213. }
  214. else if (ulTime == TEST_FAILED)
  215. {
  216. fprintf (fpOut, "F\n");
  217. }
  218. else
  219. {
  220. fprintf (fpOut, "%lu\n", ulTime);
  221. }
  222. }
  223. }
  224. //+-------------------------------------------------------------------
  225. //
  226. // Member: CTestOutput::WriteResult, public
  227. //
  228. // Synopsis: Writes test results over several columns
  229. //
  230. // Parameters: [lpszMeasurementName] Name of result (like
  231. // "Create moniker"
  232. // [iIterations] Number of results
  233. // [paUlTime] Array with measurement times
  234. //
  235. // History: 30-June-93 t-martig Created
  236. //
  237. //--------------------------------------------------------------------
  238. void CTestOutput::WriteResults (LPTSTR lpszMeasurementName, int iIterations,
  239. ULONG *paUlTimes)
  240. {
  241. int i;
  242. if (fpOut)
  243. {
  244. WriteString (lpszMeasurementName);
  245. for (i=0; i<iIterations; i++)
  246. {
  247. if (paUlTimes[i] == NOTAVAIL)
  248. {
  249. fprintf (fpOut, "\tn/a");
  250. }
  251. else if (paUlTimes[i] == TEST_FAILED)
  252. {
  253. fprintf (fpOut, "\tF");
  254. }
  255. else
  256. {
  257. fprintf (fpOut, "\t%lu", paUlTimes[i]);
  258. }
  259. }
  260. fprintf (fpOut, "\n");
  261. }
  262. }
  263. //+-------------------------------------------------------------------
  264. //
  265. // Member: WriteClassCtx, public
  266. //
  267. // Synopsis: Prints the class activation conL as string to
  268. // a specified output class
  269. //
  270. // Parameters: [dwClsCtx] Class conL to be printed
  271. //
  272. // CLSCTX_INPROC_SERVER --> "InProc"
  273. // CLSCTX_LOCAL_SERVER --> "LocaL"
  274. // CLSCTX_INPROC_HANDLER --> "Handler"
  275. // any other --> "Unknown"
  276. //
  277. // History: 12-July-93 t-martig Created
  278. //
  279. //--------------------------------------------------------------------
  280. void CTestOutput::WriteClassCtx (DWORD dwClsCtx)
  281. {
  282. LPTSTR pc = TEXT("Unknown");
  283. int i = 0;
  284. while (saModeNames[i])
  285. {
  286. if (dwaModes[i] == dwClsCtx)
  287. {
  288. pc = saModeNames[i];
  289. break;
  290. }
  291. i++;
  292. }
  293. WriteString (TEXT("ClsCtx\t"));
  294. WriteString (pc);
  295. WriteString (TEXT("\n"));
  296. }
  297. //+-------------------------------------------------------------------
  298. //
  299. // Member: WriteClassID
  300. //
  301. // Synopsis: Prints the class ID as string to
  302. // a specified output class
  303. //
  304. // Parameters: [pClsID] Class ID to be printed
  305. //
  306. // History: 13-July-93 t-martig Created
  307. //
  308. //--------------------------------------------------------------------
  309. void CTestOutput::WriteClassID (CLSID *pClsID)
  310. {
  311. if (g_fFullInfo)
  312. {
  313. TCHAR szGUID[50];
  314. WriteString (TEXT("ClsID\t"));
  315. StringFromGUID(*pClsID, szGUID);
  316. WriteString (szGUID);
  317. WriteString (TEXT("\n"));
  318. }
  319. }
  320. //+-------------------------------------------------------------------
  321. //
  322. // Member: WriteTime
  323. //
  324. // Synopsis: Prints time to a specified output class
  325. //
  326. // Parameters: [pstTime] System time
  327. //
  328. // History: 5-August-93 t-martig Created
  329. //
  330. //--------------------------------------------------------------------
  331. void CTestOutput::WriteTime (_SYSTEMTIME *pstTime)
  332. {
  333. WORD wHour;
  334. char cAmpm;
  335. if (fpOut)
  336. {
  337. cAmpm = 'a';
  338. wHour = pstTime->wHour;
  339. if (wHour >= 12)
  340. {
  341. cAmpm = 'p';
  342. if (wHour > 12)
  343. wHour-=12;
  344. }
  345. if (wHour==0)
  346. wHour=12;
  347. fprintf (fpOut, "%d:%02d%c", wHour, pstTime->wMinute, cAmpm);
  348. }
  349. }
  350. //+-------------------------------------------------------------------
  351. //
  352. // Member: WriteDate
  353. //
  354. // Synopsis: Prints date to a specified output class
  355. //
  356. // Parameters: [pstdate] System date
  357. //
  358. // History: 5-August-93 t-martig Created
  359. //
  360. //--------------------------------------------------------------------
  361. void CTestOutput::WriteDate (_SYSTEMTIME *pstDate)
  362. {
  363. if (fpOut)
  364. {
  365. fprintf (fpOut, "%02d-%02d-%02d",
  366. pstDate->wMonth, pstDate->wDay, pstDate->wYear % 100);
  367. }
  368. }
  369. //+-------------------------------------------------------------------
  370. //
  371. // Member: WriteSCODE
  372. //
  373. // Synopsis: Prints an SCODE to a specified output class
  374. //
  375. // Parameters: [sc] SCODE
  376. //
  377. // History: 5-August-93 t-martig Created
  378. //
  379. //--------------------------------------------------------------------
  380. void CTestOutput::WriteSCODE (SCODE sc)
  381. {
  382. if (fpOut)
  383. fprintf (fpOut, "%xh/%xh", SCODE_FACILITY(sc), SCODE_CODE(sc));
  384. }
  385. //+-------------------------------------------------------------------
  386. //
  387. // Member: StringFromGUID
  388. //
  389. // Synopsis: converts a GUID into a string so that it may be
  390. // printed to a specified output class
  391. //
  392. // Parameters: [pClsID] Class ID to be printed
  393. //
  394. // History: 13-July-93 t-martig Created
  395. //
  396. //--------------------------------------------------------------------
  397. void CTestOutput::StringFromGUID(GUID &rguid, LPTSTR lpsz)
  398. {
  399. wsprintf(lpsz, TEXT("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
  400. rguid.Data1, rguid.Data2, rguid.Data3,
  401. rguid.Data4[0], rguid.Data4[1],
  402. rguid.Data4[2], rguid.Data4[3],
  403. rguid.Data4[4], rguid.Data4[5],
  404. rguid.Data4[6], rguid.Data4[7]);
  405. }