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.

242 lines
8.9 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: stats.cpp
  4. //
  5. // History: 20-Dec-00 markder Ported from v1.
  6. //
  7. // Desc: This file contains statistic dumping routines.
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////
  10. #include "stdafx.h"
  11. #include "globals.h"
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Func: DumpVerboseStats
  15. //
  16. // Desc: Dumps out info about layer coverage and a shim cross-reference
  17. //
  18. VOID DumpVerboseStats(SdbDatabase* pDatabase, BOOL bSummary)
  19. {
  20. int i, j, k, l, m;
  21. DWORD dwTotal = 0;
  22. // start by listing the how many exes would be fixed
  23. // by each layer in the DB
  24. // initialize the SEEN flag for exes
  25. for (i = 0; i < pDatabase->m_rgExes.GetSize(); i++) {
  26. ((SdbExe *)pDatabase->m_rgExes[i])->m_bSeen = FALSE;
  27. }
  28. for (k = 0; k < pDatabase->m_Library.m_rgLayers.GetSize(); k++) {
  29. SdbLayer *pLayer = (SdbLayer *) pDatabase->m_Library.m_rgLayers[k];
  30. DWORD dwExesFixedByLayer = 0;
  31. Print(_T("========================================\n"));
  32. if (!bSummary) {
  33. Print(_T("Exe entries fixed by shims from layer \"%s\":\n\n"), pLayer->m_csName);
  34. }
  35. for (i = 0; i < pDatabase->m_rgExes.GetSize(); i++) {
  36. SdbExe *pExe = (SdbExe *)pDatabase->m_rgExes[i];
  37. if (!pExe->m_rgShimRefs.GetSize()) {
  38. // this has no shims and isn't a fix entry, or doesn't use shims to fix
  39. goto nextExe;
  40. }
  41. for (j = 0; j < pExe->m_rgShimRefs.GetSize(); j++) {
  42. SdbShimRef *pShimRef = (SdbShimRef *) pExe->m_rgShimRefs[j];
  43. for (l = 0; l < pLayer->m_rgShimRefs.GetSize(); l++) {
  44. SdbShimRef *pLayerShimRef = (SdbShimRef *) pLayer->m_rgShimRefs[l];
  45. if (pLayerShimRef->m_pShim == pShimRef->m_pShim) {
  46. goto nextShim;
  47. }
  48. }
  49. // if we didn't find the shim in any layer, this isn't fixed by
  50. // a layer, and we can try the next EXE
  51. goto nextExe;
  52. nextShim:
  53. ;
  54. }
  55. // we got all the way through all the shim entries, now check
  56. // if there are any patches. If so, this couldn't be fixed
  57. // by a layer anyhow. And if it's been seen, don't bother
  58. // reporting it again.
  59. if (!pExe->m_rgPatches.GetSize() && !pExe->m_bSeen) {
  60. pExe->m_bSeen = TRUE;
  61. if (!bSummary) {
  62. Print(_T(" Exe \"%s,\" App \"%s.\"\n"), pExe->m_csName, pExe->m_pApp->m_csName);
  63. }
  64. dwExesFixedByLayer++;
  65. }
  66. nextExe:
  67. ;
  68. }
  69. Print(_T("\nTotal exes fixed by shims contained in Layer \"%s\": %d\n"),
  70. pLayer->m_csName, dwExesFixedByLayer);
  71. Print(_T("Total exes in DB: %d\n"), pDatabase->m_rgExes.GetSize());
  72. Print(_T("Percentage of exes fixed by layer \"%s\": %.1f%%\n\n"),
  73. pLayer->m_csName, (double)dwExesFixedByLayer * 100.0 / pDatabase->m_rgExes.GetSize());
  74. dwTotal += dwExesFixedByLayer;
  75. }
  76. Print(_T("========================================\n"));
  77. Print(_T("\nTotal exes fixed by shims contained in ANY layer: %d\n"),
  78. dwTotal);
  79. Print(_T("Total exes in DB: %d\n"), pDatabase->m_rgExes.GetSize());
  80. Print(_T("Percentage of exes fixed by ANY layer: %.1f%%\n\n"),
  81. (double)dwTotal * 100.0 / pDatabase->m_rgExes.GetSize());
  82. // now check entire apps to see if they are fixed by any layers
  83. // initialize the SEEN flag for Apps
  84. for (i = 0; i < pDatabase->m_rgApps.GetSize(); i++) {
  85. ((SdbApp *)pDatabase->m_rgApps[i])->m_bSeen = FALSE;
  86. }
  87. dwTotal = 0;
  88. for (k = 0; k < pDatabase->m_Library.m_rgLayers.GetSize(); k++) {
  89. SdbLayer *pLayer = (SdbLayer *) pDatabase->m_Library.m_rgLayers[k];
  90. DWORD dwAppsFixedByLayer = 0;
  91. Print(_T("========================================\n"));
  92. if (!bSummary) {
  93. Print(_T("App entries fixed by only shims from layer \"%s\":\n\n"), pLayer->m_csName);
  94. }
  95. for (m = 0; m < pDatabase->m_rgApps.GetSize(); ++m) {
  96. SdbApp *pApp = (SdbApp *)pDatabase->m_rgApps[m];
  97. for (i = 0; i < pApp->m_rgExes.GetSize(); i++) {
  98. SdbExe *pExe = (SdbExe *)pApp->m_rgExes[i];
  99. if (!pExe->m_rgShimRefs.GetSize()) {
  100. // this has no shims and isn't a fix entry, or doesn't use shims to fix
  101. goto nextApp2;
  102. }
  103. for (j = 0; j < pExe->m_rgShimRefs.GetSize(); j++) {
  104. SdbShimRef *pShimRef = (SdbShimRef *) pExe->m_rgShimRefs[j];
  105. BOOL bShimInLayer = FALSE;
  106. for (l = 0; l < pLayer->m_rgShimRefs.GetSize(); l++) {
  107. SdbShimRef *pLayerShimRef = (SdbShimRef *) pLayer->m_rgShimRefs[l];
  108. if (pLayerShimRef->m_pShim == pShimRef->m_pShim) {
  109. bShimInLayer = TRUE;
  110. goto nextShim2;
  111. }
  112. }
  113. // if we didn't find the shim in any layer, this isn't fixed by
  114. // a layer, and we can try the next APP
  115. if (!bShimInLayer) {
  116. goto nextApp2;
  117. }
  118. nextShim2:
  119. ;
  120. }
  121. // we got all the way through all the shim entries, now check
  122. // if there are any patches. If so, this couldn't be fixed
  123. // by a layer anyhow.
  124. if (pExe->m_rgPatches.GetSize()) {
  125. goto nextApp2;
  126. }
  127. }
  128. // well, we got all the way through the exes, and they were all
  129. // fixed, so count this one.
  130. if (!pApp->m_bSeen) {
  131. dwAppsFixedByLayer++;
  132. pApp->m_bSeen = TRUE;
  133. if (!bSummary) {
  134. Print(_T(" App \"%s.\"\n"), pApp->m_csName);
  135. }
  136. }
  137. nextApp2:
  138. ;
  139. }
  140. Print(_T("\nTotal apps fixed by shims contained in Layer \"%s\": %d\n"),
  141. pLayer->m_csName, dwAppsFixedByLayer);
  142. Print(_T("Total apps in DB: %d\n"), pDatabase->m_rgApps.GetSize());
  143. Print(_T("Percentage of apps fixed by layer \"%s\": %.1f%%\n\n"),
  144. pLayer->m_csName, (double)dwAppsFixedByLayer * 100.0 / pDatabase->m_rgApps.GetSize());
  145. dwTotal += dwAppsFixedByLayer;
  146. }
  147. Print(_T("========================================\n"));
  148. Print(_T("\nTotal apps fixed by shims contained in ANY layer: %d\n"),
  149. dwTotal);
  150. Print(_T("Total apps in DB: %d\n"), pDatabase->m_rgApps.GetSize());
  151. Print(_T("Percentage of apps fixed by ANY layer: %.1f%%\n\n"),
  152. (double)dwTotal * 100.0 / pDatabase->m_rgApps.GetSize());
  153. // Now do a cross reference of shims to apps and exes.
  154. Print(_T("\n========================================\n"));
  155. Print(_T("Cross Reference of Shims to Apps & Exes\n"));
  156. for (i = 0; i < pDatabase->m_Library.m_rgShims.GetSize(); ++i) {
  157. SdbShim *pShim = (SdbShim *)pDatabase->m_Library.m_rgShims[i];
  158. DWORD dwExes = 0;
  159. DWORD dwApps = 0;
  160. TCHAR *szAppEnd = _T("s");
  161. TCHAR *szExeEnd = _T("s");
  162. Print(_T("\n----------------------------------------\n"));
  163. Print(_T("shim \"%s\":\n"), pShim->m_csName);
  164. for (j = 0; j < pDatabase->m_rgApps.GetSize(); ++j) {
  165. SdbApp *pApp = (SdbApp*)pDatabase->m_rgApps[j];
  166. BOOL bPrintedApp = FALSE;
  167. for (k = 0; k < pApp->m_rgExes.GetSize(); ++k) {
  168. SdbExe *pExe = (SdbExe*)pApp->m_rgExes[k];
  169. for (l = 0; l < pExe->m_rgShimRefs.GetSize(); ++l) {
  170. SdbShimRef *pShimRef = (SdbShimRef*)pExe->m_rgShimRefs[l];
  171. if (pShimRef->m_pShim == pShim) {
  172. if (!bPrintedApp) {
  173. if (!bSummary) {
  174. Print(_T("\n App \"%s\"\n"), pApp->m_csName);
  175. }
  176. bPrintedApp = TRUE;
  177. dwApps++;
  178. }
  179. if (!bSummary) {
  180. Print(_T(" Exe \"%s\"\n"), pExe->m_csName);
  181. }
  182. dwExes++;
  183. }
  184. }
  185. }
  186. }
  187. if (dwApps == 1) {
  188. szAppEnd = _T("");
  189. }
  190. if (dwExes == 1) {
  191. szExeEnd = _T("");
  192. }
  193. Print(_T("\nTotals for shim \"%s\": %d App%s, %d Exe%s.\n"),
  194. pShim->m_csName, dwApps, szAppEnd, dwExes, szExeEnd);
  195. }
  196. }