src/Pure/Admin/build_log.scala
author wenzelm
Fri Apr 28 22:29:37 2017 +0200 (2017-04-28)
changeset 65621 551950dccec6
parent 65619 e33b3d57b7cb
child 65622 52f682598f6b
permissions -rw-r--r--
operations to read database;
wenzelm@64160
     1
/*  Title:      Pure/Admin/build_log.scala
wenzelm@64045
     2
    Author:     Makarius
wenzelm@64045
     3
wenzelm@65608
     4
Management of build log files and database storage.
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@64110
    12
import java.time.format.{DateTimeFormatter, DateTimeParseException}
wenzelm@64096
    13
import java.util.Locale
wenzelm@65599
    14
import java.sql.PreparedStatement
wenzelm@64061
    15
wenzelm@65600
    16
import scala.collection.immutable.SortedMap
wenzelm@64054
    17
import scala.collection.mutable
wenzelm@64054
    18
import scala.util.matching.Regex
wenzelm@64054
    19
wenzelm@64054
    20
wenzelm@64045
    21
object Build_Log
wenzelm@64045
    22
{
wenzelm@64298
    23
  /** content **/
wenzelm@64101
    24
wenzelm@64298
    25
  /* properties */
wenzelm@64150
    26
wenzelm@64298
    27
  object Prop
wenzelm@64298
    28
  {
wenzelm@64303
    29
    val separator = '\u000b'
wenzelm@64303
    30
wenzelm@65621
    31
    def cat_multiple(args: List[String]): String =
wenzelm@65621
    32
      args.mkString(separator.toString)
wenzelm@65621
    33
wenzelm@64300
    34
    def multiple(name: String, args: List[String]): Properties.T =
wenzelm@64300
    35
      if (args.isEmpty) Nil
wenzelm@65621
    36
      else List(name -> cat_multiple(args))
wenzelm@64299
    37
wenzelm@65601
    38
    def multiple_lines(s: String): String =
wenzelm@65601
    39
      cat_lines(Library.space_explode(separator, s))
wenzelm@65601
    40
wenzelm@65591
    41
    val build_tags = SQL.Column.string("build_tags")  // multiple
wenzelm@65591
    42
    val build_args = SQL.Column.string("build_args")  // multiple
wenzelm@65591
    43
    val build_group_id = SQL.Column.string("build_group_id")
wenzelm@65591
    44
    val build_id = SQL.Column.string("build_id")
wenzelm@65591
    45
    val build_engine = SQL.Column.string("build_engine")
wenzelm@65591
    46
    val build_host = SQL.Column.string("build_host")
wenzelm@65591
    47
    val build_start = SQL.Column.date("build_start")
wenzelm@65591
    48
    val build_end = SQL.Column.date("build_end")
wenzelm@65591
    49
    val isabelle_version = SQL.Column.string("isabelle_version")
wenzelm@65591
    50
    val afp_version = SQL.Column.string("afp_version")
wenzelm@65591
    51
wenzelm@65611
    52
    val all_props: List[SQL.Column] =
wenzelm@65591
    53
      List(build_tags, build_args, build_group_id, build_id, build_engine,
wenzelm@65591
    54
        build_host, build_start, build_end, isabelle_version, afp_version)
wenzelm@64298
    55
  }
wenzelm@64150
    56
wenzelm@64150
    57
wenzelm@64298
    58
  /* settings */
wenzelm@64080
    59
wenzelm@64081
    60
  object Settings
wenzelm@64081
    61
  {
wenzelm@65611
    62
    val ISABELLE_BUILD_OPTIONS = SQL.Column.string("ISABELLE_BUILD_OPTIONS")
wenzelm@65611
    63
    val ML_PLATFORM = SQL.Column.string("ML_PLATFORM")
wenzelm@65611
    64
    val ML_HOME = SQL.Column.string("ML_HOME")
wenzelm@65611
    65
    val ML_SYSTEM = SQL.Column.string("ML_SYSTEM")
wenzelm@65611
    66
    val ML_OPTIONS = SQL.Column.string("ML_OPTIONS")
wenzelm@65611
    67
wenzelm@65611
    68
    val ml_settings = List(ML_PLATFORM, ML_HOME, ML_SYSTEM, ML_OPTIONS)
wenzelm@65611
    69
    val all_settings = ISABELLE_BUILD_OPTIONS :: ml_settings
wenzelm@64081
    70
wenzelm@64081
    71
    type Entry = (String, String)
wenzelm@64081
    72
    type T = List[Entry]
wenzelm@64080
    73
wenzelm@64081
    74
    object Entry
wenzelm@64081
    75
    {
wenzelm@64081
    76
      def unapply(s: String): Option[Entry] =
wenzelm@64081
    77
        s.indexOf('=') match {
wenzelm@64081
    78
          case -1 => None
wenzelm@64081
    79
          case i =>
wenzelm@64081
    80
            val a = s.substring(0, i)
wenzelm@64081
    81
            val b = Library.perhaps_unquote(s.substring(i + 1))
wenzelm@64081
    82
            Some((a, b))
wenzelm@64081
    83
        }
wenzelm@64081
    84
      def apply(a: String, b: String): String = a + "=" + quote(b)
wenzelm@64081
    85
      def getenv(a: String): String = apply(a, Isabelle_System.getenv(a))
wenzelm@64081
    86
    }
wenzelm@64080
    87
wenzelm@64081
    88
    def show(): String =
wenzelm@64081
    89
      cat_lines(
wenzelm@65611
    90
        List(Entry.getenv(ISABELLE_BUILD_OPTIONS.name), "") :::
wenzelm@65611
    91
        ml_settings.map(c => Entry.getenv(c.name)))
wenzelm@64080
    92
  }
wenzelm@64080
    93
wenzelm@64080
    94
wenzelm@64298
    95
  /* file names */
wenzelm@64298
    96
wenzelm@64298
    97
  def log_date(date: Date): String =
wenzelm@64298
    98
    String.format(Locale.ROOT, "%s.%05d",
wenzelm@64298
    99
      DateTimeFormatter.ofPattern("yyyy-MM-dd").format(date.rep),
wenzelm@64298
   100
      new java.lang.Long((date.time - date.midnight.time).ms / 1000))
wenzelm@64298
   101
wenzelm@64298
   102
  def log_subdir(date: Date): Path =
wenzelm@64298
   103
    Path.explode("log") + Path.explode(date.rep.getYear.toString)
wenzelm@64298
   104
