src/Pure/Tools/build_log.scala
author wenzelm
Sat Oct 08 15:39:42 2016 +0200 (2016-10-08)
changeset 64105 d93bd6d253c6
parent 64104 b70fa05d6746
child 64107 87d32aa83410
permissions -rw-r--r--
tuned signature;
wenzelm@64045
     1
/*  Title:      Pure/Tools/build_log.scala
wenzelm@64045
     2
    Author:     Makarius
wenzelm@64045
     3
wenzelm@64098
     4
Build log parsing for historic versions.
wenzelm@64045
     5
*/
wenzelm@64045
     6
wenzelm@64045
     7
package isabelle
wenzelm@64045
     8
wenzelm@64045
     9
wenzelm@64100
    10
import java.io.{File => JFile}
wenzelm@64100
    11
import java.time.ZoneId
wenzelm@64100
    12
import java.time.format.DateTimeParseException
wenzelm@64096
    13
import java.util.Locale
wenzelm@64061
    14
wenzelm@64054
    15
import scala.collection.mutable
wenzelm@64054
    16
import scala.util.matching.Regex
wenzelm@64054
    17
wenzelm@64054
    18
wenzelm@64045
    19
object Build_Log
wenzelm@64045
    20
{
wenzelm@64101
    21
  /** directory content **/
wenzelm@64101
    22
wenzelm@64101
    23
  def is_log(file: JFile): Boolean =
wenzelm@64101
    24
    List(".log", ".log.gz", ".log.xz").exists(ext => file.getName.endsWith(ext))
wenzelm@64101
    25
wenzelm@64101
    26
  def isatest_files(dir: Path): List[JFile] =
wenzelm@64101
    27
    File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("isatest-makeall-"))
wenzelm@64101
    28
wenzelm@64101
    29
  def afp_test_files(dir: Path): List[JFile] =
wenzelm@64101
    30
    File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("afp-test-devel-"))
wenzelm@64101
    31
wenzelm@64101
    32
wenzelm@64101
    33
wenzelm@64081
    34
  /** settings **/
wenzelm@64080
    35
wenzelm@64081
    36
  object Settings
wenzelm@64081
    37
  {
wenzelm@64081
    38
    val build_settings = List("ISABELLE_BUILD_OPTIONS")
wenzelm@64081
    39
    val ml_settings = List("ML_PLATFORM", "ML_HOME", "ML_SYSTEM", "ML_OPTIONS")
wenzelm@64081
    40
    val all_settings = build_settings ::: ml_settings
wenzelm@64081
    41
wenzelm@64081
    42
    type Entry = (String, String)
wenzelm@64081
    43
    type T = List[Entry]
wenzelm@64080
    44
wenzelm@64081
    45
    object Entry
wenzelm@64081
    46
    {
wenzelm@64081
    47
      def unapply(s: String): Option[Entry] =
wenzelm@64081
    48
        s.indexOf('=') match {
wenzelm@64081
    49
          case -1 => None
wenzelm@64081
    50
          case i =>
wenzelm@64081
    51
            val a = s.substring(0, i)
wenzelm@64081
    52
            val b = Library.perhaps_unquote(s.substring(i + 1))
wenzelm@64081
    53
            Some((a, b))
wenzelm@64081
    54
        }
wenzelm@64081
    55
      def apply(a: String, b: String): String = a + "=" + quote(b)
wenzelm@64081
    56
      def getenv(a: String): String = apply(a, Isabelle_System.getenv(a))
wenzelm@64081
    57
    }
wenzelm@64080
    58
wenzelm@64081
    59
    def show(): String =
wenzelm@64081
    60
      cat_lines(
wenzelm@64081
    61
        build_settings.map(Entry.getenv(_)) ::: List("") ::: ml_settings.map(Entry.getenv(_)))
wenzelm@64080
    62
  }
wenzelm@64080
    63
wenzelm@64080
    64
wenzelm@64100
    65
wenzelm@64062
    66
  /** log file **/
wenzelm@64045
    67
wenzelm@64062
    68
  object Log_File
