1 19 20 25 26 package soot; 27 28 import java.text.DecimalFormat ; 29 30 import soot.options.Options; 31 32 public class Timers 33 { 34 public Timers( Singletons.Global g ) {} 35 public static Timers v() { return G.v().soot_Timers(); } 36 37 public int totalFlowNodes; 38 39 public int totalFlowComputations; 40 41 42 public Timer copiesTimer = new Timer("copies"); 43 44 public Timer defsTimer = new Timer("defs"); 45 46 public Timer usesTimer = new Timer("uses"); 47 48 public Timer liveTimer = new Timer("live"); 49 50 public Timer splitTimer = new Timer("split"); 51 52 public Timer packTimer = new Timer("pack"); 53 54 public Timer cleanup1Timer = new Timer("cleanup1"); 55 56 public Timer cleanup2Timer = new Timer("cleanup2"); 57 58 public Timer conversionTimer = new Timer("conversion"); 59 60 public Timer cleanupAlgorithmTimer = new Timer("cleanupAlgorithm"); 61 62 public Timer graphTimer = new Timer("graphTimer"); 63 64 public Timer assignTimer = new Timer("assignTimer"); 65 66 public Timer resolveTimer = new Timer("resolveTimer"); 67 68 public Timer totalTimer = new Timer("totalTimer"); 69 70 public Timer splitPhase1Timer = new Timer("splitPhase1"); 71 72 public Timer splitPhase2Timer = new Timer("splitPhase2"); 73 74 public Timer usePhase1Timer = new Timer("usePhase1"); 75 76 public Timer usePhase2Timer = new Timer("usePhase2"); 77 78 public Timer usePhase3Timer = new Timer("usePhase3"); 79 80 public Timer defsSetupTimer = new Timer("defsSetup"); 81 82 public Timer defsAnalysisTimer = new Timer("defsAnalysis"); 83 84 public Timer defsPostTimer = new Timer("defsPost"); 85 86 public Timer liveSetupTimer = new Timer("liveSetup"); 87 88 public Timer liveAnalysisTimer = new Timer("liveAnalysis"); 89 90 public Timer livePostTimer = new Timer("livePost"); 91 92 public Timer aggregationTimer = new Timer("aggregation"); 93 94 public Timer grimpAggregationTimer = new Timer("grimpAggregation"); 95 96 public Timer deadCodeTimer = new Timer("deadCode"); 97 98 public Timer propagatorTimer = new Timer("propagator"); 99 100 public Timer buildJasminTimer = new Timer("buildjasmin"); 101 102 public Timer assembleJasminTimer = new Timer("assembling jasmin"); 103 104 public Timer resolverTimer = new Timer("resolver"); 105 106 107 public int conversionLocalCount; 108 109 public int cleanup1LocalCount; 110 111 public int splitLocalCount; 112 113 public int assignLocalCount; 114 115 public int packLocalCount; 116 117 public int cleanup2LocalCount; 118 119 120 public int conversionStmtCount; 121 122 public int cleanup1StmtCount; 123 124 public int splitStmtCount; 125 126 public int assignStmtCount; 127 128 public int packStmtCount; 129 130 public int cleanup2StmtCount; 131 132 133 public long stmtCount; 134 135 public Timer fieldTimer = new soot.Timer(); 136 137 public Timer methodTimer = new soot.Timer(); 138 139 public Timer attributeTimer = new soot.Timer(); 140 141 public Timer locatorTimer = new soot.Timer(); 142 143 public Timer readTimer = new soot.Timer(); 144 145 146 public void printProfilingInformation() 147 { 148 long totalTime = totalTimer.getTime(); 149 150 G.v().out.println("Time measurements"); 151 G.v().out.println(); 152 153 G.v().out.println(" Building graphs: " + toTimeString(graphTimer, totalTime)); 154 G.v().out.println(" Computing LocalDefs: " + toTimeString(defsTimer, totalTime)); 155 G.v().out.println(" Computing LocalUses: " + toTimeString(usesTimer, totalTime)); 159 163 G.v().out.println(" Cleaning up code: " + toTimeString(cleanupAlgorithmTimer, totalTime)); 164 G.v().out.println("Computing LocalCopies: " + toTimeString(copiesTimer, totalTime)); 165 G.v().out.println(" Computing LiveLocals: " + toTimeString(liveTimer, totalTime)); 166 170 G.v().out.println("Coading coffi structs: " + toTimeString(resolveTimer, totalTime)); 171 172 173 G.v().out.println(); 174 175 { 177 float timeInSecs; 178 179 G.v().out.println(" Resolving classfiles: " + toTimeString(resolverTimer, totalTime)); 180 G.v().out.println(" Bytecode -> jimple (naive): " + toTimeString(conversionTimer, totalTime)); 181 G.v().out.println(" Splitting variables: " + toTimeString(splitTimer, totalTime)); 182 G.v().out.println(" Assigning types: " + toTimeString(assignTimer, totalTime)); 183 G.v().out.println(" Propagating copies & csts: " + toTimeString(propagatorTimer, totalTime)); 184 G.v().out.println(" Eliminating dead code: " + toTimeString(deadCodeTimer, totalTime)); 185 G.v().out.println(" Aggregation: " + toTimeString(aggregationTimer, totalTime)); 186 G.v().out.println(" Coloring locals: " + toTimeString(packTimer, totalTime)); 187 G.v().out.println(" Generating jasmin code: " + toTimeString(buildJasminTimer, totalTime)); 188 G.v().out.println(" .jasmin -> .class: " + toTimeString(assembleJasminTimer, totalTime)); 189 190 191 194 197 202 203 timeInSecs = (float) totalTime / 1000.0f; 204 float memoryUsed = (float) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000.0f; 205 206 G.v().out.println("totalTime:" + toTimeString(totalTimer, totalTime)); 207 208 if(Options.v().subtract_gc()) 209 { 210 G.v().out.println("Garbage collection was subtracted from these numbers."); 211 G.v().out.println(" forcedGC:" + 212 toTimeString(G.v().Timer_forcedGarbageCollectionTimer, totalTime)); 213 } 214 215 G.v().out.println("stmtCount: " + stmtCount + "(" + toFormattedString(stmtCount / timeInSecs) + " stmt/s)"); 216 217 G.v().out.println("totalFlowNodes: " + totalFlowNodes + 218 " totalFlowComputations: " + totalFlowComputations + " avg: " + 219 truncatedOf((double) totalFlowComputations / totalFlowNodes, 2)); 220 } 221 } 222 223 224 private String toTimeString(Timer timer, long totalTime) 225 { 226 DecimalFormat format = new DecimalFormat ("00.0"); 227 DecimalFormat percFormat = new DecimalFormat ("00.0"); 228 229 long time = timer.getTime(); 230 231 String timeString = format.format(time / 1000.0); 233 return (timeString + "s" + " (" + percFormat.format(time * 100.0 / totalTime) + "%" + ")"); 234 } 235 236 237 private String toFormattedString(double value) 238 { 239 return paddedLeftOf(new Double (truncatedOf(value, 2)).toString(), 5); 240 } 241 242 243 public double truncatedOf(double d, int numDigits) 244 { 245 double multiplier = 1; 246 247 for(int i = 0; i < numDigits; i++) 248 multiplier *= 10; 249 250 return ((long) (d * multiplier)) / multiplier; 251 } 252 253 254 public String paddedLeftOf(String s, int length) 255 { 256 if(s.length() >= length) 257 return s; 258 else { 259 int diff = length - s.length(); 260 char[] padding = new char[diff]; 261 262 for(int i = 0; i < diff; i++) 263 padding[i] = ' '; 264 265 return new String (padding) + s; 266 } 267 } 268 269 } 270 271 | Popular Tags |