summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/util/AbstractTimer.scala
blob: f734692a79db494b670cba6474fe0339b85b63a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2006, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$

package scala.tools.util

import compat.Platform.currentTime
import scala.collection.mutable.Stack

/**
 * This abstract class implements the collection of timings. How the
 * collected timings are issued has to be implemented in subclasses.
 *
 * @author Philippe Altherr
 * @version 1.0
 */
abstract class AbstractTimer {

  //########################################################################
  // Private Fields

  /** A stack for maintaining start times */
  private val starts = new Stack[Long]()

  //########################################################################
  // Public Methods

  /** Issues a timing information (duration in milliseconds). */
  def issue(message: String, duration: Long): Unit

  /** Starts a new timer. */
  def start() = {
    starts += currentTime
  }

  /** Ends the current timer. */
  def stop(message: String): Unit = {
    val stop = currentTime
    issue(message, stop - starts.pop)
  }

  /** Drops the current timer. */
  def drop(): Unit =
    starts.pop

    //########################################################################
}