1 package org.simantics.scl.compiler.compilation;
\r
3 import java.util.ArrayList;
\r
5 import gnu.trove.map.hash.TObjectLongHashMap;
\r
7 public class CompilationTimer {
\r
8 private long initialTime, previousTime;
\r
9 private ArrayList<TimerEntry> entries = new ArrayList<TimerEntry>();
\r
10 private static TObjectLongHashMap<String> GLOBAL_TIMES = new TObjectLongHashMap<String>();
\r
12 private static class TimerEntry {
\r
13 public final String phaseName;
\r
14 public final long time;
\r
15 public final long cumulativeTime;
\r
17 public TimerEntry(String phaseName, long time, long cumulativeTime) {
\r
18 this.phaseName = phaseName;
\r
20 this.cumulativeTime = cumulativeTime;
\r
24 public CompilationTimer() {
\r
25 initialTime = previousTime = System.nanoTime();
\r
28 public void phaseFinished(String phaseName) {
\r
29 long time = System.nanoTime();
\r
30 entries.add(new TimerEntry(phaseName, time-previousTime, time-initialTime));
\r
31 previousTime = time;
\r
34 public void suspendTimer() {
\r
35 long time = System.nanoTime();
\r
36 initialTime -= time;
\r
37 previousTime -= time;
\r
40 public void continueTimer() {
\r
41 long time = System.nanoTime();
\r
42 initialTime += time;
\r
43 previousTime += time;
\r
46 public void report(String moduleName) {
\r
47 synchronized(GLOBAL_TIMES) {
\r
48 System.out.println(moduleName);
\r
49 for(TimerEntry entry : entries) {
\r
50 long globalTime = GLOBAL_TIMES.adjustOrPutValue(entry.phaseName, entry.time, entry.time);
\r
51 System.out.println(" " + entry.phaseName + " " + entry.time*1e-6
\r
52 + "ms (cumulative: " + entry.cumulativeTime*1e-6 + "ms, global: " + globalTime*1e-6 + ")");
\r