wenzelm@64062
    69
  {
wenzelm@64062
    70
    def apply(name: String, lines: List[String]): Log_File =
wenzelm@64062
    71
      new Log_File(name, lines)
wenzelm@64062
    72
wenzelm@64062
    73
    def apply(name: String, text: String): Log_File =
wenzelm@64063
    74
      Log_File(name, Library.trim_split_lines(text))
wenzelm@64090
    75
wenzelm@64090
    76
    def apply(file: JFile): Log_File =
wenzelm@64090
    77
    {
wenzelm@64090
    78
      val name = file.getName
wenzelm@64090
    79
      val (base_name, text) =
wenzelm@64090
    80
        Library.try_unsuffix(".gz", name) match {
wenzelm@64090
    81
          case Some(base_name) => (base_name, File.read_gzip(file))
wenzelm@64090
    82
          case None =>
wenzelm@64090
    83
            Library.try_unsuffix(".xz", name) match {
wenzelm@64090
    84
              case Some(base_name) => (base_name, File.read_xz(file))
wenzelm@64090
    85
              case None => (name, File.read(file))
wenzelm@64090
    86
            }
wenzelm@64090
    87
          }
wenzelm@64090
    88
      apply(base_name, text)
wenzelm@64090
    89
    }
wenzelm@64090
    90
wenzelm@64090
    91
    def apply(path: Path): Log_File = apply(path.file)
wenzelm@64101
    92
wenzelm@64101
    93
    val Date_Format =
wenzelm@64101
    94
    {
wenzelm@64101
    95
      val fmts =
wenzelm@64101
    96
        Date.Formatter.variants(
wenzelm@64101
    97
          List("EEE MMM d HH:mm:ss VV yyyy", "EEE MMM d HH:mm:ss O yyyy"),
wenzelm@64104
    98
          List(Locale.ENGLISH, Locale.GERMAN)) :::
wenzelm@64104
    99
        List(Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(ZoneId.of("Europe/Berlin")))
wenzelm@64101
   100
wenzelm@64104
   101
      def tune_timezone(s: String): String =
wenzelm@64104
   102
        s match {
wenzelm@64101
   103
          case "CET" | "MET" => "GMT+1"
wenzelm@64101
   104
          case "CEST" | "MEST" => "GMT+2"
wenzelm@64104
   105
          case "EST" => "Europe/Berlin"
wenzelm@64104
   106
          case _ => s
wenzelm@64104
   107
        }
wenzelm@64104
   108
      def tune_weekday(s: String): String =
wenzelm@64104
   109
        s match {
wenzelm@64104
   110
          case "Die" => "Di"
wenzelm@64104
   111
          case "Mit" => "Mi"
wenzelm@64104
   112
          case "Don" => "Do"
wenzelm@64104
   113
          case "Fre" => "Fr"
wenzelm@64104
   114
          case "Sam" => "Sa"
wenzelm@64104
   115
          case "Son" => "So"
wenzelm@64104
   116
          case _ => s
wenzelm@64104
   117
        }
wenzelm@64104
   118
wenzelm@64104
   119
      def tune(s: String): String =
wenzelm@64104
   120
        Word.implode(
wenzelm@64104
   121
          Word.explode(s) match {
wenzelm@64104
   122
            case a :: "M\uFFFDr" :: bs => tune_weekday(a) :: "Mär" :: bs.map(tune_timezone(_))
wenzelm@64104
   123
            case a :: bs => tune_weekday(a) :: bs.map(tune_timezone(_))
wenzelm@64104
   124
            case Nil => Nil
wenzelm@64104
   125
          }
wenzelm@64104
   126
        )
wenzelm@64101
   127
wenzelm@64101
   128
      Date.Format.make(fmts, tune)
wenzelm@64101
   129
    }
wenzelm@64102
   130
  }
wenzelm@64102
   131
wenzelm@64102
   132
  class Log_File private(val name: String, val lines: List[String])
