Improve startup time for fresh or rollback'd session in index writing
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / TimingProgressMonitor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics;
13
14 import org.eclipse.core.runtime.NullProgressMonitor;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * @author Tuukka Lehtonen
20  */
21 public class TimingProgressMonitor extends NullProgressMonitor {
22
23     private static final Logger LOGGER = LoggerFactory.getLogger(TimingProgressMonitor.class);
24
25     private final long start;
26
27     public TimingProgressMonitor() {
28         this.start = System.nanoTime();
29     }
30
31     private void log(String msg) {
32         LOGGER.info(msg + " @ " + (System.nanoTime() - start)*1e-9);
33     }
34
35     @Override
36     public void worked(int work) {
37         log("worked(" + work + ")");
38     }
39
40     @Override
41     public void subTask(String name) {
42         log("subTask(" + name + ")");
43     }
44
45     @Override
46     public void setTaskName(String name) {
47         log("setTaskName(" + name + ")");
48     }
49
50     @Override
51     public void setCanceled(boolean value) {
52         log("setCanceled(" + value+ ")");
53         super.setCanceled(value);
54     }
55
56     @Override
57     public boolean isCanceled() {
58         log("isCanceled()");
59         return super.isCanceled();
60     }
61
62     @Override
63     public void internalWorked(double work) {
64         log("internalWorked(" + work + ")");
65     }
66
67     @Override
68     public void done() {
69         log("done()");
70     }
71
72     @Override
73     public void beginTask(String name, int totalWork) {
74         log("beginTask(" + name + ", " + totalWork + ")");
75     }
76
77 }