KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > Timers


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot;
27
28 import java.text.DecimalFormat JavaDoc;
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(" setup: " + toTimeString(defsSetupTimer, totalTime));
156
// G.v().out.println(" analysis: " + toTimeString(defsAnalysisTimer, totalTime));
157
// G.v().out.println(" post: " + toTimeString(defsPostTimer, totalTime));
158
G.v().out.println(" Computing LocalUses: " + toTimeString(usesTimer, totalTime));
159     // G.v().out.println(" Use phase1: " + toTimeString(usePhase1Timer, totalTime));
160
// G.v().out.println(" Use phase2: " + toTimeString(usePhase2Timer, totalTime));
161
// G.v().out.println(" Use phase3: " + toTimeString(usePhase3Timer, totalTime));
162

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     // G.v().out.println(" setup: " + toTimeString(liveSetupTimer, totalTime));
167
// G.v().out.println(" analysis: " + toTimeString(liveAnalysisTimer, totalTime));
168
// G.v().out.println(" post: " + toTimeString(livePostTimer, totalTime));
169

170         G.v().out.println("Coading coffi structs: " + toTimeString(resolveTimer, totalTime));
171
172                 
173         G.v().out.println();
174
175         // Print out time stats.
176
{
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         // G.v().out.println(" Cleaning up code: " + toTimeString(cleanup1Timer, totalTime) +
192
// "\t" + cleanup1LocalCount + " locals " + cleanup1StmtCount + " stmts");
193

194         // G.v().out.println(" Split phase1: " + toTimeString(splitPhase1Timer, totalTime));
195
// G.v().out.println(" Split phase2: " + toTimeString(splitPhase2Timer, totalTime));
196

197         /*
198           G.v().out.println("cleanup2Timer: " + cleanup2Time +
199           "(" + (cleanup2Time * 100 / totalTime) + "%) " +
200           cleanup2LocalCount + " locals " + cleanup2StmtCount + " stmts");
201         */

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 JavaDoc toTimeString(Timer timer, long totalTime)
225     {
226         DecimalFormat JavaDoc format = new DecimalFormat JavaDoc("00.0");
227         DecimalFormat JavaDoc percFormat = new DecimalFormat JavaDoc("00.0");
228         
229         long time = timer.getTime();
230         
231         String JavaDoc timeString = format.format(time / 1000.0); // paddedLeftOf(new Double(truncatedOf(time / 1000.0, 1)).toString(), 5);
232

233         return (timeString + "s" + " (" + percFormat.format(time * 100.0 / totalTime) + "%" + ")");
234     }
235     
236
237     private String JavaDoc toFormattedString(double value)
238     {
239         return paddedLeftOf(new Double JavaDoc(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 JavaDoc paddedLeftOf(String JavaDoc 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 JavaDoc(padding) + s;
266         }
267     }
268
269 }
270
271
Popular Tags