wenzelm@64102
   133
  {
wenzelm@64102
   134
    log_file =>
wenzelm@64102
   135
wenzelm@64102
   136
    override def toString: String = name
wenzelm@64102
   137
wenzelm@64102
   138
    def text: String = cat_lines(lines)
wenzelm@64102
   139
wenzelm@64102
   140
    def err(msg: String): Nothing =
wenzelm@64102
   141
      error("Error in log file " + quote(name) + ": " + msg)
wenzelm@64102
   142
wenzelm@64102
   143
wenzelm@64102
   144
    /* date format */
wenzelm@64101
   145
wenzelm@64101
   146
    object Strict_Date
wenzelm@64101
   147
    {
wenzelm@64101
   148
      def unapply(s: String): Some[Date] =
wenzelm@64102
   149
        try { Some(Log_File.Date_Format.parse(s)) }
wenzelm@64101
   150
        catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) }
wenzelm@64101
   151
    }
wenzelm@64101
   152
wenzelm@64101
   153
wenzelm@64062
   154
    /* inlined content */
wenzelm@64062
   155
wenzelm@64062
   156
    def find[A](f: String => Option[A]): Option[A] =
wenzelm@64062
   157
      lines.iterator.map(f).find(_.isDefined).map(_.get)
wenzelm@64062
   158
wenzelm@64062
   159
    def find_match(regex: Regex): Option[String] =
wenzelm@64062
   160
      lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1).
wenzelm@64062
   161
        map(res => res.get.head)
wenzelm@64062
   162
wenzelm@64062
   163
wenzelm@64062
   164
    /* settings */
wenzelm@64062
   165
wenzelm@64091
   166
    def get_setting(a: String): Option[Settings.Entry] =
wenzelm@64091
   167
      lines.find(_.startsWith(a + "=")) match {
wenzelm@64091
   168
        case Some(line) => Settings.Entry.unapply(line)
wenzelm@64091
   169
        case None => None
wenzelm@64091
   170
      }
wenzelm@64045
   171
wenzelm@64091
   172
    def get_settings(as: List[String]): Settings.T =
wenzelm@64091
   173
      for { a <- as; entry <- get_setting(a) } yield entry
wenzelm@64062
   174
wenzelm@64062
   175
wenzelm@64062
   176
    /* properties (YXML) */
wenzelm@64062
   177
wenzelm@64062
   178
    val xml_cache = new XML.Cache()
wenzelm@64062
   179
wenzelm@64062
   180
    def parse_props(text: String): Properties.T =
wenzelm@64062
   181
      xml_cache.props(XML.Decode.properties(YXML.parse_body(text)))
wenzelm@64062
   182
wenzelm@64062
   183
    def filter_props(prefix: String): List[Properties.T] =
wenzelm@64062
   184
      for (line <- lines; s <- Library.try_unprefix(prefix, line)) yield parse_props(s)
wenzelm@64045
   185
wenzelm@64062
   186
    def find_line(prefix: String): Option[String] =
wenzelm@64062
   187
      find(Library.try_unprefix(prefix, _))
wenzelm@64062
   188
wenzelm@64062
   189
    def find_props(prefix: String): Option[Properties.T] =
wenzelm@64062
   190
      find_line(prefix).map(parse_props(_))
wenzelm@64062
   191
wenzelm@64062
   192
wenzelm@64062
   193
    /* parse various formats */
wenzelm@64062
   194
wenzelm@64105
   195
    def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file)
wenzelm@64105
   196
wenzelm@64105
   197
    def parse_build_info(): Build_Info = Build_Log.parse_build_info(log_file)
wenzelm@64105
   198
wenzelm@64082
   199
    def parse_session_info(
wenzelm@64085
   200
        default_name: String = "",
wenzelm@64082
   201
        command_timings: Boolean = false,
wenzelm@64082
   202
        ml_statistics: Boolean = false,
wenzelm@64082
   203
        task_statistics: Boolean = false): Session_Info =
wenzelm@64082
   204
      Build_Log.parse_session_info(
wenzelm@64085
   205
        log_file, default_name, command_timings, ml_statistics, task_statistics)
wenzelm@64045
   206
  }
wenzelm@64045
   207
wenzelm@64045
   208
wenzelm@64098
   209
wenzelm@64105
   210
  /** meta info **/
wenzelm@64045
   211
wenzelm@64099
   212
  object Field