wenzelm@64298
   105
  def log_filename(engine: String, date: Date, more: List[String] = Nil): Path =
wenzelm@64298
   106
    Path.explode((engine :: log_date(date) :: more).mkString("", "_", ".log"))
wenzelm@64298
   107
wenzelm@64298
   108
wenzelm@64100
   109
wenzelm@64062
   110
  /** log file **/
wenzelm@64045
   111
wenzelm@64155
   112
  def print_date(date: Date): String = Log_File.Date_Format(date)
wenzelm@64155
   113
wenzelm@64062
   114
  object Log_File
wenzelm@64062
   115
  {
wenzelm@65607
   116
    /* log file */
wenzelm@65607
   117
wenzelm@65609
   118
    def plain_name(name: String): String =
wenzelm@65609
   119
    {
wenzelm@65609
   120
      List(".log", ".log.gz", ".log.xz", ".gz", ".xz").find(name.endsWith(_)) match {
wenzelm@65609
   121
        case Some(s) => Library.try_unsuffix(s, name).get
wenzelm@65609
   122
        case None => name
wenzelm@65609
   123
      }
wenzelm@65609
   124
    }
wenzelm@65609
   125
wenzelm@64062
   126
    def apply(name: String, lines: List[String]): Log_File =
wenzelm@65609
   127
      new Log_File(plain_name(name), lines)
wenzelm@64062
   128
wenzelm@64062
   129
    def apply(name: String, text: String): Log_File =
wenzelm@64063
   130
      Log_File(name, Library.trim_split_lines(text))
wenzelm@64090
   131
wenzelm@64090
   132
    def apply(file: JFile): Log_File =
wenzelm@64090
   133
    {
wenzelm@64090
   134
      val name = file.getName
wenzelm@65609
   135
      val text =
wenzelm@65609
   136
        if (name.endsWith(".gz")) File.read_gzip(file)
wenzelm@65609
   137
        else if (name.endsWith(".xz")) File.read_xz(file)
wenzelm@65609
   138
        else File.read(file)
wenzelm@65609
   139
      apply(name, text)
wenzelm@64090
   140
    }
wenzelm@64090
   141
wenzelm@64090
   142
    def apply(path: Path): Log_File = apply(path.file)
wenzelm@64101
   143
wenzelm@64110
   144
wenzelm@65607
   145
    /* log file collections */
wenzelm@65607
   146
wenzelm@65607
   147
    def is_log(file: JFile,
wenzelm@65607
   148
      prefixes: List[String] =
wenzelm@65609
   149
        List(Build_History.log_prefix, Isatest.log_prefix, AFP_Test.log_prefix),
wenzelm@65609
   150
      suffixes: List[String] = List(".log", ".log.gz", ".log.xz")): Boolean =
wenzelm@65607
   151
    {
wenzelm@65607
   152
      val name = file.getName
wenzelm@65607
   153
      prefixes.exists(name.startsWith(_)) &&
wenzelm@65607
   154
      suffixes.exists(name.endsWith(_))
wenzelm@65607
   155
    }
wenzelm@65607
   156
wenzelm@65607
   157
    def find_files(dirs: Iterable[Path]): List[JFile] =
wenzelm@65607
   158
      dirs.iterator.flatMap(dir => File.find_files(dir.file, is_log(_))).toList
wenzelm@65607
   159
wenzelm@65607
   160
wenzelm@64110
   161
    /* date format */
wenzelm@64110
   162
wenzelm@64101
   163
    val Date_Format =
wenzelm@64101
   164
    {
wenzelm@64101
   165
      val fmts =
wenzelm@64101
   166
        Date.Formatter.variants(
wenzelm@64116
   167
          List("EEE MMM d HH:mm:ss O yyyy", "EEE MMM d HH:mm:ss VV yyyy"),
wenzelm@64104
   168
          List(Locale.ENGLISH, Locale.GERMAN)) :::
wenzelm@64110
   169
        List(
wenzelm@64110
   170
          DateTimeFormatter.RFC_1123_DATE_TIME,
wenzelm@64110
   171
          Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(ZoneId.of("Europe/Berlin")))
wenzelm@64101
   172
wenzelm@64104
   173
      def tune_timezone(s: String): String =
wenzelm@64104
   174
        s match {
wenzelm@64101
   175
          case "CET" | "MET" => "GMT+1"
wenzelm@64101
   176
          case "CEST" | "MEST" => "GMT+2"
wenzelm@64104
   177
          case "EST" => "Europe/Berlin"
wenzelm@64104
   178
          case _ => s
wenzelm@64104
   179
        }
wenzelm@64104
   180
      def tune_weekday(s: String): String =
wenzelm@64104
   181
        s match {
wenzelm@64104
   182
          case "Die" => "Di"
wenzelm@64104
   183
          case "Mit" => "Mi"
wenzelm@64104
   184
          case "Don" => "Do"
wenzelm@64104
   185
          case "Fre" => "Fr"
wenzelm@64104
   186
          case "Sam" => "Sa"
wenzelm@64104
   187
          case "Son" => "So"
wenzelm@64104
   188
          case _ => s
wenzelm@64104
   189
        }
wenzelm@64104
   190
wenzelm@64104
   191
      def tune(s: String): String =
wenzelm@64104
   192
        Word.implode(
wenzelm@64104
   193
          Word.explode(s) match {
wenzelm@64104
   194
            case a :: "M\uFFFDr" :: bs => tune_weekday(a) :: "Mär" :: bs.map(tune_timezone(_))
wenzelm@64104
   195
            case a :: bs => tune_weekday(a) :: bs.map(tune_timezone(_))
wenzelm@64104
   196
            case Nil => Nil
wenzelm@64104
   197
          }
wenzelm@64104
   198
        )
wenzelm@64101
   199
wenzelm@64101
   200
      Date.Format.make(fmts, tune)
wenzelm@64101
   201
    }
wenzelm@64117
   202
wenzelm@64117
   203
wenzelm@64117
   204
    /* inlined content */
wenzelm@64117
   205
wenzelm@64119
   206
    def print_props(marker: String, props: Properties.T): String =
wenzelm@64119
   207
      marker + YXML.string_of_body(XML.Encode.properties(props))
wenzelm@64102
   208
  }
wenzelm@64102
   209
wenzelm@64102
   210
  class Log_File private(val name: String, val lines: List[String])
