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