wenzelm@64045
   213
  {
wenzelm@64099
   214
    val build_host = "build_host"
wenzelm@64099
   215
    val build_start = "build_start"
wenzelm@64099
   216
    val build_end = "build_end"
wenzelm@64099
   217
    val isabelle_version = "isabelle_version"
wenzelm@64099
   218
    val afp_version = "afp_version"
wenzelm@64045
   219
  }
wenzelm@64054
   220
wenzelm@64099
   221
  object Kind extends Enumeration
wenzelm@64099
   222
  {
wenzelm@64104
   223
    val EMPTY = Value("empty")
wenzelm@64099
   224
    val ISATEST = Value("isatest")
wenzelm@64099
   225
    val AFP_TEST = Value("afp-test")
wenzelm@64099
   226
    val JENKINS = Value("jenkins")
wenzelm@64099
   227
  }
wenzelm@64098
   228
wenzelm@64105
   229
  object Meta_Info
wenzelm@64104
   230
  {
wenzelm@64105
   231
    val empty: Meta_Info = Meta_Info(Kind.EMPTY, Nil, Nil)
wenzelm@64104
   232
  }
wenzelm@64104
   233
wenzelm@64105
   234
  sealed case class Meta_Info(
wenzelm@64105
   235
    kind: Kind.Value, props: Properties.T, settings: List[(String, String)])
wenzelm@64103
   236
  {
wenzelm@64103
   237
    def is_empty: Boolean = props.isEmpty && settings.isEmpty
wenzelm@64103
   238
  }
wenzelm@64061
   239
wenzelm@64095
   240
  object Isatest
wenzelm@64095
   241
  {
wenzelm@64095
   242
    val Test_Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""")
wenzelm@64095
   243
    val Test_End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""")
wenzelm@64095
   244
    val Isabelle_Version = new Regex("""^Isabelle version: (\S+)$""")
wenzelm@64095
   245
    val No_AFP_Version = new Regex("""$.""")
wenzelm@64095
   246
  }
wenzelm@64095
   247
wenzelm@64061
   248
  object AFP
wenzelm@64061
   249
  {
wenzelm@64091
   250
    val Test_Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""")
wenzelm@64091
   251
    val Test_Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""")
wenzelm@64091
   252
    val Test_End = new Regex("""^End test on (.+), .+, elapsed time:.*$""")
wenzelm@64087
   253
    val Isabelle_Version = new Regex("""^Isabelle version: .* -- hg id (\S+)$""")
wenzelm@64087
   254
    val AFP_Version = new Regex("""^AFP version: .* -- hg id (\S+)$""")
wenzelm@64104
   255
    val Bad_Init = new Regex("""^cp:.*: Disc quota exceeded$""")
wenzelm@64061
   256
  }
wenzelm@64061
   257
wenzelm@64105
   258
  private def parse_meta_info(log_file: Log_File): Meta_Info =
