src/Pure/Tools/build_log.scala
author wenzelm
Fri, 07 Oct 2016 11:45:30 +0200
changeset 64081 38bb09ed965b
parent 64080 2e5c0bd708af
child 64082 d57c7295f601
permissions -rw-r--r--
more uniform treatment of settings;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/build_log.scala
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     3
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     4
Build log parsing for historic versions, back to "build_history_base".
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     6
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     8
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
     9
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
    10
import java.time.ZonedDateTime
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
    11
import java.time.format.{DateTimeFormatter, DateTimeParseException}
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
    12
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
    13
import scala.collection.mutable
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
    14
import scala.util.matching.Regex
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
    15
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
    16
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
    17
object Build_Log
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
    18
{
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    19
  /** settings **/
64080
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    20
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    21
  object Settings
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    22
  {
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    23
    val build_settings = List("ISABELLE_BUILD_OPTIONS")
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    24
    val ml_settings = List("ML_PLATFORM", "ML_HOME", "ML_SYSTEM", "ML_OPTIONS")
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    25
    val all_settings = build_settings ::: ml_settings
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    26
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    27
    type Entry = (String, String)
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    28
    type T = List[Entry]
64080
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    29
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    30
    object Entry
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    31
    {
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    32
      def unapply(s: String): Option[Entry] =
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    33
        s.indexOf('=') match {
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    34
          case -1 => None
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    35
          case i =>
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    36
            val a = s.substring(0, i)
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    37
            val b = Library.perhaps_unquote(s.substring(i + 1))
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    38
            Some((a, b))
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    39
        }
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    40
      def apply(a: String, b: String): String = a + "=" + quote(b)
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    41
      def getenv(a: String): String = apply(a, Isabelle_System.getenv(a))
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    42
    }
64080
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    43
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    44
    def show(): String =
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    45
      cat_lines(
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    46
        build_settings.map(Entry.getenv(_)) ::: List("") ::: ml_settings.map(Entry.getenv(_)))
64080
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    47
  }
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    48
2e5c0bd708af clarified modules;
wenzelm
parents: 64079
diff changeset
    49
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    50
  /** log file **/
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
    51
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    52
  object Log_File
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    53
  {
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    54
    def apply(name: String, lines: List[String]): Log_File =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    55
      new Log_File(name, lines)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    56
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    57
    def apply(name: String, text: String): Log_File =
64063
2c5039363ea3 tuned signature;
wenzelm
parents: 64062
diff changeset
    58
      Log_File(name, Library.trim_split_lines(text))
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    59
  }
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    60
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    61
  class Log_File private(val name: String, val lines: List[String])
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
    62
  {
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    63
    log_file =>
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    64
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    65
    override def toString: String = name
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    66
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    67
    def text: String = cat_lines(lines)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    68
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    69
    def err(msg: String): Nothing =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    70
      error("Error in log file " + quote(name) + ": " + msg)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    71
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    72
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    73
    /* inlined content */
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    74
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    75
    def find[A](f: String => Option[A]): Option[A] =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    76
      lines.iterator.map(f).find(_.isDefined).map(_.get)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    77
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    78
    def find_match(regex: Regex): Option[String] =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    79
      lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1).
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    80
        map(res => res.get.head)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    81
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    82
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    83
    /* settings */
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    84
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    85
    def get_setting(a: String): Settings.Entry =
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    86
      Settings.Entry.unapply(
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    87
        lines.find(_.startsWith(a + "=")) getOrElse err("missing " + a)).get
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
    88
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
    89
    def get_settings(as: List[String]): Settings.T = as.map(get_setting(_))
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    90
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    91
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    92
    /* properties (YXML) */
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    93
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    94
    val xml_cache = new XML.Cache()
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    95
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    96
    def parse_props(text: String): Properties.T =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    97
      xml_cache.props(XML.Decode.properties(YXML.parse_body(text)))
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    98
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
    99
    def filter_props(prefix: String): List[Properties.T] =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   100
      for (line <- lines; s <- Library.try_unprefix(prefix, line)) yield parse_props(s)
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   101
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   102
    def find_line(prefix: String): Option[String] =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   103
      find(Library.try_unprefix(prefix, _))
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   104
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   105
    def find_props(prefix: String): Option[Properties.T] =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   106
      find_line(prefix).map(parse_props(_))
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   107
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   108
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   109
    /* parse various formats */
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   110
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   111
    def parse_session_info(session_name: String, full: Boolean): Session_Info =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   112
      Build_Log.parse_session_info(log_file, session_name, full)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   113
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   114
    def parse_header: Header = Build_Log.parse_header(log_file)
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   115
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   116
    def parse_info: Info = Build_Log.parse_info(log_file)
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   117
  }
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   118
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   119
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   120
  /* session log: produced by "isabelle build" */
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   121
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   122
  sealed case class Session_Info(
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   123
    session_name: String,
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   124
    session_timing: Properties.T,
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   125
    command_timings: List[Properties.T],
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   126
    ml_statistics: List[Properties.T],
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   127
    task_statistics: List[Properties.T])
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   128
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   129
  private def parse_session_info(log_file: Log_File, name0: String, full: Boolean): Session_Info =
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   130
  {
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   131
    val xml_cache = new XML.Cache()
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   132
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   133
    val session_name =
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   134
      log_file.find_line("\fSession.name = ") match {
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   135
        case None => name0
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   136
        case Some(name) if name0 == "" || name0 == name => name
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   137
        case Some(name) => log_file.err("log from different session " + quote(name))
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   138
      }
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   139
    val session_timing = log_file.find_props("\fTiming = ") getOrElse Nil
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   140
    val command_timings = log_file.filter_props("\fcommand_timing = ")
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   141
    val ml_statistics = if (full) log_file.filter_props("\fML_statistics = ") else Nil
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   142
    val task_statistics = if (full) log_file.filter_props("\ftask_statistics = ") else Nil
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   143
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   144
    Session_Info(session_name, session_timing, command_timings, ml_statistics, task_statistics)
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   145
  }
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   146
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   147
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   148
  /* header and meta data */
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   149
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   150
  object Header_Kind extends Enumeration
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   151
  {
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   152
    val ISATEST = Value("isatest")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   153
    val AFP_TEST = Value("afp-test")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   154
    val JENKINS = Value("jenkins")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   155
  }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   156
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   157
  sealed case class Header(
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   158
    kind: Header_Kind.Value, props: Properties.T, settings: List[(String, String)])
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   159
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   160
  object Field
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   161
  {
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   162
    val build_host = "build_host"
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   163
    val build_start = "build_start"
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   164
    val build_end = "build_end"
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   165
    val isabelle_version = "isabelle_version"
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   166
    val afp_version = "afp_version"
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   167
  }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   168
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   169
  object AFP
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   170
  {
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   171
    val Date_Format =
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   172
      Date.Format.make_patterns(List("EEE MMM d HH:mm:ss VV yyyy", "EEE MMM d HH:mm:ss O yyyy"),
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   173
        // workaround for jdk-8u102
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   174
        s => Word.implode(Word.explode(s).map({ case "CEST" => "GMT+2" case a => a })))
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   175
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   176
    val Test_Start = new Regex("""^Start test for .+ at (.+), (\w+)$""")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   177
    val Test_End = new Regex("""^End test on (.+), \w+, elapsed time:.*$""")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   178
    val Isabelle_Version = new Regex("""^Isabelle version: .* -- hg id (\w+)$""")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   179
    val AFP_Version = new Regex("""^AFP version: .* -- hg id (\w+)$""")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   180
  }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   181
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   182
  private def parse_header(log_file: Log_File): Header =
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   183
  {
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   184
    log_file.lines match {
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   185
      case AFP.Test_Start(start, hostname) :: _ =>
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   186
        (start, log_file.lines.last) match {
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   187
          case (AFP.Date_Format(start_date), AFP.Test_End(AFP.Date_Format(end_date))) =>
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   188
            val isabelle_version =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   189
              log_file.find_match(AFP.Isabelle_Version) getOrElse
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   190
                log_file.err("missing Isabelle version")
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   191
            val afp_version =
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   192
              log_file.find_match(AFP.AFP_Version) getOrElse
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   193
                log_file.err("missing AFP version")
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   194
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   195
            Header(Header_Kind.AFP_TEST,
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   196
              List(
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   197
                Field.build_host -> hostname,
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   198
                Field.build_start -> start_date.toString,
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   199
                Field.build_end -> end_date.toString,
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   200
                Field.isabelle_version -> isabelle_version,
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   201
                Field.afp_version -> afp_version),
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   202
              log_file.get_settings(Settings.all_settings))
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   203
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   204
          case _ => log_file.err("cannot detect start/end date in afp-test log")
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   205
        }
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   206
      case _ => log_file.err("cannot detect log header format")
64061
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   207
    }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   208
  }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   209
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   210
  object Session_Status extends Enumeration
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   211
  {
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   212
    val UNKNOWN = Value("unknown")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   213
    val FINISHED = Value("finished")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   214
    val FAILED = Value("failed")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   215
    val CANCELLED = Value("cancelled")
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   216
  }
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   217
1bbea2b55d22 some support for header and data fields, notably from afp-test;
wenzelm
parents: 64054
diff changeset
   218
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   219
  /* main log: produced by isatest, afp-test, jenkins etc. */
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   220
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   221
  sealed case class Info(
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   222
    settings: List[(String, String)],
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   223
    finished: Map[String, Timing],
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   224
    timing: Map[String, Timing],
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   225
    threads: Map[String, Int])
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   226
  {
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   227
    val sessions: Set[String] = finished.keySet ++ timing.keySet
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   228
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   229
    override def toString: String =
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   230
      sessions.toList.sorted.mkString("Build_Log.Info(", ", ", ")")
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   231
  }
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   232
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   233
  private val Session_Finished1 =
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   234
    new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   235
  private val Session_Finished2 =
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   236
    new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   237
  private val Session_Timing =
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   238
    new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   239
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   240
  private def parse_info(log_file: Log_File): Info =
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   241
  {
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   242
    val settings = new mutable.ListBuffer[(String, String)]
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   243
    var finished = Map.empty[String, Timing]
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   244
    var timing = Map.empty[String, Timing]
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   245
    var threads = Map.empty[String, Int]
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   246
64062
a7352cbde7d7 misc tuning and clarification;
wenzelm
parents: 64061
diff changeset
   247
    for (line <- log_file.lines) {
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   248
      line match {
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   249
        case Session_Finished1(name,
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   250
            Value.Int(e1), Value.Int(e2), Value.Int(e3),
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   251
            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   252
          val elapsed = Time.hms(e1, e2, e3)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   253
          val cpu = Time.hms(c1, c2, c3)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   254
          finished += (name -> Timing(elapsed, cpu, Time.zero))
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   255
        case Session_Finished2(name,
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   256
            Value.Int(e1), Value.Int(e2), Value.Int(e3)) =>
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   257
          val elapsed = Time.hms(e1, e2, e3)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   258
          finished += (name -> Timing(elapsed, Time.zero, Time.zero))
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   259
        case Session_Timing(name,
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   260
            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   261
          val elapsed = Time.seconds(e)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   262
          val cpu = Time.seconds(c)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   263
          val gc = Time.seconds(g)
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   264
          timing += (name -> Timing(elapsed, cpu, gc))
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   265
          threads += (name -> t)
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   266
        case Settings.Entry(a, b) if Settings.all_settings.contains(a) =>
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   267
          settings += (a -> b)
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   268
        case _ =>
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   269
      }
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   270
    }
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   271
64081
38bb09ed965b more uniform treatment of settings;
wenzelm
parents: 64080
diff changeset
   272
    Info(settings.toList, finished, timing, threads)
64054
1fc9ab31720d clarified modules;
wenzelm
parents: 64053
diff changeset
   273
  }
64045
c6160d0b0337 clarified modules;
wenzelm
parents:
diff changeset
   274
}