wenzelm@64102
   211
  {
wenzelm@64102
   212
    log_file =>
wenzelm@64102
   213
wenzelm@64102
   214
    override def toString: String = name
wenzelm@64102
   215
wenzelm@64102
   216
    def text: String = cat_lines(lines)
wenzelm@64102
   217
wenzelm@64102
   218
    def err(msg: String): Nothing =
wenzelm@64102
   219
      error("Error in log file " + quote(name) + ": " + msg)
wenzelm@64102
   220
wenzelm@64102
   221
wenzelm@64102
   222
    /* date format */
wenzelm@64101
   223
wenzelm@64101
   224
    object Strict_Date
wenzelm@64101
   225
    {
wenzelm@64101
   226
      def unapply(s: String): Some[Date] =
wenzelm@64102
   227
        try { Some(Log_File.Date_Format.parse(s)) }
wenzelm@64101
   228
        catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) }
wenzelm@64101
   229
    }
wenzelm@64101
   230
wenzelm@64101
   231
wenzelm@64062
   232
    /* inlined content */
wenzelm@64062
   233
wenzelm@64062
   234
    def find[A](f: String => Option[A]): Option[A] =
wenzelm@64062
   235
      lines.iterator.map(f).find(_.isDefined).map(_.get)
wenzelm@64062
   236
wenzelm@64196
   237
    def find_line(marker: String): Option[String] =
wenzelm@64196
   238
      find(Library.try_unprefix(marker, _))
wenzelm@64196
   239
wenzelm@64062
   240
    def find_match(regex: Regex): Option[String] =
wenzelm@64062
   241
      lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1).
wenzelm@64062
   242
        map(res => res.get.head)
wenzelm@64062
   243
wenzelm@64062
   244
wenzelm@64062
   245
    /* settings */
wenzelm@64062
   246
wenzelm@64091
   247
    def get_setting(a: String): Option[Settings.Entry] =
wenzelm@64091
   248
      lines.find(_.startsWith(a + "=")) match {
wenzelm@64091
   249
        case Some(line) => Settings.Entry.unapply(line)
wenzelm@64091
   250
        case None => None
wenzelm@64091
   251
      }
wenzelm@64045
   252
wenzelm@65611
   253
    def get_all_settings: Settings.T =
wenzelm@65611
   254
      for { c <- Settings.all_settings; entry <- get_setting(c.name) }
wenzelm@65611
   255
      yield entry
wenzelm@64062
   256
wenzelm@64062
   257
wenzelm@64062
   258
    /* properties (YXML) */
wenzelm@64062
   259
wenzelm@64062
   260
    val xml_cache = new XML.Cache()
wenzelm@64062
   261
wenzelm@64062
   262
    def parse_props(text: String): Properties.T =
wenzelm@64062
   263
      xml_cache.props(XML.Decode.properties(YXML.parse_body(text)))
wenzelm@64062
   264
wenzelm@64119
   265
    def filter_props(marker: String): List[Properties.T] =
wenzelm@64196
   266
      for {
wenzelm@64196
   267
        line <- lines
wenzelm@64196
   268
        s <- Library.try_unprefix(marker, line)
wenzelm@64196
   269
        if YXML.detect(s)
wenzelm@64196
   270
      } yield parse_props(s)
wenzelm@64062
   271
wenzelm@64119
   272
    def find_props(marker: String): Option[Properties.T] =
wenzelm@64196
   273
      find_line(marker) match {
wenzelm@64196
   274
        case Some(text) if YXML.detect(text) => Some(parse_props(text))
wenzelm@64196
   275
        case _ => None
wenzelm@64196
   276
      }
wenzelm@64062
   277
wenzelm@64062
   278
wenzelm@64062
   279
    /* parse various formats */
wenzelm@64062
   280
wenzelm@64105
   281
    def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file)
wenzelm@64105
   282
wenzelm@64105
   283
    def parse_build_info(): Build_Info = Build_Log.parse_build_info(log_file)
wenzelm@64105
   284
wenzelm@64082
   285
    def parse_session_info(
wenzelm@64082
   286
        command_timings: Boolean = false,
wenzelm@64082
   287
        ml_statistics: Boolean = false,
wenzelm@64082
   288
        task_statistics: Boolean = false): Session_Info =
wenzelm@65318
   289
      Build_Log.parse_session_info(log_file, command_timings, ml_statistics, task_statistics)
wenzelm@64045
   290
  }
wenzelm@64045
   291
wenzelm@64045
   292
wenzelm@64098
   293
wenzelm@65276
   294
  /** digested meta info: produced by Admin/build_history in log.xz file **/
wenzelm@64045
   295
wenzelm@64108
   296
  object Meta_Info
wenzelm@64099
   297
  {
wenzelm@64108
   298
    val empty: Meta_Info = Meta_Info(Nil, Nil)
wenzelm@65605
   299
wenzelm@65609
   300
    val log_name = SQL.Column.string("log_name", primary_key = true)
wenzelm@65605
   301
    val table =
wenzelm@65611
   302
      SQL.Table("isabelle_build_log_meta_info", log_name :: Prop.all_props ::: Settings.all_settings)
wenzelm@64099
   303
  }
wenzelm@64098
   304
wenzelm@65611
   305
  sealed case class Meta_Info(props: Properties.T, settings: Settings.T)
wenzelm@64103
   306
  {
wenzelm@64103
   307
    def is_empty: Boolean = props.isEmpty && settings.isEmpty
wenzelm@65599
   308
wenzelm@65611
   309
    def get(c: SQL.Column): Option[String] =
wenzelm@65611
   310
      Properties.get(props, c.name) orElse
wenzelm@65611
   311
      Properties.get(settings, c.name)
wenzelm@65611
   312
wenzelm@65611
   313
    def get_date(c: SQL.Column): Option[Date] =
wenzelm@65611
   314
      get(c).map(Log_File.Date_Format.parse(_))
wenzelm@64103
   315
  }
wenzelm@64061
   316
wenzelm@64095
   317
  object Isatest
wenzelm@64095
   318
  {
wenzelm@65588
   319
    val log_prefix = "isatest-makeall-"
wenzelm@64108
   320
    val engine = "isatest"
wenzelm@64109
   321
    val Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""")
wenzelm@64109
   322
    val End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""")
wenzelm@64095
   323
    val Isabelle_Version = new Regex("""^Isabelle version: (\S+)$""")
wenzelm@64095
   324
    val No_AFP_Version = new Regex("""$.""")
wenzelm@64095
   325
  }
wenzelm@64095
   326
wenzelm@64109
   327
  object AFP_Test