wenzelm@64061
   259
  {
wenzelm@64099
   260
    def parse(kind: Kind.Value, start: Date, hostname: String,
wenzelm@64105
   261
      Test_End: Regex, Isabelle_Version: Regex, AFP_Version: Regex): Meta_Info =
wenzelm@64091
   262
    {
wenzelm@64091
   263
      val start_date = Field.build_start -> start.toString
wenzelm@64091
   264
      val end_date =
wenzelm@64091
   265
        log_file.lines.last match {
wenzelm@64101
   266
          case Test_End(log_file.Strict_Date(end_date)) =>
wenzelm@64091
   267
            List(Field.build_end -> end_date.toString)
wenzelm@64091
   268
          case _ => Nil
wenzelm@64091
   269
        }
wenzelm@64091
   270
wenzelm@64091
   271
      val build_host = if (hostname == "") Nil else List(Field.build_host -> hostname)
wenzelm@64061
   272
wenzelm@64091
   273
      val isabelle_version =
wenzelm@64095
   274
        log_file.find_match(Isabelle_Version).map(Field.isabelle_version -> _)
wenzelm@64091
   275
wenzelm@64091
   276
      val afp_version =
wenzelm@64095
   277
        log_file.find_match(AFP_Version).map(Field.afp_version -> _)
wenzelm@64062
   278
wenzelm@64105
   279
      Meta_Info(kind,
wenzelm@64095
   280
        start_date :: end_date ::: build_host :::
wenzelm@64095
   281
          isabelle_version.toList ::: afp_version.toList,
wenzelm@64091
   282
        log_file.get_settings(Settings.all_settings))
wenzelm@64091
   283
    }
wenzelm@64091
   284
wenzelm@64091
   285
    log_file.lines match {
wenzelm@64101
   286
      case Isatest.Test_Start(log_file.Strict_Date(start), hostname) :: _ =>
wenzelm@64099
   287
        parse(Kind.ISATEST, start, hostname,
wenzelm@64095
   288
          Isatest.Test_End, Isatest.Isabelle_Version, Isatest.No_AFP_Version)
wenzelm@64099
   289
wenzelm@64101
   290
      case AFP.Test_Start(log_file.Strict_Date(start), hostname) :: _ =>
wenzelm@64099
   291
        parse(Kind.AFP_TEST, start, hostname,
wenzelm@64095
   292
          AFP.Test_End, AFP.Isabelle_Version, AFP.AFP_Version)
wenzelm@64099
   293
wenzelm@64101
   294
      case AFP.Test_Start_Old(log_file.Strict_Date(start)) :: _ =>
wenzelm@64099
   295
        parse(Kind.AFP_TEST, start, "",
wenzelm@64095
   296
          AFP.Test_End, AFP.Isabelle_Version, AFP.AFP_Version)
wenzelm@64099
   297
wenzelm@64105
   298
      case line :: _ if line.startsWith("\0") => Meta_Info.empty
wenzelm@64105
   299
      case List(Isatest.Test_End(_)) => Meta_Info.empty
wenzelm@64105
   300
      case _ :: AFP.Bad_Init() :: _ => Meta_Info.empty
wenzelm@64105
   301
      case Nil => Meta_Info.empty
wenzelm@64104
   302
wenzelm@64062
   303
      case _ => log_file.err("cannot detect log header format")
wenzelm@64061
   304
    }
wenzelm@64061
   305
  }
wenzelm@64061
   306
wenzelm@64085
   307
wenzelm@64098
   308
wenzelm@64098
   309
  /** build info: produced by isabelle build **/
wenzelm@64085
   310
wenzelm@64061
   311
  object Session_Status extends Enumeration
wenzelm@64061
   312
  {
wenzelm@64085
   313
    val EXISTING = Value("existing")
wenzelm@64061
   314
    val FINISHED = Value("finished")
wenzelm@64061
   315
    val FAILED = Value("failed")
wenzelm@64061
   316
    val CANCELLED = Value("cancelled")
wenzelm@64061
   317
  }
wenzelm@64061
   318
wenzelm@64085
   319
  sealed case class Session_Entry(
wenzelm@64085
   320
    chapter: String,
wenzelm@64085
   321
    groups: List[String],
wenzelm@64085
   322
    threads: Option[Int],
wenzelm@64089
   323
    timing: Timing,
wenzelm@64089
   324
    ml_timing: Timing,
wenzelm@64085
   325
    status: Session_Status.Value)
wenzelm@64085
   326
  {
wenzelm@64085
   327
    def finished: Boolean = status == Session_Status.FINISHED
wenzelm@64085
   328
  }
wenzelm@64054
   329
wenzelm@64085
   330
  sealed case class Build_Info(sessions: Map[String, Session_Entry])
wenzelm@64054
   331
  {
wenzelm@64085
   332
    def session(name: String): Session_Entry = sessions(name)
wenzelm@64085
   333
    def get_session(name: String): Option[Session_Entry] = sessions.get(name)
wenzelm@64054
   334
wenzelm@64089
   335
    def get_default[A](name: String, f: Session_Entry => A, x: A): A =
wenzelm@64085
   336
      get_session(name) match {
wenzelm@64089
   337
        case Some(entry) => f(entry)
wenzelm@64089
   338
        case None => x
wenzelm@64085
   339
      }
wenzelm@64085
   340
wenzelm@64089
   341
    def finished(name: String): Boolean = get_default(name, _.finished, false)
wenzelm@64089
   342
    def timing(name: String): Timing = get_default(name, _.timing, Timing.zero)
wenzelm@64089
   343
    def ml_timing(name: String): Timing = get_default(name, _.ml_timing, Timing.zero)
wenzelm@64054
   344
  }
