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