blob: d18495458c6310d13d832e08b86b7ed32f3e59f8 (
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
|
/* NSC -- new Scala compiler
* Copyright 2005-2011 LAMP/EPFL
* @author Martin Odersky
*/
package scala.tools.nsc
import symtab.Flags
import util.TableDef
object Phases {
val MaxPhases = 64
/** A class for tracking something about each phase.
*/
class Model[T: Manifest] {
case class Cell(ph: Phase, value: T) {
def name = ph.name
def id = ph.id
}
val values = new Array[Cell](MaxPhases + 1)
def results = values filterNot (_ == null)
def apply(ph: Phase): T = values(ph.id).value
def update(ph: Phase, value: T): Unit = values(ph.id) = Cell(ph, value)
}
/** A class for recording the elapsed time of each phase in the
* interests of generating a classy and informative table.
*/
class TimingModel extends Model[Long] {
var total: Long = 0
def table() = {
total = results map (_.value) sum;
new Format.Table(results sortBy (-_.value))
}
object Format extends TableDef[Cell] {
>> ("phase" -> (_.name)) >+ " "
<< ("id" -> (_.id)) >+ " "
>> ("ms" -> (_.value)) >+ " "
<< ("share" -> (_.value.toDouble * 100 / total formatted "%.2f"))
}
def formatted = "" + table()
}
}
|