diff options
-rw-r--r-- | config/list/util.lst | 6 | ||||
-rw-r--r-- | sources/scala/tools/util/AbstractTimer.java | 49 | ||||
-rw-r--r-- | sources/scala/tools/util/DummyTimer.java | 44 | ||||
-rw-r--r-- | sources/scala/tools/util/ReporterTimer.java | 39 | ||||
-rw-r--r-- | sources/scala/tools/util/Timer.java | 27 |
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(); + + //######################################################################## +} |