1 34 package jarg; 35 36 import java.util.*; 37 38 44 class Statistics { 45 Statistics() { 46 } 47 48 private int oldClassFileSize; 50 void addOldClassFileSize(int sz) { 51 oldClassFileSize += sz; 52 } 53 54 private int oldClassCount; 55 void incOldClassCount() { 56 oldClassCount++; 57 } 58 59 private int oldCpEntrySize; 60 void addOldCpEntrySize(int sz) { 61 oldCpEntrySize += sz; 62 } 63 64 private int oldCpEntryCount; 65 void addOldCpEntryCount(int count) { 66 oldCpEntryCount += count; 67 } 68 69 private int oldFieldCount; 70 void incOldFieldCount() { 71 oldFieldCount++; 72 } 73 74 private int oldMethodCount; 75 void incOldMethodCount() { 76 oldMethodCount++; 77 } 78 79 private int oldByteCodeCount; 80 void addOldByteCodeCount(int count) { 81 oldByteCodeCount += count; 82 } 83 84 private int oldByteCodeSize; 85 void addOldByteCodeSize(int sz) { 86 oldByteCodeSize += sz; 87 } 88 89 private int newClassFileSize; 91 void addNewClassFileSize(int sz) { 92 newClassFileSize += sz; 93 } 94 95 private int newClassCount; 96 void incNewClassCount() { 97 newClassCount++; 98 } 99 100 private int newCpEntrySize; 101 void addNewCpEntrySize(int sz) { 102 newCpEntrySize += sz; 103 } 104 105 private int newCpEntryCount; 106 void addNewCpEntryCount(int count) { 107 newCpEntryCount += count; 108 } 109 110 private int newFieldCount; 111 void incNewFieldCount() { 112 newFieldCount++; 113 } 114 115 private int newMethodCount; 116 void incNewMethodCount() { 117 newMethodCount++; 118 } 119 120 private int newByteCodeCount; 121 void addNewByteCodeCount(int count) { 122 newByteCodeCount += count; 123 } 124 125 private int newByteCodeSize; 126 void addNewByteCodeSize(int sz) { 127 newByteCodeSize += sz; 128 } 129 130 void print() { 132 System.out.println(); 133 System.out.println("[Statistics]"); 134 System.out.println(" OLD : NEW : REDUCED : RATIO :"); 135 printLine("class sz", oldClassFileSize, newClassFileSize); 136 printLine("class #", oldClassCount, newClassCount); 137 printLine("cp size ", oldCpEntrySize, newCpEntrySize); 138 printLine("cp entr#", oldCpEntryCount, newCpEntryCount); 139 printLine("field #", oldFieldCount, newFieldCount); 140 printLine("method #", oldMethodCount, newMethodCount); 141 printLine("bcode sz", oldByteCodeSize, newByteCodeSize); 142 printLine("bcode #", oldByteCodeCount, newByteCodeCount); 143 } 144 145 private void printLine(String label, int oldInt, int newInt) { 146 System.out.print(" "); 147 System.out.print(label); 148 System.out.print(" : "); 149 System.out.print(formatNum(oldInt)); 150 System.out.print(" : "); 151 System.out.print(formatNum(newInt)); 152 System.out.print(" : "); 153 System.out.print(formatNum(oldInt - newInt)); 154 System.out.print(" : "); 155 System.out.print(formatNum(newInt*100/oldInt)); 156 System.out.print("%"); 157 System.out.println(); 158 } 159 160 private static final int NUM_COL = 8; 161 162 private String formatNum(int val) { 163 String v = String.valueOf(val); 164 if (v.length() < NUM_COL) { 165 StringBuffer str = new StringBuffer (); 166 for (int i=NUM_COL-v.length(); i>0; i--) { 167 str.append(' '); 168 } 169 str.append(v); 170 v = str.toString(); 171 } 172 return v; 173 } 174 186 } 187 | Popular Tags |