wenzelm@64061
   328
  {
wenzelm@65588
   329
    val log_prefix = "afp-test-devel-"
wenzelm@64108
   330
    val engine = "afp-test"
wenzelm@64109
   331
    val Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""")
wenzelm@64109
   332
    val Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""")
wenzelm@64109
   333
    val End = new Regex("""^End test on (.+), .+, elapsed time:.*$""")
wenzelm@64087
   334
    val Isabelle_Version = new Regex("""^Isabelle version: .* -- hg id (\S+)$""")
wenzelm@64087
   335
    val AFP_Version = new Regex("""^AFP version: .* -- hg id (\S+)$""")
wenzelm@64104
   336
    val Bad_Init = new Regex("""^cp:.*: Disc quota exceeded$""")
wenzelm@64061
   337
  }
wenzelm@64061
   338
wenzelm@64110
   339
  object Jenkins
wenzelm@64110
   340
  {
wenzelm@64110
   341
    val engine = "jenkins"
wenzelm@64110
   342
    val Start = new Regex("""^Started .*$""")
wenzelm@64110
   343
    val Start_Date = new Regex("""^Build started at (.+)$""")
wenzelm@64110
   344
    val No_End = new Regex("""$.""")
wenzelm@64110
   345
    val Isabelle_Version = new Regex("""^Isabelle id (\S+)$""")
wenzelm@64110
   346
    val AFP_Version = new Regex("""^AFP id (\S+)$""")
wenzelm@64110
   347
    val CONFIGURATION = "=== CONFIGURATION ==="
wenzelm@64110
   348
    val BUILD = "=== BUILD ==="
wenzelm@64110
   349
    val FINISHED = "Finished: "
wenzelm@64110
   350
  }
wenzelm@64110
   351
wenzelm@64105
   352
  private def parse_meta_info(log_file: Log_File): Meta_Info =
wenzelm@64061
   353
  {
wenzelm@64108
   354
    def parse(engine: String, host: String, start: Date,
wenzelm@64109
   355
      End: Regex, Isabelle_Version: Regex, AFP_Version: Regex): Meta_Info =
wenzelm@64091
   356
    {
wenzelm@64296
   357
      val build_id =
wenzelm@64296
   358
      {
wenzelm@64296
   359
        val prefix = if (host != "") host else if (engine != "") engine else ""
wenzelm@64296
   360
        (if (prefix == "") "build" else prefix) + ":" + start.time.ms
wenzelm@64296
   361
      }
wenzelm@65591
   362
      val build_engine = if (engine == "") Nil else List(Prop.build_engine.name -> engine)
wenzelm@65591
   363
      val build_host = if (host == "") Nil else List(Prop.build_host.name -> host)
wenzelm@64108
   364
wenzelm@65599
   365
      val start_date = List(Prop.build_start.name -> print_date(start))
wenzelm@64091
   366
      val end_date =
wenzelm@64091
   367
        log_file.lines.last match {
wenzelm@64109
   368
          case End(log_file.Strict_Date(end_date)) =>
wenzelm@65599
   369
            List(Prop.build_end.name -> print_date(end_date))
wenzelm@64091
   370
          case _ => Nil
wenzelm@64091
   371
        }
wenzelm@64091
   372
wenzelm@64091
   373
      val isabelle_version =
wenzelm@65591
   374
        log_file.find_match(Isabelle_Version).map(Prop.isabelle_version.name -> _)
wenzelm@64091
   375
      val afp_version =
wenzelm@65591
   376
        log_file.find_match(AFP_Version).map(Prop.afp_version.name -> _)
wenzelm@64062
   377
wenzelm@65591
   378
      Meta_Info((Prop.build_id.name -> build_id) :: build_engine ::: build_host :::
wenzelm@64108
   379
          start_date ::: end_date ::: isabelle_version.toList ::: afp_version.toList,
wenzelm@65611
   380
        log_file.get_all_settings)
wenzelm@64091
   381
    }
wenzelm@64091
   382
wenzelm@64091
   383
    log_file.lines match {
wenzelm@64119
   384
      case line :: _ if line.startsWith(Build_History.META_INFO_MARKER) =>
wenzelm@64119
   385
        Meta_Info(log_file.find_props(Build_History.META_INFO_MARKER).get,
wenzelm@65611
   386
          log_file.get_all_settings)
wenzelm@64117
   387
wenzelm@64109
   388
      case Isatest.Start(log_file.Strict_Date(start), host) :: _ =>
wenzelm@64109
   389
        parse(Isatest.engine, host, start, Isatest.End,
wenzelm@64108
   390
          Isatest.Isabelle_Version, Isatest.No_AFP_Version)
wenzelm@64099
   391
wenzelm@64109
   392
      case AFP_Test.Start(log_file.Strict_Date(start), host) :: _ =>
wenzelm@64109
   393
        parse(AFP_Test.engine, host, start, AFP_Test.End,
wenzelm@64109
   394
          AFP_Test.Isabelle_Version, AFP_Test.AFP_Version)
wenzelm@64099
   395
wenzelm@64109
   396
      case AFP_Test.Start_Old(log_file.Strict_Date(start)) :: _ =>
wenzelm@64109
   397
        parse(AFP_Test.engine, "", start, AFP_Test.End,
wenzelm@64109
   398
          AFP_Test.Isabelle_Version, AFP_Test.AFP_Version)
wenzelm@64099
   399
wenzelm@64110
   400
      case Jenkins.Start() :: _
wenzelm@64110
   401
      if log_file.lines.contains(Jenkins.CONFIGURATION) ||
wenzelm@64110
   402
         log_file.lines.last.startsWith(Jenkins.FINISHED) =>
wenzelm@64110
   403
        log_file.lines.dropWhile(_ != Jenkins.BUILD) match {
wenzelm@64110
   404
          case Jenkins.BUILD :: _ :: Jenkins.Start_Date(log_file.Strict_Date(start)) :: _ =>
wenzelm@64111
   405
            parse(Jenkins.engine, "", start.to(ZoneId.of("Europe/Berlin")), Jenkins.No_End,
wenzelm@64110
   406
              Jenkins.Isabelle_Version, Jenkins.AFP_Version)
wenzelm@64110
   407
          case _ => Meta_Info.empty
wenzelm@64110
   408
        }
wenzelm@64110
   409
wenzelm@64341
   410
      case line :: _ if line.startsWith("\u0000") => Meta_Info.empty
wenzelm@64109
   411
      case List(Isatest.End(_)) => Meta_Info.empty
wenzelm@64109
   412
      case _ :: AFP_Test.Bad_Init() :: _ => Meta_Info.empty
wenzelm@64105
   413
      case Nil => Meta_Info.empty
wenzelm@64104
   414
wenzelm@64110
   415
      case _ => log_file.err("cannot detect log file format")
wenzelm@64061
   416
    }
wenzelm@64061
   417
  }
