src/Pure/Tools/build_stats.scala
author wenzelm
Sat Aug 13 12:06:11 2016 +0200 (2016-08-13)
changeset 63686 66f217416da7
child 63688 cc57255bf6ae
permissions -rw-r--r--
statistics from session build output;
wenzelm@63686
     1
/*  Title:      Pure/Tools/build_stats.scala
wenzelm@63686
     2
    Author:     Makarius
wenzelm@63686
     3
wenzelm@63686
     4
Statistics from session build output.
wenzelm@63686
     5
*/
wenzelm@63686
     6
wenzelm@63686
     7
package isabelle
wenzelm@63686
     8
wenzelm@63686
     9
wenzelm@63686
    10
import scala.collection.mutable
wenzelm@63686
    11
import scala.util.matching.Regex
wenzelm@63686
    12
wenzelm@63686
    13
wenzelm@63686
    14
object Build_Stats
wenzelm@63686
    15
{
wenzelm@63686
    16
  private val Session_Finished =
wenzelm@63686
    17
    new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
wenzelm@63686
    18
  private val Session_Timing =
wenzelm@63686
    19
    new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
wenzelm@63686
    20
wenzelm@63686
    21
  private object ML_Option
wenzelm@63686
    22
  {
wenzelm@63686
    23
    def unapply(s: String): Option[(String, String)] =
wenzelm@63686
    24
      s.indexOf('=') match {
wenzelm@63686
    25
        case -1 => None
wenzelm@63686
    26
        case i =>
wenzelm@63686
    27
          val a = s.substring(0, i)
wenzelm@63686
    28
          Library.try_unquote(s.substring(i + 1)) match {
wenzelm@63686
    29
            case Some(b) if Build.ml_options.contains(a) => Some((a, b))
wenzelm@63686
    30
            case _ => None
wenzelm@63686
    31
          }
wenzelm@63686
    32
      }
wenzelm@63686
    33
  }
wenzelm@63686
    34
wenzelm@63686
    35
  def parse(text: String): Build_Stats =
wenzelm@63686
    36
  {
wenzelm@63686
    37
    import Properties.Value
wenzelm@63686
    38
wenzelm@63686
    39
    val ml_options = new mutable.ListBuffer[(String, String)]
wenzelm@63686
    40
    var finished = Map.empty[String, Timing]
wenzelm@63686
    41
    var timing = Map.empty[String, Timing]
wenzelm@63686
    42
    var threads = Map.empty[String, Int]
wenzelm@63686
    43
wenzelm@63686
    44
    for (line <- split_lines(text)) {
wenzelm@63686
    45
      line match {
wenzelm@63686
    46
        case Session_Finished(name,
wenzelm@63686
    47
            Value.Int(e1), Value.Int(e2), Value.Int(e3),
wenzelm@63686
    48
            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
wenzelm@63686
    49
          val elapsed = Time.hours_minutes_seconds(e1, e2, e3)
wenzelm@63686
    50
          val cpu = Time.hours_minutes_seconds(c1, c2, c3)
wenzelm@63686
    51
          finished += (name -> Timing(elapsed, cpu, Time.zero))
wenzelm@63686
    52
        case Session_Timing(name,
wenzelm@63686
    53
            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
wenzelm@63686
    54
          val elapsed = Time.seconds(e)
wenzelm@63686
    55
          val cpu = Time.seconds(c)
wenzelm@63686
    56
          val gc = Time.seconds(g)
wenzelm@63686
    57
          timing += (name -> Timing(elapsed, cpu, gc))
wenzelm@63686
    58
          threads += (name -> t)
wenzelm@63686
    59
        case ML_Option(option) => ml_options += option
wenzelm@63686
    60
        case _ =>
wenzelm@63686
    61
      }
wenzelm@63686
    62
    }
wenzelm@63686
    63
wenzelm@63686
    64
    Build_Stats(ml_options.toList, finished, timing, threads)
wenzelm@63686
    65
  }
wenzelm@63686
    66
}
wenzelm@63686
    67
wenzelm@63686
    68
sealed case class Build_Stats(
wenzelm@63686
    69
  ml_options: List[(String, String)],
wenzelm@63686
    70
  finished: Map[String, Timing],
wenzelm@63686
    71
  timing: Map[String, Timing],
wenzelm@63686
    72
  threads: Map[String, Int])
wenzelm@63686
    73
{
wenzelm@63686
    74
  val sessions: Set[String] = finished.keySet ++ timing.keySet
wenzelm@63686
    75
wenzelm@63686
    76
  override def toString: String =
wenzelm@63686
    77
    sessions.toList.sorted.mkString("Build_Stats(", ", ", ")")
wenzelm@63686
    78
}