wenzelm@64054
   345
wenzelm@64085
   346
  private def parse_build_info(log_file: Log_File): Build_Info =
wenzelm@64085
   347
  {
wenzelm@64085
   348
    object Chapter_Name
wenzelm@64085
   349
    {
wenzelm@64085
   350
      def unapply(s: String): Some[(String, String)] =
wenzelm@64085
   351
        space_explode('/', s) match {
wenzelm@64085
   352
          case List(chapter, name) => Some((chapter, name))
wenzelm@64085
   353
          case _ => Some(("", s))
wenzelm@64085
   354
        }
wenzelm@64085
   355
    }
wenzelm@64054
   356
wenzelm@64085
   357
    val Session_No_Groups = new Regex("""^Session (\S+)$""")
wenzelm@64085
   358
    val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""")
wenzelm@64085
   359
    val Session_Finished1 =
wenzelm@64085
   360
      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
wenzelm@64085
   361
    val Session_Finished2 =
wenzelm@64085
   362
      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
wenzelm@64085
   363
    val Session_Timing =
wenzelm@64085
   364
      new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
wenzelm@64086
   365
    val Session_Started = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""")
wenzelm@64085
   366
    val Session_Failed = new Regex("""^(\S+) FAILED""")
wenzelm@64085
   367
    val Session_Cancelled = new Regex("""^(\S+) CANCELLED""")
wenzelm@64085
   368
wenzelm@64085
   369
    var chapter = Map.empty[String, String]
wenzelm@64085
   370
    var groups = Map.empty[String, List[String]]
wenzelm@64085
   371
    var threads = Map.empty[String, Int]
wenzelm@64054
   372
    var timing = Map.empty[String, Timing]
wenzelm@64085
   373
    var ml_timing = Map.empty[String, Timing]
wenzelm@64086
   374
    var started = Set.empty[String]
wenzelm@64085
   375
    var failed = Set.empty[String]
wenzelm@64085
   376
    var cancelled = Set.empty[String]
wenzelm@64085
   377
    def all_sessions: Set[String] =
wenzelm@64085
   378
      chapter.keySet ++ groups.keySet ++ threads.keySet ++
wenzelm@64086
   379
      timing.keySet ++ ml_timing.keySet ++ failed ++ cancelled ++ started
wenzelm@64085
   380
wenzelm@64054
   381
