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.

239 lines
7.2 KiB

  1. ###################################################################################
  2. # #
  3. # Copyright (c) 1989-1999 Microsoft Corporation #
  4. # #
  5. # Module Name: #
  6. # #
  7. # unioninfo.pl #
  8. # #
  9. # Abstract: #
  10. # #
  11. # Computes statistics from MIDL union instrumentation. #
  12. # #
  13. # Notes: #
  14. # To use this module, build MIDL with the define DUMP_UNION_INFO set. Run #
  15. # MIDL and a file named c:\unioninfo.log will be produced. Run this perl #
  16. # script on the output to compute usefull statistics. #
  17. # #
  18. # History: #
  19. # #
  20. # Oct-11-99 mzoran Created. #
  21. # #
  22. # #
  23. ###################################################################################
  24. $RemoveDuplicateSymbols = 1;
  25. @thresholds = (1.0, 1.25, 1.50, 1.75, 2.0, 3.0, 4.0);
  26. @densevalues = (0, 0, 0, 0, 0, 0, 0 );
  27. $NUMBERTHRESHOLDS = 7;
  28. @armthresholds = (5, 6, 7, 8, 9);
  29. $NUMBERARMTHRESHOLDS = 5;
  30. $NumUnions = 0;
  31. @UnionList;
  32. $TotalNonDefaultArms = 0;
  33. $UnionsWithDefault = 0;
  34. %UnionTypes = (
  35. "Union_Unknown" => 0,
  36. "Union_Encap" => 0,
  37. "Union_NonEncap_DCE" => 0,
  38. "Union_NonEncap_MS" => 0,
  39. "Unknown" => 0
  40. );
  41. @
  42. $MinArms = 100000000;
  43. $MaxArms = 0;
  44. while($line = <STDIN>) {
  45. $line =~ s/,|\(|\)/ /g;
  46. $header = "";
  47. $environ = "";
  48. $filename = "";
  49. $symbol = "";
  50. $typesym = "";
  51. $Arms = 1;
  52. ($header,$environ,$trash,$filename,$trash,
  53. $symbol,$trash,$trash,$typesym,$trash,$Arms) = split(/\s+|\n$/,$line);
  54. $trash = 0;
  55. #
  56. # Every valid union block begins with a * and ends with a +
  57. #
  58. if ($header eq "*") {
  59. # Skip duplicate symbols
  60. if (!($environ == 32)
  61. || ($RemoveDuplicateSymbols && exists($UnionNames{$filename.$symbol}))) {
  62. $DontCount = 1;
  63. }
  64. else {
  65. $DontCount = 0;
  66. }
  67. $LocalHasDefault = 0;
  68. $FirstArmValue = 1;
  69. $MinArmValue = 0;
  70. $MaxArmValue = 0;
  71. $UnionNames{$filename.$symbol} = 1;
  72. # process the union arms
  73. while($line = <STDIN>) {
  74. ($ArmValue) = split(/\s+/,$line);
  75. if ($ArmValue eq "+") {
  76. last;
  77. }
  78. if($ArmValue eq "DEFAULT") {
  79. $LocalHasDefault = 1;
  80. }
  81. else {
  82. if ($FirstArmValue == 1) {
  83. $MaxArmValue = $ArmValue;
  84. $MinArmValue = $ArmValue;
  85. $FirstArmValue = 0;
  86. }
  87. else {
  88. if($ArmValue > $MaxArmValue) {
  89. $MaxArmValue = $ArmValue;
  90. }
  91. if($ArmValue < $MinArmValue) {
  92. $MinArmValue = $ArmValue;
  93. }
  94. }
  95. }
  96. }
  97. if (!$DontCount) {
  98. $NumUnions++;
  99. $TotalNonDefaultArms += $Arms;
  100. $UnionsWithDefault += $LocalHasDefault;
  101. $UnionTypes{$typesym}++;
  102. if ($Arms < $MinArms) {
  103. $MinArms = $Arms;
  104. }
  105. if ($Arms > $MaxArms) {
  106. $MaxArms = $Arms;
  107. }
  108. push (@UnionList, ($Arms, $MinArmValue, $MaxArmValue));
  109. }
  110. }
  111. }
  112. if ($RemoveDuplicateSymbols)
  113. {
  114. print("Union Statistics(Each type is counted once.)\n");
  115. }
  116. else
  117. {
  118. print("Union Statistics(Each usage in the generated format strings is counted before optimization.)\n");
  119. }
  120. print("\n");
  121. print("Number of unions: $NumUnions \n");
  122. foreach $i (keys(%UnionTypes)) {
  123. $name = $i;
  124. $number = $UnionTypes{$i};
  125. $percentage = (($number/$NumUnions) * 100)."%";
  126. print("$name: $number ($percentage)\n");
  127. }
  128. print("\n");
  129. print("Arm statistics:\n");
  130. $percentage = (($UnionsWithDefault / $NumUnions) * 100)."%";
  131. print("Unions with default: $UnionsWithDefault ($percentage)\n");
  132. print("Minimum arms: $MinArms \n");
  133. print("Maximum arms: $MaxArms \n");
  134. print("Average arms: ".$TotalNonDefaultArms/$NumUnions."\n");
  135. print("\n");
  136. $numbuckets = 20;
  137. @Buckets;
  138. @BucketInterval;
  139. for($i = 0; $i < $numbuckets; $i++)
  140. {
  141. $Buckets[$i] = 0;
  142. $BucketInterval[$i] = $i * ( $MaxArms / $numbuckets );
  143. }
  144. $BucketInterval[$i] = $MaxArms + 1;
  145. @TempList = @UnionList;
  146. for($i = 0; $i < $NumUnions; $i++)
  147. {
  148. $TempUnionArms = shift(@TempList);
  149. $TempMinArmValue = shift(@TempList);
  150. $TempMaxArmValue = shift(@TempList);
  151. for($j = 0; $j < $numbuckets; $j++)
  152. {
  153. if ($TempUnionArms < $BucketInterval[$j+1]) {
  154. $Buckets[$j]++;
  155. last;
  156. }
  157. }
  158. }
  159. print("Arm distribution:(Count is number >= Interval and < next value) \n");
  160. print("Interval Number\n");
  161. for($i = 0; $i < $numbuckets; $i++)
  162. {
  163. print("$BucketInterval[$i] $Buckets[$i]"."(".(($Buckets[$i]/$NumUnions)*100)."%)\n");
  164. }
  165. print("\n");
  166. print("Density statistics:\n");
  167. @MinNumberArms = (1, 7, 10);
  168. foreach $MinNumberArms (@MinNumberArms)
  169. {
  170. @thresholds = (1.0, 1.25, 1.50, 1.75, 2.0, 3.0, 4.0);
  171. @densevalues = (0, 0, 0, 0, 0, 0, 0 );
  172. $NUMBERTHRESHOLDS = 7;
  173. @TempList = @UnionList;
  174. for($i = 0; $i < $NumUnions; $i++)
  175. {
  176. $TempUnionArms = shift(@TempList);
  177. $TempMinArmValue = shift(@TempList);
  178. $TempMaxArmValue = shift(@TempList);
  179. $slotsrequired = ($TempMaxArmValue - $TempMinArmValue + 1);
  180. $Density = ($slotsrequired / $TempUnionArms);
  181. for($j = 0; $j < $NUMBERTHRESHOLDS; $j++) {
  182. if (($Density <= $thresholds[$j]) && ($MinNumberArms <= $TempUnionArms)) {
  183. $densevalues[$j]++;
  184. }
  185. }
  186. }
  187. print("Counting unions with a minimum of $MinNumberArms arms:\n");
  188. print("Table Growth Number of dense unions\n");
  189. for($i = 0; $i < $NUMBERTHRESHOLDS; $i++) {
  190. $name = ($thresholds[$i] * 100)."%";
  191. $number = $densevalues[$i];
  192. $percentage = (($number / $NumUnions) * 100)."%";
  193. print("$name: $number ($percentage)\n");
  194. }
  195. print("\n");
  196. }