summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2005-01-25 17:08:56 +0000
committerpaltherr <paltherr@epfl.ch>2005-01-25 17:08:56 +0000
commit2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4 (patch)
tree2b900db68b0defb89ff37a8269a5e80e5dd0a269
parent80c6300d103adcc45e50b2c91c104c7c1ce6dfc3 (diff)
downloadscala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.tar.gz
scala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.tar.bz2
scala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.zip
- Added timers
-rw-r--r--config/list/util.lst6
-rw-r--r--sources/scala/tools/util/AbstractTimer.java49
-rw-r--r--sources/scala/tools/util/DummyTimer.java44
-rw-r--r--sources/scala/tools/util/ReporterTimer.java39
-rw-r--r--sources/scala/tools/util/Timer.java27
5 files changed, 164 insertions, 1 deletions
diff --git a/config/list/util.lst b/config/list/util.lst
index 170a91b459..05f8560728 100644
--- a/config/list/util.lst
+++ b/config/list/util.lst
@@ -5,20 +5,24 @@
AbstractFile.java
AbstractFileReader.java
+AbstractTimer.java
ByteArrayFile.java
CharArrayFile.java
ClassPath.java
DirectoryPath.java
+DummyTimer.java
EmptyIterator.java
PlainFile.java
Position.java
+Reporter.java
+ReporterTimer.java
SourceFile.java
SourceReader.java
StringBufferWriter.java
+Timer.java
VirtualDirectory.java
VirtualFile.java
ZipArchive.java
-Reporter.java
debug/AbortError.java
debug/ArrayDebugger.java
diff --git a/sources/scala/tools/util/AbstractTimer.java b/sources/scala/tools/util/AbstractTimer.java
new file mode 100644
index 0000000000..6314023fe3
--- /dev/null
+++ b/sources/scala/tools/util/AbstractTimer.java
@@ -0,0 +1,49 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.util;
+
+import java.util.ArrayList;
+
+/**
+ * This abstract class implements the collection of timings. How the
+ * collected timings are issued has to be implemented in subclasses.
+ */
+public abstract class AbstractTimer implements Timer {
+
+ //########################################################################
+ // Private Fields
+
+ /** A stack for maintaining start times */
+ private final ArrayList starts = new ArrayList();
+
+ //########################################################################
+ // Public Methods
+
+ /** Issues a timing information (duration in milliseconds). */
+ public abstract void issue(String message, long duration);
+
+ /** Starts a new timer. */
+ public void start() {
+ starts.add(new Long(System.currentTimeMillis()));
+ }
+
+ /** Ends the current timer. */
+ public void stop(String message) {
+ long stop = System.currentTimeMillis();
+ long start = ((Long)starts.remove(starts.size() - 1)).longValue();
+ issue(message, stop - start);
+ }
+
+ /** Drops the current timer. */
+ public void drop() {
+ starts.remove(starts.size() - 1);
+ }
+
+ //########################################################################
+}
diff --git a/sources/scala/tools/util/DummyTimer.java b/sources/scala/tools/util/DummyTimer.java
new file mode 100644
index 0000000000..e16c44b6be
--- /dev/null
+++ b/sources/scala/tools/util/DummyTimer.java
@@ -0,0 +1,44 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.util;
+
+import java.util.ArrayList;
+
+/** This class implements a timer that does nothing. */
+public class DummyTimer implements Timer {
+
+ //########################################################################
+ // Public Constants
+
+ /** The unique instance of this class. */
+ public static final DummyTimer object = new DummyTimer();
+
+ //########################################################################
+ // Private Constructors
+
+ /** Initializes this instance. */
+ private DummyTimer() {}
+
+ //########################################################################
+ // Public Methods
+
+ /** Starts a new timer. */
+ public void start() {
+ }
+
+ /** Ends the current timer. */
+ public void stop(String message) {
+ }
+
+ /** Drops the current timer. */
+ public void drop() {
+ }
+
+ //########################################################################
+}
diff --git a/sources/scala/tools/util/ReporterTimer.java b/sources/scala/tools/util/ReporterTimer.java
new file mode 100644
index 0000000000..77e91d290d
--- /dev/null
+++ b/sources/scala/tools/util/ReporterTimer.java
@@ -0,0 +1,39 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.util;
+
+/**
+ * This class implements a timer that uses a Reporter to issue
+ * timings.
+ */
+public class ReporterTimer extends AbstractTimer {
+
+ //########################################################################
+ // Private Fields
+
+ /** A reporter to report timing information */
+ private final Reporter reporter;
+
+ //########################################################################
+ // Public Constructors
+
+ public ReporterTimer(Reporter reporter) {
+ this.reporter = reporter;
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Issues a timing information (duration in milliseconds). */
+ public void issue(String message, long duration) {
+ reporter.inform("[" + message + " in " + duration + "ms]");
+ }
+
+ //########################################################################
+}
diff --git a/sources/scala/tools/util/Timer.java b/sources/scala/tools/util/Timer.java
new file mode 100644
index 0000000000..df60d580ae
--- /dev/null
+++ b/sources/scala/tools/util/Timer.java
@@ -0,0 +1,27 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.util;
+
+/** This interface provides methods to collect timings. */
+public interface Timer {
+
+ //########################################################################
+ // Public Methods
+
+ /** Starts a new timer. */
+ public void start();
+
+ /** Stops the current timer. */
+ public void stop(String message);
+
+ /** Drops the current timer. */
+ public void drop();
+
+ //########################################################################
+}