wenzelm@64061
   418
wenzelm@64085
   419
wenzelm@64098
   420
wenzelm@65276
   421
  /** build info: toplevel output of isabelle build or Admin/build_history **/
wenzelm@64119
   422
wenzelm@64119
   423
  val ML_STATISTICS_MARKER = "\fML_statistics = "
wenzelm@64119
   424
  val SESSION_NAME = "session_name"
wenzelm@64085
   425
wenzelm@64061
   426
  object Session_Status extends Enumeration
wenzelm@64061
   427
  {
wenzelm@64085
   428
    val EXISTING = Value("existing")
wenzelm@64061
   429
    val FINISHED = Value("finished")
wenzelm@64061
   430
    val FAILED = Value("failed")
wenzelm@64061
   431
    val CANCELLED = Value("cancelled")
wenzelm@64061
   432
  }
wenzelm@64061
   433
wenzelm@64085
   434
  sealed case class Session_Entry(
wenzelm@64085
   435
    chapter: String,
wenzelm@64085
   436
    groups: List[String],
wenzelm@64085
   437
    threads: Option[Int],
wenzelm@64089
   438
    timing: Timing,
wenzelm@64089
   439
    ml_timing: Timing,
wenzelm@64119
   440
    ml_statistics: List[Properties.T],
wenzelm@64120
   441
    heap_size: Option[Long],
wenzelm@64085
   442
    status: Session_Status.Value)
wenzelm@64085
   443
  {
wenzelm@64085
   444
    def finished: Boolean = status == Session_Status.FINISHED
wenzelm@64085
   445
  }
wenzelm@64054
   446
wenzelm@65599
   447
  object Build_Info
wenzelm@65599
   448
  {
wenzelm@65613
   449
    val session_name = SQL.Column.string("session_name", primary_key = true)
wenzelm@65613
   450
    val chapter = SQL.Column.string("chapter")
wenzelm@65613
   451
    val groups = SQL.Column.string("groups")
wenzelm@65613
   452
    val threads = SQL.Column.int("threads")
wenzelm@65616
   453
    val timing_elapsed = SQL.Column.long("timing_elapsed")
wenzelm@65616
   454
    val timing_cpu = SQL.Column.long("timing_cpu")
wenzelm@65616
   455
    val timing_gc = SQL.Column.long("timing_gc")
wenzelm@65616
   456
    val ml_timing_elapsed = SQL.Column.long("ml_timing_elapsed")
wenzelm@65616
   457
    val ml_timing_cpu = SQL.Column.long("ml_timing_cpu")
wenzelm@65616
   458
    val ml_timing_gc = SQL.Column.long("ml_timing_gc")
wenzelm@65613
   459
    val ml_statistics = SQL.Column.bytes("ml_statistics")
wenzelm@65613
   460
    val heap_size = SQL.Column.long("heap_size")
wenzelm@65613
   461
    val status = SQL.Column.string("status")
wenzelm@65605
   462
wenzelm@65613
   463
    val table = SQL.Table("isabelle_build_log_build_info",
wenzelm@65616
   464
      List(Meta_Info.log_name, session_name, chapter, groups, threads, timing_elapsed, timing_cpu,
wenzelm@65616
   465
        timing_gc, ml_timing_elapsed, ml_timing_cpu, ml_timing_gc, ml_statistics, heap_size, status))
wenzelm@65599
   466
  }
wenzelm@65599
   467
wenzelm@64085
   468
  sealed case class Build_Info(sessions: Map[String, Session_Entry])
wenzelm@64054
   469
  {
wenzelm@64085
   470
    def session(name: String): Session_Entry = sessions(name)
wenzelm@64085
   471
    def get_session(name: String): Option[Session_Entry] = sessions.get(name)
wenzelm@64054
   472
wenzelm@64089
   473
    def get_default[A](name: String, f: Session_Entry => A, x: A): A =
wenzelm@64085
   474
      get_session(name) match {
wenzelm@64089
   475
        case Some(entry) => f(entry)
wenzelm@64089
   476
        case None => x
wenzelm@64085
   477
      }
wenzelm@64085
   478
wenzelm@64119
   479
    def finished_sessions: List[String] = sessions.keySet.iterator.filter(finished(_)).toList
wenzelm@64089
   480
    def finished(name: String): Boolean = get_default(name, _.finished, false)
wenzelm@64089
   481
    def timing(name: String): Timing = get_default(name, _.timing, Timing.zero)
wenzelm@64089
   482
    def ml_timing(name: String): Timing = get_default(name, _.ml_timing, Timing.zero)
wenzelm@65052
   483
    def ml_statistics(name: String): ML_Statistics =
wenzelm@65052
   484
      get_default(name, entry => ML_Statistics(name, entry.ml_statistics), ML_Statistics.empty)
wenzelm@64054
   485
  }
wenzelm@64054
   486
wenzelm@64085
   487
  private def parse_build_info(log_file: Log_File): Build_Info =
wenzelm@64085
   488
  {
wenzelm@64085
   489
    object Chapter_Name
wenzelm@64085
   490
    {
wenzelm@64085
   491
      def unapply(s: String): Some[(String, String)] =
wenzelm@64085
   492
        space_explode('/', s) match {
wenzelm@64085
   493
          case List(chapter, name) => Some((chapter, name))
wenzelm@64085
   494
          case _ => Some(("", s))
wenzelm@64085
   495
        }
wenzelm@64085
   496
    }
wenzelm@64054
   497
wenzelm@64085
   498
    val Session_No_Groups = new Regex("""^Session (\S+)$""")
wenzelm@64085
   499
    val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""")
wenzelm@64085
   500
    val Session_Finished1 =
wenzelm@64085
   501
      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
wenzelm@64085
   502
    val Session_Finished2 =
wenzelm@64085
   503
      new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
wenzelm@64085
   504
    val Session_Timing =
wenzelm@64085
   505
      new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
wenzelm@64086
   506
    val Session_Started = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""")
wenzelm@64085
   507
    val Session_Failed = new Regex("""^(\S+) FAILED""")
wenzelm@64085
   508
    val Session_Cancelled = new Regex("""^(\S+) CANCELLED""")
wenzelm@64120
   509
    val Heap = new Regex("""^Heap (\S+) \((\d+) bytes\)$""")