wenzelm@64062
   382
    for (line <- log_file.lines) {
wenzelm@64054
   383
      line match {
wenzelm@64085
   384
        case Session_No_Groups(Chapter_Name(chapt, name)) =>
wenzelm@64085
   385
          chapter += (name -> chapt)
wenzelm@64085
   386
          groups += (name -> Nil)
wenzelm@64085
   387
        case Session_Groups(Chapter_Name(chapt, name), grps) =>
wenzelm@64085
   388
          chapter += (name -> chapt)
wenzelm@64085
   389
          groups += (name -> Word.explode(grps))
wenzelm@64086
   390
        case Session_Started(name) =>
wenzelm@64086
   391
          started += name
wenzelm@64054
   392
        case Session_Finished1(name,
wenzelm@64054
   393
            Value.Int(e1), Value.Int(e2), Value.Int(e3),
wenzelm@64054
   394
            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
wenzelm@64054
   395
          val elapsed = Time.hms(e1, e2, e3)
wenzelm@64054
   396
          val cpu = Time.hms(c1, c2, c3)
wenzelm@64085
   397
          timing += (name -> Timing(elapsed, cpu, Time.zero))
wenzelm@64054
   398
        case Session_Finished2(name,
wenzelm@64054
   399
            Value.Int(e1), Value.Int(e2), Value.Int(e3)) =>
wenzelm@64054
   400
          val elapsed = Time.hms(e1, e2, e3)
wenzelm@64085
   401
          timing += (name -> Timing(elapsed, Time.zero, Time.zero))
wenzelm@64054
   402
        case Session_Timing(name,
wenzelm@64054
   403
            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
wenzelm@64054
   404
          val elapsed = Time.seconds(e)
wenzelm@64054
   405
          val cpu = Time.seconds(c)
wenzelm@64054
   406
          val gc = Time.seconds(g)
wenzelm@64085
   407
          ml_timing += (name -> Timing(elapsed, cpu, gc))
wenzelm@64054
   408
          threads += (name -> t)
wenzelm@64054
   409
        case _ =>
wenzelm@64054
   410
      }
wenzelm@64054
   411
    }
wenzelm@64054
   412
wenzelm@64085
   413
    val sessions =
wenzelm@64085
   414
      Map(
wenzelm@64085
   415
        (for (name <- all_sessions.toList) yield {
wenzelm@64085
   416
          val status =
wenzelm@64085
   417
            if (failed(name)) Session_Status.FAILED
wenzelm@64085
   418
            else if (cancelled(name)) Session_Status.CANCELLED
wenzelm@64086
   419
            else if (timing.isDefinedAt(name) || ml_timing.isDefinedAt(name))
wenzelm@64086
   420
              Session_Status.FINISHED
wenzelm@64086
   421
            else if (started(name)) Session_Status.FAILED
wenzelm@64085
   422
            else Session_Status.EXISTING
wenzelm@64085
   423
          val entry =
wenzelm@64085
   424
            Session_Entry(
wenzelm@64085
   425
              chapter.getOrElse(name, ""),
wenzelm@64085
   426
              groups.getOrElse(name, Nil),
wenzelm@64085
   427
              threads.get(name),
wenzelm@64089
   428
              timing.getOrElse(name, Timing.zero),
wenzelm@64089
   429
              ml_timing.getOrElse(name, Timing.zero),
wenzelm@64085
   430
              status)
wenzelm@64085
   431
          (name -> entry)
wenzelm@64085
   432
        }):_*)
wenzelm@64085
   433
    Build_Info(sessions)
wenzelm@64054
   434
  }
wenzelm@64099
   435
wenzelm@64099
   436
wenzelm@64099
   437
wenzelm@64099
   438
  /** session info: produced by "isabelle build" **/
wenzelm@64099
   439
wenzelm@64099
   440
  sealed case class Session_Info(
wenzelm@64099
   441
    session_name: String,
wenzelm@64099
   442
    session_timing: Properties.T,
wenzelm@64099
   443
    command_timings: List[Properties.T],
wenzelm@64099
   444
    ml_statistics: List[Properties.T],
wenzelm@64099
   445
    task_statistics: List[Properties.T])
wenzelm@64099
   446
wenzelm@64099
   447
  private def parse_session_info(
wenzelm@64099
   448
    log_file: Log_File,
wenzelm@64099
   449
    default_name: String,
wenzelm@64099
   450
    command_timings: Boolean,
wenzelm@64099
   451
    ml_statistics: Boolean,
wenzelm@64099
   452
    task_statistics: Boolean): Session_Info =
wenzelm@64099
   453
  {
wenzelm@64099
   454
    val xml_cache = new XML.Cache()
wenzelm@64099
   455
wenzelm@64099
   456
    val session_name =
wenzelm@64099
   457
      log_file.find_line("\fSession.name = ") match {
wenzelm@64099
   458
        case None => default_name
wenzelm@64099
   459
        case Some(name) if default_name == "" || default_name == name => name
wenzelm@64099
   460
        case Some(name) => log_file.err("log from different session " + quote(name))
wenzelm@64099
   461
      }
wenzelm@64099
   462
    val session_timing = log_file.find_props("\fTiming = ") getOrElse Nil
wenzelm@64099
   463
    val command_timings_ =
wenzelm@64099
   464
      if (command_timings) log_file.filter_props("\fcommand_timing = ") else Nil
wenzelm@64099
   465
    val ml_statistics_ =
wenzelm@64099
   466
      if (ml_statistics) log_file.filter_props("\fML_statistics = ") else Nil
wenzelm@64099
   467
    val task_statistics_ =
wenzelm@64099
   468
      if (task_statistics) log_file.filter_props("\ftask_statistics = ") else Nil
wenzelm@64099
   469
wenzelm@64099
   470
    Session_Info(session_name, session_timing, command_timings_, ml_statistics_, task_statistics_)
wenzelm@64099
   471
  }
wenzelm@64045
   472
}