src/Pure/Admin/build_log.scala
changeset 64160 1eea419fab65
parent 64155 646c4d6a6a02
child 64193 7a7e370e2523
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Admin/build_log.scala	Wed Oct 12 09:38:20 2016 +0200
     1.3 @@ -0,0 +1,548 @@
     1.4 +/*  Title:      Pure/Admin/build_log.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Build log parsing for current and historic formats.
     1.8 +*/
     1.9 +
    1.10 +package isabelle
    1.11 +
    1.12 +
    1.13 +import java.io.{File => JFile}
    1.14 +import java.time.ZoneId
    1.15 +import java.time.format.{DateTimeFormatter, DateTimeParseException}
    1.16 +import java.util.Locale
    1.17 +
    1.18 +import scala.collection.mutable
    1.19 +import scala.util.matching.Regex
    1.20 +
    1.21 +
    1.22 +object Build_Log
    1.23 +{
    1.24 +  /** directory content **/
    1.25 +
    1.26 +  /* file names */
    1.27 +
    1.28 +  def log_date(date: Date): String =
    1.29 +    String.format(Locale.ROOT, "%s.%05d",
    1.30 +      DateTimeFormatter.ofPattern("yyyy-MM-dd").format(date.rep),
    1.31 +      new java.lang.Long((date.time - date.midnight.time).ms / 1000))
    1.32 +
    1.33 +  def log_path(engine: String, date: Date, more: String*): Path =
    1.34 +    Path.explode(date.rep.getYear.toString) +
    1.35 +      Path.explode((engine :: log_date(date) :: more.toList).mkString("", "_", ".log"))
    1.36 +
    1.37 +
    1.38 +  /* log file collections */
    1.39 +
    1.40 +  def is_log(file: JFile): Boolean =
    1.41 +    List(".log", ".log.gz", ".log.xz").exists(ext => file.getName.endsWith(ext))
    1.42 +
    1.43 +  def isatest_files(dir: Path): List[JFile] =
    1.44 +    File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("isatest-makeall-"))
    1.45 +
    1.46 +  def afp_test_files(dir: Path): List[JFile] =
    1.47 +    File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("afp-test-devel-"))
    1.48 +
    1.49 +
    1.50 +
    1.51 +  /** settings **/
    1.52 +
    1.53 +  object Settings
    1.54 +  {
    1.55 +    val build_settings = List("ISABELLE_BUILD_OPTIONS")
    1.56 +    val ml_settings = List("ML_PLATFORM", "ML_HOME", "ML_SYSTEM", "ML_OPTIONS")
    1.57 +    val all_settings = build_settings ::: ml_settings
    1.58 +
    1.59 +    type Entry = (String, String)
    1.60 +    type T = List[Entry]
    1.61 +
    1.62 +    object Entry
    1.63 +    {
    1.64 +      def unapply(s: String): Option[Entry] =
    1.65 +        s.indexOf('=') match {
    1.66 +          case -1 => None
    1.67 +          case i =>
    1.68 +            val a = s.substring(0, i)
    1.69 +            val b = Library.perhaps_unquote(s.substring(i + 1))
    1.70 +            Some((a, b))
    1.71 +        }
    1.72 +      def apply(a: String, b: String): String = a + "=" + quote(b)
    1.73 +      def getenv(a: String): String = apply(a, Isabelle_System.getenv(a))
    1.74 +    }
    1.75 +
    1.76 +    def show(): String =
    1.77 +      cat_lines(
    1.78 +        build_settings.map(Entry.getenv(_)) ::: List("") ::: ml_settings.map(Entry.getenv(_)))
    1.79 +  }
    1.80 +
    1.81 +
    1.82 +
    1.83 +  /** log file **/
    1.84 +
    1.85 +  def print_date(date: Date): String = Log_File.Date_Format(date)
    1.86 +
    1.87 +  object Log_File
    1.88 +  {
    1.89 +    def apply(name: String, lines: List[String]): Log_File =
    1.90 +      new Log_File(name, lines)
    1.91 +
    1.92 +    def apply(name: String, text: String): Log_File =
    1.93 +      Log_File(name, Library.trim_split_lines(text))
    1.94 +
    1.95 +    def apply(file: JFile): Log_File =
    1.96 +    {
    1.97 +      val name = file.getName
    1.98 +      val (base_name, text) =
    1.99 +        Library.try_unsuffix(".gz", name) match {
   1.100 +          case Some(base_name) => (base_name, File.read_gzip(file))
   1.101 +          case None =>
   1.102 +            Library.try_unsuffix(".xz", name) match {
   1.103 +              case Some(base_name) => (base_name, File.read_xz(file))
   1.104 +              case None => (name, File.read(file))
   1.105 +            }
   1.106 +          }
   1.107 +      apply(base_name, text)
   1.108 +    }
   1.109 +
   1.110 +    def apply(path: Path): Log_File = apply(path.file)
   1.111 +
   1.112 +
   1.113 +    /* date format */
   1.114 +
   1.115 +    val Date_Format =
   1.116 +    {
   1.117 +      val fmts =
   1.118 +        Date.Formatter.variants(
   1.119 +          List("EEE MMM d HH:mm:ss O yyyy", "EEE MMM d HH:mm:ss VV yyyy"),
   1.120 +          List(Locale.ENGLISH, Locale.GERMAN)) :::
   1.121 +        List(
   1.122 +          DateTimeFormatter.RFC_1123_DATE_TIME,
   1.123 +          Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(ZoneId.of("Europe/Berlin")))
   1.124 +
   1.125 +      def tune_timezone(s: String): String =
   1.126 +        s match {
   1.127 +          case "CET" | "MET" => "GMT+1"
   1.128 +          case "CEST" | "MEST" => "GMT+2"
   1.129 +          case "EST" => "Europe/Berlin"
   1.130 +          case _ => s
   1.131 +        }
   1.132 +      def tune_weekday(s: String): String =
   1.133 +        s match {
   1.134 +          case "Die" => "Di"
   1.135 +          case "Mit" => "Mi"
   1.136 +          case "Don" => "Do"
   1.137 +          case "Fre" => "Fr"
   1.138 +          case "Sam" => "Sa"
   1.139 +          case "Son" => "So"
   1.140 +          case _ => s
   1.141 +        }
   1.142 +
   1.143 +      def tune(s: String): String =
   1.144 +        Word.implode(
   1.145 +          Word.explode(s) match {
   1.146 +            case a :: "M\uFFFDr" :: bs => tune_weekday(a) :: "Mär" :: bs.map(tune_timezone(_))
   1.147 +            case a :: bs => tune_weekday(a) :: bs.map(tune_timezone(_))
   1.148 +            case Nil => Nil
   1.149 +          }
   1.150 +        )
   1.151 +
   1.152 +      Date.Format.make(fmts, tune)
   1.153 +    }
   1.154 +
   1.155 +
   1.156 +    /* inlined content */
   1.157 +
   1.158 +    def print_props(marker: String, props: Properties.T): String =
   1.159 +      marker + YXML.string_of_body(XML.Encode.properties(props))
   1.160 +  }
   1.161 +
   1.162 +  class Log_File private(val name: String, val lines: List[String])
   1.163 +  {
   1.164 +    log_file =>
   1.165 +
   1.166 +    override def toString: String = name
   1.167 +
   1.168 +    def text: String = cat_lines(lines)
   1.169 +
   1.170 +    def err(msg: String): Nothing =
   1.171 +      error("Error in log file " + quote(name) + ": " + msg)
   1.172 +
   1.173 +
   1.174 +    /* date format */
   1.175 +
   1.176 +    object Strict_Date
   1.177 +    {
   1.178 +      def unapply(s: String): Some[Date] =
   1.179 +        try { Some(Log_File.Date_Format.parse(s)) }
   1.180 +        catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) }
   1.181 +    }
   1.182 +
   1.183 +
   1.184 +    /* inlined content */
   1.185 +
   1.186 +    def find[A](f: String => Option[A]): Option[A] =
   1.187 +      lines.iterator.map(f).find(_.isDefined).map(_.get)
   1.188 +
   1.189 +    def find_match(regex: Regex): Option[String] =
   1.190 +      lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1).
   1.191 +        map(res => res.get.head)
   1.192 +
   1.193 +
   1.194 +    /* settings */
   1.195 +
   1.196 +    def get_setting(a: String): Option[Settings.Entry] =
   1.197 +      lines.find(_.startsWith(a + "=")) match {
   1.198 +        case Some(line) => Settings.Entry.unapply(line)
   1.199 +        case None => None
   1.200 +      }
   1.201 +
   1.202 +    def get_settings(as: List[String]): Settings.T =
   1.203 +      for { a <- as; entry <- get_setting(a) } yield entry
   1.204 +
   1.205 +
   1.206 +    /* properties (YXML) */
   1.207 +
   1.208 +    val xml_cache = new XML.Cache()
   1.209 +
   1.210 +    def parse_props(text: String): Properties.T =
   1.211 +      xml_cache.props(XML.Decode.properties(YXML.parse_body(text)))
   1.212 +
   1.213 +    def filter_props(marker: String): List[Properties.T] =
   1.214 +      for (line <- lines; s <- Library.try_unprefix(marker, line)) yield parse_props(s)
   1.215 +
   1.216 +    def find_line(marker: String): Option[String] =
   1.217 +      find(Library.try_unprefix(marker, _))
   1.218 +
   1.219 +    def find_props(marker: String): Option[Properties.T] =
   1.220 +      find_line(marker).map(parse_props(_))
   1.221 +
   1.222 +
   1.223 +    /* parse various formats */
   1.224 +
   1.225 +    def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file)
   1.226 +
   1.227 +    def parse_build_info(): Build_Info = Build_Log.parse_build_info(log_file)
   1.228 +
   1.229 +    def parse_session_info(
   1.230 +        default_name: String = "",
   1.231 +        command_timings: Boolean = false,
   1.232 +        ml_statistics: Boolean = false,
   1.233 +        task_statistics: Boolean = false): Session_Info =
   1.234 +      Build_Log.parse_session_info(
   1.235 +        log_file, default_name, command_timings, ml_statistics, task_statistics)
   1.236 +  }
   1.237 +
   1.238 +
   1.239 +
   1.240 +  /** meta info **/
   1.241 +
   1.242 +  object Field
   1.243 +  {
   1.244 +    val build_engine = "build_engine"
   1.245 +    val build_host = "build_host"
   1.246 +    val build_start = "build_start"
   1.247 +    val build_end = "build_end"
   1.248 +    val isabelle_version = "isabelle_version"
   1.249 +    val afp_version = "afp_version"
   1.250 +  }
   1.251 +
   1.252 +  object Meta_Info
   1.253 +  {
   1.254 +    val empty: Meta_Info = Meta_Info(Nil, Nil)
   1.255 +  }
   1.256 +
   1.257 +  sealed case class Meta_Info(props: Properties.T, settings: List[(String, String)])
   1.258 +  {
   1.259 +    def is_empty: Boolean = props.isEmpty && settings.isEmpty
   1.260 +  }
   1.261 +
   1.262 +  object Isatest
   1.263 +  {
   1.264 +    val engine = "isatest"
   1.265 +    val Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""")
   1.266 +    val End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""")
   1.267 +    val Isabelle_Version = new Regex("""^Isabelle version: (\S+)$""")
   1.268 +    val No_AFP_Version = new Regex("""$.""")
   1.269 +  }
   1.270 +
   1.271 +  object AFP_Test
   1.272 +  {
   1.273 +    val engine = "afp-test"
   1.274 +    val Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""")
   1.275 +    val Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""")
   1.276 +    val End = new Regex("""^End test on (.+), .+, elapsed time:.*$""")
   1.277 +    val Isabelle_Version = new Regex("""^Isabelle version: .* -- hg id (\S+)$""")
   1.278 +    val AFP_Version = new Regex("""^AFP version: .* -- hg id (\S+)$""")
   1.279 +    val Bad_Init = new Regex("""^cp:.*: Disc quota exceeded$""")
   1.280 +  }
   1.281 +
   1.282 +  object Jenkins
   1.283 +  {
   1.284 +    val engine = "jenkins"
   1.285 +    val Start = new Regex("""^Started .*$""")
   1.286 +    val Start_Date = new Regex("""^Build started at (.+)$""")
   1.287 +    val No_End = new Regex("""$.""")
   1.288 +    val Isabelle_Version = new Regex("""^Isabelle id (\S+)$""")
   1.289 +    val AFP_Version = new Regex("""^AFP id (\S+)$""")
   1.290 +    val CONFIGURATION = "=== CONFIGURATION ==="
   1.291 +    val BUILD = "=== BUILD ==="
   1.292 +    val FINISHED = "Finished: "
   1.293 +  }
   1.294 +
   1.295 +  private def parse_meta_info(log_file: Log_File): Meta_Info =
   1.296 +  {
   1.297 +    def parse(engine: String, host: String, start: Date,
   1.298 +      End: Regex, Isabelle_Version: Regex, AFP_Version: Regex): Meta_Info =
   1.299 +    {
   1.300 +      val build_engine = if (engine == "") Nil else List(Field.build_engine -> engine)
   1.301 +      val build_host = if (host == "") Nil else List(Field.build_host -> host)
   1.302 +
   1.303 +      val start_date = List(Field.build_start -> start.toString)
   1.304 +      val end_date =
   1.305 +        log_file.lines.last match {
   1.306 +          case End(log_file.Strict_Date(end_date)) =>
   1.307 +            List(Field.build_end -> end_date.toString)
   1.308 +          case _ => Nil
   1.309 +        }
   1.310 +
   1.311 +      val isabelle_version =
   1.312 +        log_file.find_match(Isabelle_Version).map(Field.isabelle_version -> _)
   1.313 +      val afp_version =
   1.314 +        log_file.find_match(AFP_Version).map(Field.afp_version -> _)
   1.315 +
   1.316 +      Meta_Info(build_engine ::: build_host :::
   1.317 +          start_date ::: end_date ::: isabelle_version.toList ::: afp_version.toList,
   1.318 +        log_file.get_settings(Settings.all_settings))
   1.319 +    }
   1.320 +
   1.321 +    log_file.lines match {
   1.322 +      case line :: _ if line.startsWith(Build_History.META_INFO_MARKER) =>
   1.323 +        Meta_Info(log_file.find_props(Build_History.META_INFO_MARKER).get,
   1.324 +          log_file.get_settings(Settings.all_settings))
   1.325 +
   1.326 +      case Isatest.Start(log_file.Strict_Date(start), host) :: _ =>
   1.327 +        parse(Isatest.engine, host, start, Isatest.End,
   1.328 +          Isatest.Isabelle_Version, Isatest.No_AFP_Version)
   1.329 +
   1.330 +      case AFP_Test.Start(log_file.Strict_Date(start), host) :: _ =>
   1.331 +        parse(AFP_Test.engine, host, start, AFP_Test.End,
   1.332 +          AFP_Test.Isabelle_Version, AFP_Test.AFP_Version)
   1.333 +
   1.334 +      case AFP_Test.Start_Old(log_file.Strict_Date(start)) :: _ =>
   1.335 +        parse(AFP_Test.engine, "", start, AFP_Test.End,
   1.336 +          AFP_Test.Isabelle_Version, AFP_Test.AFP_Version)
   1.337 +
   1.338 +      case Jenkins.Start() :: _
   1.339 +      if log_file.lines.contains(Jenkins.CONFIGURATION) ||
   1.340 +         log_file.lines.last.startsWith(Jenkins.FINISHED) =>
   1.341 +        log_file.lines.dropWhile(_ != Jenkins.BUILD) match {
   1.342 +          case Jenkins.BUILD :: _ :: Jenkins.Start_Date(log_file.Strict_Date(start)) :: _ =>
   1.343 +            parse(Jenkins.engine, "", start.to(ZoneId.of("Europe/Berlin")), Jenkins.No_End,
   1.344 +              Jenkins.Isabelle_Version, Jenkins.AFP_Version)
   1.345 +          case _ => Meta_Info.empty
   1.346 +        }
   1.347 +
   1.348 +      case line :: _ if line.startsWith("\0") => Meta_Info.empty
   1.349 +      case List(Isatest.End(_)) => Meta_Info.empty
   1.350 +      case _ :: AFP_Test.Bad_Init() :: _ => Meta_Info.empty
   1.351 +      case Nil => Meta_Info.empty
   1.352 +
   1.353 +      case _ => log_file.err("cannot detect log file format")
   1.354 +    }
   1.355 +  }
   1.356 +
   1.357 +
   1.358 +
   1.359 +  /** build info: produced by isabelle build or build_history **/
   1.360 +
   1.361 +  val ML_STATISTICS_MARKER = "\fML_statistics = "
   1.362 +  val SESSION_NAME = "session_name"
   1.363 +
   1.364 +  object Session_Status extends Enumeration
   1.365 +  {
   1.366 +    val EXISTING = Value("existing")
   1.367 +    val FINISHED = Value("finished")
   1.368 +    val FAILED = Value("failed")
   1.369 +    val CANCELLED = Value("cancelled")
   1.370 +  }
   1.371 +
   1.372 +  sealed case class Session_Entry(
   1.373 +    chapter: String,
   1.374 +    groups: List[String],
   1.375 +    threads: Option[Int],
   1.376 +    timing: Timing,
   1.377 +    ml_timing: Timing,
   1.378 +    ml_statistics: List[Properties.T],
   1.379 +    heap_size: Option[Long],
   1.380 +    status: Session_Status.Value)
   1.381 +  {
   1.382 +    def finished: Boolean = status == Session_Status.FINISHED
   1.383 +  }
   1.384 +
   1.385 +  sealed case class Build_Info(sessions: Map[String, Session_Entry])
   1.386 +  {
   1.387 +    def session(name: String): Session_Entry = sessions(name)
   1.388 +    def get_session(name: String): Option[Session_Entry] = sessions.get(name)
   1.389 +
   1.390 +    def get_default[A](name: String, f: Session_Entry => A, x: A): A =
   1.391 +      get_session(name) match {
   1.392 +        case Some(entry) => f(entry)
   1.393 +        case None => x
   1.394 +      }
   1.395 +
   1.396 +    def finished_sessions: List[String] = sessions.keySet.iterator.filter(finished(_)).toList
   1.397 +    def finished(name: String): Boolean = get_default(name, _.finished, false)
   1.398 +    def timing(name: String): Timing = get_default(name, _.timing, Timing.zero)
   1.399 +    def ml_timing(name: String): Timing = get_default(name, _.ml_timing, Timing.zero)
   1.400 +  }
   1.401 +
   1.402 +  private def parse_build_info(log_file: Log_File): Build_Info =
   1.403 +  {
   1.404 +    object Chapter_Name
   1.405 +    {
   1.406 +      def unapply(s: String): Some[(String, String)] =
   1.407 +        space_explode('/', s) match {
   1.408 +          case List(chapter, name) => Some((chapter, name))
   1.409 +          case _ => Some(("", s))
   1.410 +        }
   1.411 +    }
   1.412 +
   1.413 +    val Session_No_Groups = new Regex("""^Session (\S+)$""")
   1.414 +    val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""")
   1.415 +    val Session_Finished1 =
   1.416 +      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
   1.417 +    val Session_Finished2 =
   1.418 +      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
   1.419 +    val Session_Timing =
   1.420 +      new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
   1.421 +    val Session_Started = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""")
   1.422 +    val Session_Failed = new Regex("""^(\S+) FAILED""")
   1.423 +    val Session_Cancelled = new Regex("""^(\S+) CANCELLED""")
   1.424 +    val Heap = new Regex("""^Heap (\S+) \((\d+) bytes\)$""")
   1.425 +
   1.426 +    var chapter = Map.empty[String, String]
   1.427 +    var groups = Map.empty[String, List[String]]
   1.428 +    var threads = Map.empty[String, Int]
   1.429 +    var timing = Map.empty[String, Timing]
   1.430 +    var ml_timing = Map.empty[String, Timing]
   1.431 +    var started = Set.empty[String]
   1.432 +    var failed = Set.empty[String]
   1.433 +    var cancelled = Set.empty[String]
   1.434 +    var ml_statistics = Map.empty[String, List[Properties.T]]
   1.435 +    var heap_sizes = Map.empty[String, Long]
   1.436 +
   1.437 +    def all_sessions: Set[String] =
   1.438 +      chapter.keySet ++ groups.keySet ++ threads.keySet ++ timing.keySet ++ ml_timing.keySet ++
   1.439 +      failed ++ cancelled ++ started ++ ml_statistics.keySet ++ heap_sizes.keySet
   1.440 +
   1.441 +
   1.442 +    for (line <- log_file.lines) {
   1.443 +      line match {
   1.444 +        case Session_No_Groups(Chapter_Name(chapt, name)) =>
   1.445 +          chapter += (name -> chapt)
   1.446 +          groups += (name -> Nil)
   1.447 +
   1.448 +        case Session_Groups(Chapter_Name(chapt, name), grps) =>
   1.449 +          chapter += (name -> chapt)
   1.450 +          groups += (name -> Word.explode(grps))
   1.451 +
   1.452 +        case Session_Started(name) =>
   1.453 +          started += name
   1.454 +
   1.455 +        case Session_Finished1(name,
   1.456 +            Value.Int(e1), Value.Int(e2), Value.Int(e3),
   1.457 +            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
   1.458 +          val elapsed = Time.hms(e1, e2, e3)
   1.459 +          val cpu = Time.hms(c1, c2, c3)
   1.460 +          timing += (name -> Timing(elapsed, cpu, Time.zero))
   1.461 +
   1.462 +        case Session_Finished2(name,
   1.463 +            Value.Int(e1), Value.Int(e2), Value.Int(e3)) =>
   1.464 +          val elapsed = Time.hms(e1, e2, e3)
   1.465 +          timing += (name -> Timing(elapsed, Time.zero, Time.zero))
   1.466 +
   1.467 +        case Session_Timing(name,
   1.468 +            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
   1.469 +          val elapsed = Time.seconds(e)
   1.470 +          val cpu = Time.seconds(c)
   1.471 +          val gc = Time.seconds(g)
   1.472 +          ml_timing += (name -> Timing(elapsed, cpu, gc))
   1.473 +          threads += (name -> t)
   1.474 +
   1.475 +        case Heap(name, Value.Long(size)) =>
   1.476 +          heap_sizes += (name -> size)
   1.477 +
   1.478 +        case _ if line.startsWith(ML_STATISTICS_MARKER) =>
   1.479 +          val (name, props) =
   1.480 +            Library.try_unprefix(ML_STATISTICS_MARKER, line).map(log_file.parse_props(_)) match {
   1.481 +              case Some((SESSION_NAME, session_name) :: props) => (session_name, props)
   1.482 +              case _ => log_file.err("malformed ML_statistics " + quote(line))
   1.483 +            }
   1.484 +          ml_statistics += (name -> (props :: ml_statistics.getOrElse(name, Nil)))
   1.485 +
   1.486 +        case _ =>
   1.487 +      }
   1.488 +    }
   1.489 +
   1.490 +    val sessions =
   1.491 +      Map(
   1.492 +        (for (name <- all_sessions.toList) yield {
   1.493 +          val status =
   1.494 +            if (failed(name)) Session_Status.FAILED
   1.495 +            else if (cancelled(name)) Session_Status.CANCELLED
   1.496 +            else if (timing.isDefinedAt(name) || ml_timing.isDefinedAt(name))
   1.497 +              Session_Status.FINISHED
   1.498 +            else if (started(name)) Session_Status.FAILED
   1.499 +            else Session_Status.EXISTING
   1.500 +          val entry =
   1.501 +            Session_Entry(
   1.502 +              chapter.getOrElse(name, ""),
   1.503 +              groups.getOrElse(name, Nil),
   1.504 +              threads.get(name),
   1.505 +              timing.getOrElse(name, Timing.zero),
   1.506 +              ml_timing.getOrElse(name, Timing.zero),
   1.507 +              ml_statistics.getOrElse(name, Nil).reverse,
   1.508 +              heap_sizes.get(name),
   1.509 +              status)
   1.510 +          (name -> entry)
   1.511 +        }):_*)
   1.512 +    Build_Info(sessions)
   1.513 +  }
   1.514 +
   1.515 +
   1.516 +
   1.517 +  /** session info: produced by "isabelle build" **/
   1.518 +
   1.519 +  sealed case class Session_Info(
   1.520 +    session_name: String,
   1.521 +    session_timing: Properties.T,
   1.522 +    command_timings: List[Properties.T],
   1.523 +    ml_statistics: List[Properties.T],
   1.524 +    task_statistics: List[Properties.T])
   1.525 +
   1.526 +  private def parse_session_info(
   1.527 +    log_file: Log_File,
   1.528 +    default_name: String,
   1.529 +    command_timings: Boolean,
   1.530 +    ml_statistics: Boolean,
   1.531 +    task_statistics: Boolean): Session_Info =
   1.532 +  {
   1.533 +    val xml_cache = new XML.Cache()
   1.534 +
   1.535 +    val session_name =
   1.536 +      log_file.find_line("\fSession.name = ") match {
   1.537 +        case None => default_name
   1.538 +        case Some(name) if default_name == "" || default_name == name => name
   1.539 +        case Some(name) => log_file.err("log from different session " + quote(name))
   1.540 +      }
   1.541 +    val session_timing = log_file.find_props("\fTiming = ") getOrElse Nil
   1.542 +    val command_timings_ =
   1.543 +      if (command_timings) log_file.filter_props("\fcommand_timing = ") else Nil
   1.544 +    val ml_statistics_ =
   1.545 +      if (ml_statistics) log_file.filter_props(ML_STATISTICS_MARKER) else Nil
   1.546 +    val task_statistics_ =
   1.547 +      if (task_statistics) log_file.filter_props("\ftask_statistics = ") else Nil
   1.548 +
   1.549 +    Session_Info(session_name, session_timing, command_timings_, ml_statistics_, task_statistics_)
   1.550 +  }
   1.551 +}