wenzelm@64085
   510
wenzelm@64085
   511
    var chapter = Map.empty[String, String]
wenzelm@64085
   512
    var groups = Map.empty[String, List[String]]
wenzelm@64085
   513
    var threads = Map.empty[String, Int]
wenzelm@64054
   514
    var timing = Map.empty[String, Timing]
wenzelm@64085
   515
    var ml_timing = Map.empty[String, Timing]
wenzelm@64086
   516
    var started = Set.empty[String]
wenzelm@64085
   517
    var failed = Set.empty[String]
wenzelm@64085
   518
    var cancelled = Set.empty[String]
wenzelm@64119
   519
    var ml_statistics = Map.empty[String, List[Properties.T]]
wenzelm@64120
   520
    var heap_sizes = Map.empty[String, Long]
wenzelm@64119
   521
wenzelm@64085
   522
    def all_sessions: Set[String] =
wenzelm@64120
   523
      chapter.keySet ++ groups.keySet ++ threads.keySet ++ timing.keySet ++ ml_timing.keySet ++
wenzelm@64120
   524
      failed ++ cancelled ++ started ++ ml_statistics.keySet ++ heap_sizes.keySet
wenzelm@64085
   525
wenzelm@64054
   526
wenzelm@64062
   527
    for (line <- log_file.lines) {
wenzelm@64054
   528
      line match {
wenzelm@64085
   529
        case Session_No_Groups(Chapter_Name(chapt, name)) =>
wenzelm@64085
   530
          chapter += (name -> chapt)
wenzelm@64085
   531
          groups += (name -> Nil)
wenzelm@64119
   532
wenzelm@64085
   533
        case Session_Groups(Chapter_Name(chapt, name), grps) =>
wenzelm@64085
   534
          chapter += (name -> chapt)
wenzelm@64085
   535
          groups += (name -> Word.explode(grps))
wenzelm@64119
   536
wenzelm@64086
   537
        case Session_Started(name) =>
wenzelm@64086
   538
          started += name
wenzelm@64119
   539
wenzelm@64054
   540
        case Session_Finished1(name,
wenzelm@64054
   541
            Value.Int(e1), Value.Int(e2), Value.Int(e3),
wenzelm@64054
   542
            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
wenzelm@64054
   543
          val elapsed = Time.hms(e1, e2, e3)
wenzelm@64054
   544
          val cpu = Time.hms(c1, c2, c3)
wenzelm@64085
   545
          timing += (name -> Timing(elapsed, cpu, Time.zero))
wenzelm@64119
   546
wenzelm@64054
   547
        case Session_Finished2(name,
wenzelm@64054
   548
            Value.Int(e1), Value.Int(e2), Value.Int(e3)) =>
wenzelm@64054
   549
          val elapsed = Time.hms(e1, e2, e3)
wenzelm@64085
   550
          timing += (name -> Timing(elapsed, Time.zero, Time.zero))
wenzelm@64119
   551
wenzelm@64054
   552
        case Session_Timing(name,
wenzelm@64054
   553
            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
wenzelm@64054
   554
          val elapsed = Time.seconds(e)
wenzelm@64054
   555
          val cpu = Time.seconds(c)
wenzelm@64054
   556
          val gc = Time.seconds(g)
wenzelm@64085
   557
          ml_timing += (name -> Timing(elapsed, cpu, gc))
wenzelm@64054
   558
          threads += (name -> t)
wenzelm@64119
   559
wenzelm@64120
   560
        case Heap(name, Value.Long(size)) =>
wenzelm@64120
   561
          heap_sizes += (name -> size)
wenzelm@64120
   562
wenzelm@65590
   563
        case _ if line.startsWith(ML_STATISTICS_MARKER) && YXML.detect(line) =>
wenzelm@64119
   564
          val (name, props) =
wenzelm@64119
   565
            Library.try_unprefix(ML_STATISTICS_MARKER, line).map(log_file.parse_props(_)) match {
wenzelm@64119
   566
              case Some((SESSION_NAME, session_name) :: props) => (session_name, props)
wenzelm@64119
   567
              case _ => log_file.err("malformed ML_statistics " + quote(line))
wenzelm@64119
   568
            }
wenzelm@64120
   569
          ml_statistics += (name -> (props :: ml_statistics.getOrElse(name, Nil)))
wenzelm@64119
   570
wenzelm@64054
   571
        case _ =>
wenzelm@64054
   572
      }
wenzelm@64054
   573
    }
wenzelm@64054
   574
wenzelm@64085
   575
    val sessions =
wenzelm@64085
   576
      Map(
wenzelm@64085
   577
        (for (name <- all_sessions.toList) yield {
wenzelm@64085
   578
          val status =
wenzelm@64085
   579
            if (failed(name)) Session_Status.FAILED
wenzelm@64085
   580
            else if (cancelled(name)) Session_Status.CANCELLED
wenzelm@64086
   581
            else if (timing.isDefinedAt(name) || ml_timing.isDefinedAt(name))
wenzelm@64086
   582
              Session_Status.FINISHED
wenzelm@64086
   583
            else if (started(name)) Session_Status.FAILED
wenzelm@64085
   584
            else Session_Status.EXISTING
wenzelm@64085
   585
          val entry =
wenzelm@64085
   586
            Session_Entry(
wenzelm@64085
   587
              chapter.getOrElse(name, ""),
wenzelm@64085
   588
              groups.getOrElse(name, Nil),
wenzelm@64085
   589
              threads.get(name),
wenzelm@64089
   590
              timing.getOrElse(name, Timing.zero),
wenzelm@64089
   591
              ml_timing.getOrElse(name, Timing.zero),
wenzelm@64119
   592
              ml_statistics.getOrElse(name, Nil).reverse,
wenzelm@64120
   593
              heap_sizes.get(name),
wenzelm@64085
   594
              status)
wenzelm@64085
   595
          (name -> entry)
wenzelm@64085
   596
        }):_*)
wenzelm@64085
   597
    Build_Info(sessions)
wenzelm@64054
   598
  }
wenzelm@64099
   599
wenzelm@64099
   600
wenzelm@64099
   601
wenzelm@65276
   602
  /** session info: produced by isabelle build as session log.gz file **/
wenzelm@64099
   603
wenzelm@64099
   604
  sealed case class Session_Info(
wenzelm@64099
   605
    session_timing: Properties.T,
wenzelm@64099
   606
    command_timings: List[Properties.T],
wenzelm@64099
   607
    ml_statistics: List[Properties.T],
wenzelm@64099
   608
    task_statistics: List[Properties.T])
wenzelm@64099
   609
wenzelm@64099
   610
  private def parse_session_info(
wenzelm@64099
   611
    log_file: Log_File,
wenzelm@64099
   612
    command_timings: Boolean,
wenzelm@64099
   613
    ml_statistics: Boolean,
wenzelm@64099
   614
    task_statistics: Boolean): Session_Info =
wenzelm@64099
   615
  {
wenzelm@65290
   616
    Session_Info(
wenzelm@65290
   617
      session_timing = log_file.find_props("\fTiming = ") getOrElse Nil,
wenzelm@65290
   618
      command_timings = if (command_timings) log_file.filter_props("\fcommand_timing = ") else Nil,
wenzelm@65290
   619
      ml_statistics = if (ml_statistics) log_file.filter_props(ML_STATISTICS_MARKER) else Nil,
wenzelm@65290
   620
      task_statistics = if (task_statistics) log_file.filter_props("\ftask_statistics = ") else Nil)
wenzelm@64099
   621
  }
wenzelm@65595
   622
wenzelm@65595
   623
wenzelm@65595
   624
wenzelm@65595
   625
  /** persistent store **/
wenzelm@65595
   626
wenzelm@65595
   627
  def store(options: Options): Store = new Store(options)
wenzelm@65595
   628
wenzelm@65595
   629
  class Store private[Build_Log](options: Options) extends Properties.Store
wenzelm@65595
   630
  {
wenzelm@65595
   631
    def open_database(
wenzelm@65595
   632
      user: String = options.string("build_log_database_user"),
wenzelm@65595
   633
      password: String = options.string("build_log_database_password"),
wenzelm@65595
   634
      database: String = options.string("build_log_database_name"),
wenzelm@65595
   635
      host: String = options.string("build_log_database_host"),
wenzelm@65595
   636
      port: Int = options.int("build_log_database_port"),
wenzelm@65595
   637
      ssh_host: String = options.string("build_log_ssh_host"),
wenzelm@65595
   638
      ssh_user: String = options.string("build_log_ssh_user"),
wenzelm@65595
   639
      ssh_port: Int = options.int("build_log_ssh_port")): PostgreSQL.Database =
wenzelm@65595
   640
    {
wenzelm@65595
   641
      PostgreSQL.open_database(
wenzelm@65595
   642
        user = user, password = password, database = database, host = host, port = port,
wenzelm@65595
   643
        ssh =
wenzelm@65595
   644
          if (ssh_host == "") None
wenzelm@65595
   645
          else Some(SSH.init_context(options).open_session(ssh_host, ssh_user, port)))
wenzelm@65595
   646
    }
wenzelm@65599
   647
wenzelm@65605
   648
    def filter_files(db: SQL.Database, table: SQL.Table, files: List[JFile]): List[JFile] =
wenzelm@65600
   649
    {
wenzelm@65614
   650
      db.transaction {
wenzelm@65614
   651
        db.create_table(table)
wenzelm@65614
   652
wenzelm@65614
   653
        val key = Meta_Info.log_name
wenzelm@65614
   654
        val known_files =
wenzelm@65619
   655
          using(db.select(table, List(key)))(stmt =>
wenzelm@65614
   656
            SQL.iterator(stmt.executeQuery)(rs => db.string(rs, key)).toSet)
wenzelm@65600
   657
wenzelm@65614
   658
        val unique_files =
wenzelm@65614
   659
          (Map.empty[String, JFile] /: files.iterator)({ case (m, file) =>
wenzelm@65614
   660
            val name = Log_File.plain_name(file.getName)
wenzelm@65614
   661
            if (known_files(name)) m else m + (name -> file)
wenzelm@65614
   662
          })
wenzelm@65600
   663
wenzelm@65614
   664
        unique_files.iterator.map(_._2).toList
wenzelm@65614
   665
      }
wenzelm@65600
   666
    }
wenzelm@65600
   667
wenzelm@65605
   668
    def write_meta_info(db: SQL.Database, files: List[JFile])
wenzelm@65599
   669
    {
wenzelm@65618
   670
      for (file_group <- filter_files(db, Meta_Info.table, files).grouped(1000)) {
wenzelm@65614
   671
        db.transaction {
wenzelm@65618
   672
          for (file <- file_group) {
wenzelm@65618
   673
            val log_file = Log_File(file)
wenzelm@65618
   674
            val meta_info = log_file.parse_meta_info()
wenzelm@65618
   675
wenzelm@65619
   676
            using(db.delete(Meta_Info.table, Meta_Info.log_name.sql_where_equal(log_file.name)))(
wenzelm@65619
   677
              _.execute)
wenzelm@65619
   678
            using(db.insert(Meta_Info.table))(stmt =>
wenzelm@65618
   679
            {
wenzelm@65618
   680
              db.set_string(stmt, 1, log_file.name)
wenzelm@65618
   681
              for ((c, i) <- Meta_Info.table.columns.tail.zipWithIndex) {
wenzelm@65618
   682
                if (c.T == SQL.Type.Date)
wenzelm@65618
   683
                  db.set_date(stmt, i + 2, meta_info.get_date(c))
wenzelm@65618
   684
                else
wenzelm@65618
   685
                  db.set_string(stmt, i + 2, meta_info.get(c).map(Prop.multiple_lines(_)))
wenzelm@65618
   686
              }
wenzelm@65618
   687
              stmt.execute()
wenzelm@65618
   688
            })
wenzelm@65618
   689
          }
wenzelm@65614
   690
        }
wenzelm@65605
   691
      }
wenzelm@65605
   692
    }
wenzelm@65605
   693
wenzelm@65621
   694
    def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] =
wenzelm@65621
   695
    {
wenzelm@65621
   696
      val cs = Meta_Info.table.columns.tail
wenzelm@65621
   697
      using(db.select(Meta_Info.table, cs, Meta_Info.log_name.sql_where_equal(log_name)))(stmt =>
wenzelm@65621
   698
      {
wenzelm@65621
   699
        val rs = stmt.executeQuery
wenzelm@65621
   700
        if (!rs.next) None
wenzelm@65621
   701
        else {
wenzelm@65621
   702
          val results =
wenzelm@65621
   703
            cs.map(c => c.name ->
wenzelm@65621
   704
              (if (c.T == SQL.Type.Date)
wenzelm@65621
   705
                db.get(rs, c, db.date _).map(Log_File.Date_Format(_))
wenzelm@65621
   706
               else
wenzelm@65621
   707
                db.get(rs, c, db.string _).map(s => Prop.cat_multiple(split_lines(s)))))
wenzelm@65621
   708
          val n = Prop.all_props.length
wenzelm@65621
   709
          val props = for ((x, Some(y)) <- results.take(n)) yield (x, y)
wenzelm@65621
   710
          val settings = for ((x, Some(y)) <- results.drop(n)) yield (x, y)
wenzelm@65621
   711
          Some(Meta_Info(props, settings))
wenzelm@65621
   712
        }
wenzelm@65621
   713
      })
wenzelm@65621
   714
    }
wenzelm@65621
   715
wenzelm@65605
   716
    def write_build_info(db: SQL.Database, files: List[JFile])
wenzelm@65605
   717
    {
wenzelm@65618
   718
      for (file_group <- filter_files(db, Build_Info.table, files).grouped(100)) {
wenzelm@65614
   719
        db.transaction {
wenzelm@65618
   720
          for (file <- file_group) {
wenzelm@65618
   721
            val log_file = Log_File(file)
wenzelm@65618
   722
            val build_info = log_file.parse_build_info()
wenzelm@65618
   723
wenzelm@65619
   724
            using(db.delete(Build_Info.table, Meta_Info.log_name.sql_where_equal(log_file.name)))(
wenzelm@65619
   725
              _.execute)
wenzelm@65619
   726
            using(db.insert(Build_Info.table))(stmt =>
wenzelm@65618
   727
            {
wenzelm@65618
   728
              for ((session_name, session) <- build_info.sessions.iterator) {
wenzelm@65618
   729
                db.set_string(stmt, 1, log_file.name)
wenzelm@65618
   730
                db.set_string(stmt, 2, session_name)
wenzelm@65618
   731
                db.set_string(stmt, 3, session.chapter)
wenzelm@65618
   732
                db.set_string(stmt, 4, cat_lines(session.groups))
wenzelm@65618
   733
                db.set_int(stmt, 5, session.threads)
wenzelm@65618
   734
                db.set_long(stmt, 6, session.timing.elapsed.proper_ms)
wenzelm@65618
   735
                db.set_long(stmt, 7, session.timing.cpu.proper_ms)
wenzelm@65618
   736
                db.set_long(stmt, 8, session.timing.gc.proper_ms)
wenzelm@65618
   737
                db.set_long(stmt, 9, session.ml_timing.elapsed.proper_ms)
wenzelm@65618
   738
                db.set_long(stmt, 10, session.ml_timing.cpu.proper_ms)
wenzelm@65618
   739
                db.set_long(stmt, 11, session.ml_timing.gc.proper_ms)
wenzelm@65618
   740
                db.set_bytes(stmt, 12, compress_properties(session.ml_statistics))
wenzelm@65618
   741
                db.set_long(stmt, 13, session.heap_size)
wenzelm@65618
   742
                db.set_string(stmt, 14, session.status.toString)
wenzelm@65618
   743
                stmt.execute()
wenzelm@65618
   744
              }
wenzelm@65618
   745
            })
wenzelm@65618
   746
          }
wenzelm@65614
   747
        }
wenzelm@65599
   748
      }
wenzelm@65599
   749
    }
wenzelm@65621
   750
wenzelm@65621
   751
    def read_build_info(
wenzelm@65621
   752
      db: SQL.Database, log_name: String, session_names: List[String] = Nil): Build_Info =
wenzelm@65621
   753
    {
wenzelm@65621
   754
      val where_log_name = Meta_Info.log_name.sql_where_equal(log_name)
wenzelm@65621
   755
      val where =
wenzelm@65621
   756
        if (session_names.isEmpty) where_log_name
wenzelm@65621
   757
        else
wenzelm@65621
   758
          where_log_name + " AND " +
wenzelm@65621
   759
          session_names.map(a => Build_Info.session_name.sql_name + " = " + SQL.quote_string(a)).
wenzelm@65621
   760
            mkString("(", " OR ", ")")
wenzelm@65621
   761
      val sessions =
wenzelm@65621
   762
        using(db.select(Build_Info.table, Build_Info.table.columns.tail, where))(stmt =>
wenzelm@65621
   763
        {
wenzelm@65621
   764
          SQL.iterator(stmt.executeQuery)(rs =>
wenzelm@65621
   765
          {
wenzelm@65621
   766
            val session_name = db.string(rs, Build_Info.session_name)
wenzelm@65621
   767
            val chapter = db.string(rs, Build_Info.chapter)
wenzelm@65621
   768
            val groups = split_lines(db.string(rs, Build_Info.groups))
wenzelm@65621
   769
            val threads = db.get(rs, Build_Info.threads, db.int _)
wenzelm@65621
   770
            val timing_elapsed = Time.ms(db.long(rs, Build_Info.timing_elapsed))
wenzelm@65621
   771
            val timing_cpu = Time.ms(db.long(rs, Build_Info.timing_cpu))
wenzelm@65621
   772
            val timing_gc = Time.ms(db.long(rs, Build_Info.timing_gc))
wenzelm@65621
   773
            val ml_timing_elapsed = Time.ms(db.long(rs, Build_Info.ml_timing_elapsed))
wenzelm@65621
   774
            val ml_timing_cpu = Time.ms(db.long(rs, Build_Info.ml_timing_cpu))
wenzelm@65621
   775
            val ml_timing_gc = Time.ms(db.long(rs, Build_Info.ml_timing_gc))
wenzelm@65621
   776
            val ml_statistics = uncompress_properties(db.bytes(rs, Build_Info.ml_statistics))
wenzelm@65621
   777
            val heap_size = db.get(rs, Build_Info.heap_size, db.long _)
wenzelm@65621
   778
            val status = Session_Status.withName(db.string(rs, Build_Info.status))
wenzelm@65621
   779
wenzelm@65621
   780
            session_name ->
wenzelm@65621
   781
              Session_Entry(chapter, groups, threads, Timing(timing_elapsed, timing_cpu, timing_gc),
wenzelm@65621
   782
                Timing(ml_timing_elapsed, ml_timing_cpu, ml_timing_gc), ml_statistics,
wenzelm@65621
   783
                heap_size, status)
wenzelm@65621
   784
          }).toMap
wenzelm@65621
   785
        })
wenzelm@65621
   786
      Build_Info(sessions)
wenzelm@65621
   787
    }
wenzelm@65595
   788
  }
wenzelm@64045
   789
}