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