| author | nipkow | 
| Thu, 04 Oct 2018 11:18:39 +0200 | |
| changeset 69118 | 12dce58bcd3f | 
| parent 68169 | 395432e7516e | 
| child 69299 | 2fd070377c99 | 
| permissions | -rw-r--r-- | 
| 64160 | 1 | /* Title: Pure/Admin/build_log.scala | 
| 64045 | 2 | Author: Makarius | 
| 3 | ||
| 65608 | 4 | Management of build log files and database storage. | 
| 64045 | 5 | */ | 
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 64100 | 10 | import java.io.{File => JFile}
 | 
| 11 | import java.time.ZoneId | |
| 64110 | 12 | import java.time.format.{DateTimeFormatter, DateTimeParseException}
 | 
| 64096 | 13 | import java.util.Locale | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 14 | |
| 65600 | 15 | import scala.collection.immutable.SortedMap | 
| 64054 | 16 | import scala.collection.mutable | 
| 17 | import scala.util.matching.Regex | |
| 18 | ||
| 19 | ||
| 64045 | 20 | object Build_Log | 
| 21 | {
 | |
| 64298 | 22 | /** content **/ | 
| 64101 | 23 | |
| 64298 | 24 | /* properties */ | 
| 64150 | 25 | |
| 64298 | 26 | object Prop | 
| 27 |   {
 | |
| 65624 | 28 |     val build_tags = SQL.Column.string("build_tags")  // lines
 | 
| 29 |     val build_args = SQL.Column.string("build_args")  // lines
 | |
| 65591 | 30 |     val build_group_id = SQL.Column.string("build_group_id")
 | 
| 31 |     val build_id = SQL.Column.string("build_id")
 | |
| 32 |     val build_engine = SQL.Column.string("build_engine")
 | |
| 33 |     val build_host = SQL.Column.string("build_host")
 | |
| 34 |     val build_start = SQL.Column.date("build_start")
 | |
| 35 |     val build_end = SQL.Column.date("build_end")
 | |
| 36 |     val isabelle_version = SQL.Column.string("isabelle_version")
 | |
| 37 |     val afp_version = SQL.Column.string("afp_version")
 | |
| 38 | ||
| 65611 | 39 | val all_props: List[SQL.Column] = | 
| 65591 | 40 | List(build_tags, build_args, build_group_id, build_id, build_engine, | 
| 41 | build_host, build_start, build_end, isabelle_version, afp_version) | |
| 64298 | 42 | } | 
| 64150 | 43 | |
| 44 | ||
| 64298 | 45 | /* settings */ | 
| 64080 | 46 | |
| 64081 | 47 | object Settings | 
| 48 |   {
 | |
| 65611 | 49 |     val ISABELLE_BUILD_OPTIONS = SQL.Column.string("ISABELLE_BUILD_OPTIONS")
 | 
| 50 |     val ML_PLATFORM = SQL.Column.string("ML_PLATFORM")
 | |
| 51 |     val ML_HOME = SQL.Column.string("ML_HOME")
 | |
| 52 |     val ML_SYSTEM = SQL.Column.string("ML_SYSTEM")
 | |
| 53 |     val ML_OPTIONS = SQL.Column.string("ML_OPTIONS")
 | |
| 54 | ||
| 55 | val ml_settings = List(ML_PLATFORM, ML_HOME, ML_SYSTEM, ML_OPTIONS) | |
| 56 | val all_settings = ISABELLE_BUILD_OPTIONS :: ml_settings | |
| 64081 | 57 | |
| 58 | type Entry = (String, String) | |
| 59 | type T = List[Entry] | |
| 64080 | 60 | |
| 64081 | 61 | object Entry | 
| 62 |     {
 | |
| 63 | def unapply(s: String): Option[Entry] = | |
| 64 |         s.indexOf('=') match {
 | |
| 65 | case -1 => None | |
| 66 | case i => | |
| 67 | val a = s.substring(0, i) | |
| 68 | val b = Library.perhaps_unquote(s.substring(i + 1)) | |
| 69 | Some((a, b)) | |
| 70 | } | |
| 71 | def apply(a: String, b: String): String = a + "=" + quote(b) | |
| 72 | def getenv(a: String): String = apply(a, Isabelle_System.getenv(a)) | |
| 73 | } | |
| 64080 | 74 | |
| 64081 | 75 | def show(): String = | 
| 76 | cat_lines( | |
| 65611 | 77 | List(Entry.getenv(ISABELLE_BUILD_OPTIONS.name), "") ::: | 
| 78 | ml_settings.map(c => Entry.getenv(c.name))) | |
| 64080 | 79 | } | 
| 80 | ||
| 81 | ||
| 64298 | 82 | /* file names */ | 
| 83 | ||
| 84 | def log_date(date: Date): String = | |
| 85 | String.format(Locale.ROOT, "%s.%05d", | |
| 86 |       DateTimeFormatter.ofPattern("yyyy-MM-dd").format(date.rep),
 | |
| 87 | new java.lang.Long((date.time - date.midnight.time).ms / 1000)) | |
| 88 | ||
| 89 | def log_subdir(date: Date): Path = | |
| 90 |     Path.explode("log") + Path.explode(date.rep.getYear.toString)
 | |
| 91 | ||
| 92 | def log_filename(engine: String, date: Date, more: List[String] = Nil): Path = | |
| 93 |     Path.explode((engine :: log_date(date) :: more).mkString("", "_", ".log"))
 | |
| 94 | ||
| 95 | ||
| 64100 | 96 | |
| 64062 | 97 | /** log file **/ | 
| 64045 | 98 | |
| 64155 | 99 | def print_date(date: Date): String = Log_File.Date_Format(date) | 
| 100 | ||
| 64062 | 101 | object Log_File | 
| 102 |   {
 | |
| 65607 | 103 | /* log file */ | 
| 104 | ||
| 65609 | 105 | def plain_name(name: String): String = | 
| 106 |     {
 | |
| 107 |       List(".log", ".log.gz", ".log.xz", ".gz", ".xz").find(name.endsWith(_)) match {
 | |
| 108 | case Some(s) => Library.try_unsuffix(s, name).get | |
| 109 | case None => name | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 64062 | 113 | def apply(name: String, lines: List[String]): Log_File = | 
| 65609 | 114 | new Log_File(plain_name(name), lines) | 
| 64062 | 115 | |
| 116 | def apply(name: String, text: String): Log_File = | |
| 64063 | 117 | Log_File(name, Library.trim_split_lines(text)) | 
| 64090 | 118 | |
| 119 | def apply(file: JFile): Log_File = | |
| 120 |     {
 | |
| 121 | val name = file.getName | |
| 65609 | 122 | val text = | 
| 123 |         if (name.endsWith(".gz")) File.read_gzip(file)
 | |
| 124 |         else if (name.endsWith(".xz")) File.read_xz(file)
 | |
| 125 | else File.read(file) | |
| 126 | apply(name, text) | |
| 64090 | 127 | } | 
| 128 | ||
| 129 | def apply(path: Path): Log_File = apply(path.file) | |
| 64101 | 130 | |
| 64110 | 131 | |
| 65607 | 132 | /* log file collections */ | 
| 133 | ||
| 134 | def is_log(file: JFile, | |
| 135 | prefixes: List[String] = | |
| 66995 
9cb263dbb2f7
plain identify job for Isabelle + AFP, independent of any Isabelle technology;
 wenzelm parents: 
66944diff
changeset | 136 | List(Build_History.log_prefix, Identify.log_prefix, Identify.log_prefix2, | 
| 
9cb263dbb2f7
plain identify job for Isabelle + AFP, independent of any Isabelle technology;
 wenzelm parents: 
66944diff
changeset | 137 | Isatest.log_prefix, AFP_Test.log_prefix, Jenkins.log_prefix), | 
| 65609 | 138 |       suffixes: List[String] = List(".log", ".log.gz", ".log.xz")): Boolean =
 | 
| 65607 | 139 |     {
 | 
| 140 | val name = file.getName | |
| 65639 | 141 | |
| 65607 | 142 | prefixes.exists(name.startsWith(_)) && | 
| 65639 | 143 | suffixes.exists(name.endsWith(_)) && | 
| 144 | name != "isatest.log" && | |
| 145 | name != "afp-test.log" && | |
| 146 | name != "main.log" | |
| 65607 | 147 | } | 
| 148 | ||
| 149 | def find_files(dirs: Iterable[Path]): List[JFile] = | |
| 150 | dirs.iterator.flatMap(dir => File.find_files(dir.file, is_log(_))).toList | |
| 151 | ||
| 152 | ||
| 64110 | 153 | /* date format */ | 
| 154 | ||
| 64101 | 155 | val Date_Format = | 
| 156 |     {
 | |
| 157 | val fmts = | |
| 158 | Date.Formatter.variants( | |
| 64116 | 159 |           List("EEE MMM d HH:mm:ss O yyyy", "EEE MMM d HH:mm:ss VV yyyy"),
 | 
| 64104 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 160 | List(Locale.ENGLISH, Locale.GERMAN)) ::: | 
| 64110 | 161 | List( | 
| 162 | DateTimeFormatter.RFC_1123_DATE_TIME, | |
| 163 |           Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(ZoneId.of("Europe/Berlin")))
 | |
| 64101 | 164 | |
| 64104 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 165 | def tune_timezone(s: String): String = | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 166 |         s match {
 | 
| 64101 | 167 | case "CET" | "MET" => "GMT+1" | 
| 168 | case "CEST" | "MEST" => "GMT+2" | |
| 64104 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 169 | case "EST" => "Europe/Berlin" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 170 | case _ => s | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 171 | } | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 172 | def tune_weekday(s: String): String = | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 173 |         s match {
 | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 174 | case "Die" => "Di" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 175 | case "Mit" => "Mi" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 176 | case "Don" => "Do" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 177 | case "Fre" => "Fr" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 178 | case "Sam" => "Sa" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 179 | case "Son" => "So" | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 180 | case _ => s | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 181 | } | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 182 | |
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 183 | def tune(s: String): String = | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 184 | Word.implode( | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 185 |           Word.explode(s) match {
 | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 186 | case a :: "M\uFFFDr" :: bs => tune_weekday(a) :: "Mär" :: bs.map(tune_timezone(_)) | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 187 | case a :: bs => tune_weekday(a) :: bs.map(tune_timezone(_)) | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 188 | case Nil => Nil | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 189 | } | 
| 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 190 | ) | 
| 64101 | 191 | |
| 192 | Date.Format.make(fmts, tune) | |
| 193 | } | |
| 64117 | 194 | |
| 195 | ||
| 196 | /* inlined content */ | |
| 197 | ||
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 198 | def print_props(marker: String, props: Properties.T): String = | 
| 65624 | 199 | marker + YXML.string_of_body(XML.Encode.properties(Properties.encode_lines(props))) | 
| 64102 | 200 | } | 
| 201 | ||
| 202 | class Log_File private(val name: String, val lines: List[String]) | |
| 203 |   {
 | |
| 204 | log_file => | |
| 205 | ||
| 206 | override def toString: String = name | |
| 207 | ||
| 208 | def text: String = cat_lines(lines) | |
| 209 | ||
| 210 | def err(msg: String): Nothing = | |
| 211 |       error("Error in log file " + quote(name) + ": " + msg)
 | |
| 212 | ||
| 213 | ||
| 214 | /* date format */ | |
| 64101 | 215 | |
| 216 | object Strict_Date | |
| 217 |     {
 | |
| 218 | def unapply(s: String): Some[Date] = | |
| 64102 | 219 |         try { Some(Log_File.Date_Format.parse(s)) }
 | 
| 64101 | 220 |         catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) }
 | 
| 221 | } | |
| 222 | ||
| 223 | ||
| 64062 | 224 | /* inlined content */ | 
| 225 | ||
| 226 | def find[A](f: String => Option[A]): Option[A] = | |
| 227 | lines.iterator.map(f).find(_.isDefined).map(_.get) | |
| 228 | ||
| 64196 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 229 | def find_line(marker: String): Option[String] = | 
| 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 230 | find(Library.try_unprefix(marker, _)) | 
| 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 231 | |
| 65684 | 232 | def find_match(regexes: List[Regex]): Option[String] = | 
| 233 |       regexes match {
 | |
| 234 | case Nil => None | |
| 235 | case regex :: rest => | |
| 236 | lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1). | |
| 237 | map(res => res.get.head) orElse find_match(rest) | |
| 238 | } | |
| 64062 | 239 | |
| 240 | ||
| 241 | /* settings */ | |
| 242 | ||
| 64091 | 243 | def get_setting(a: String): Option[Settings.Entry] = | 
| 244 |       lines.find(_.startsWith(a + "=")) match {
 | |
| 245 | case Some(line) => Settings.Entry.unapply(line) | |
| 246 | case None => None | |
| 247 | } | |
| 64045 | 248 | |
| 65611 | 249 | def get_all_settings: Settings.T = | 
| 250 |       for { c <- Settings.all_settings; entry <- get_setting(c.name) }
 | |
| 251 | yield entry | |
| 64062 | 252 | |
| 253 | ||
| 254 | /* properties (YXML) */ | |
| 255 | ||
| 68169 | 256 | val xml_cache = XML.make_cache() | 
| 64062 | 257 | |
| 258 | def parse_props(text: String): Properties.T = | |
| 66046 | 259 |       try {
 | 
| 260 | xml_cache.props(Properties.decode_lines(XML.Decode.properties(YXML.parse_body(text)))) | |
| 261 | } | |
| 262 |       catch { case _: XML.Error => log_file.err("malformed properties") }
 | |
| 64062 | 263 | |
| 65934 | 264 | def filter_lines(marker: String): List[String] = | 
| 265 | for (line <- lines; s <- Library.try_unprefix(marker, line)) yield s | |
| 266 | ||
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 267 | def filter_props(marker: String): List[Properties.T] = | 
| 65934 | 268 | for (s <- filter_lines(marker) if YXML.detect(s)) yield parse_props(s) | 
| 64062 | 269 | |
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 270 | def find_props(marker: String): Option[Properties.T] = | 
| 64196 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 271 |       find_line(marker) match {
 | 
| 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 272 | case Some(text) if YXML.detect(text) => Some(parse_props(text)) | 
| 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 273 | case _ => None | 
| 
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
 wenzelm parents: 
64193diff
changeset | 274 | } | 
| 64062 | 275 | |
| 276 | ||
| 277 | /* parse various formats */ | |
| 278 | ||
| 64105 | 279 | def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file) | 
| 280 | ||
| 65646 | 281 | def parse_build_info(ml_statistics: Boolean = false): Build_Info = | 
| 282 | Build_Log.parse_build_info(log_file, ml_statistics) | |
| 64105 | 283 | |
| 64082 | 284 | def parse_session_info( | 
| 285 | command_timings: Boolean = false, | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 286 | theory_timings: Boolean = false, | 
| 64082 | 287 | ml_statistics: Boolean = false, | 
| 288 | task_statistics: Boolean = false): Session_Info = | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 289 | Build_Log.parse_session_info( | 
| 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 290 | log_file, command_timings, theory_timings, ml_statistics, task_statistics) | 
| 64045 | 291 | } | 
| 292 | ||
| 293 | ||
| 64098 | 294 | |
| 65276 | 295 | /** digested meta info: produced by Admin/build_history in log.xz file **/ | 
| 64045 | 296 | |
| 64108 | 297 | object Meta_Info | 
| 64099 | 298 |   {
 | 
| 64108 | 299 | val empty: Meta_Info = Meta_Info(Nil, Nil) | 
| 64099 | 300 | } | 
| 64098 | 301 | |
| 65611 | 302 | sealed case class Meta_Info(props: Properties.T, settings: Settings.T) | 
| 64103 | 303 |   {
 | 
| 304 | def is_empty: Boolean = props.isEmpty && settings.isEmpty | |
| 65599 | 305 | |
| 65611 | 306 | def get(c: SQL.Column): Option[String] = | 
| 307 | Properties.get(props, c.name) orElse | |
| 308 | Properties.get(settings, c.name) | |
| 309 | ||
| 310 | def get_date(c: SQL.Column): Option[Date] = | |
| 311 | get(c).map(Log_File.Date_Format.parse(_)) | |
| 64103 | 312 | } | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 313 | |
| 65625 | 314 | object Identify | 
| 315 |   {
 | |
| 316 | val log_prefix = "isabelle_identify_" | |
| 66995 
9cb263dbb2f7
plain identify job for Isabelle + AFP, independent of any Isabelle technology;
 wenzelm parents: 
66944diff
changeset | 317 | val log_prefix2 = "plain_identify_" | 
| 65674 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 318 | |
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 319 | def engine(log_file: Log_File): String = | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 320 | if (log_file.name.startsWith(Jenkins.log_prefix)) "jenkins_identify" | 
| 66995 
9cb263dbb2f7
plain identify job for Isabelle + AFP, independent of any Isabelle technology;
 wenzelm parents: 
66944diff
changeset | 321 | else if (log_file.name.startsWith(log_prefix2)) "plain_identify" | 
| 65674 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 322 | else "identify" | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 323 | |
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 324 | def content(date: Date, isabelle_version: Option[String], afp_version: Option[String]): String = | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 325 | terminate_lines( | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 326 |         List("isabelle_identify: " + Build_Log.print_date(date), "") :::
 | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 327 |         isabelle_version.map("Isabelle version: " + _).toList :::
 | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 328 |         afp_version.map("AFP version: " + _).toList)
 | 
| 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 329 | |
| 65625 | 330 |     val Start = new Regex("""^isabelle_identify: (.+)$""")
 | 
| 331 |     val No_End = new Regex("""$.""")
 | |
| 65684 | 332 |     val Isabelle_Version = List(new Regex("""^Isabelle version: (\S+)$"""))
 | 
| 333 |     val AFP_Version = List(new Regex("""^AFP version: (\S+)$"""))
 | |
| 65625 | 334 | } | 
| 335 | ||
| 64095 | 336 | object Isatest | 
| 337 |   {
 | |
| 65588 | 338 | val log_prefix = "isatest-makeall-" | 
| 64108 | 339 | val engine = "isatest" | 
| 64109 | 340 |     val Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""")
 | 
| 341 |     val End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""")
 | |
| 65684 | 342 |     val Isabelle_Version = List(new Regex("""^Isabelle version: (\S+)$"""))
 | 
| 64095 | 343 | } | 
| 344 | ||
| 64109 | 345 | object AFP_Test | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 346 |   {
 | 
| 65588 | 347 | val log_prefix = "afp-test-devel-" | 
| 64108 | 348 | val engine = "afp-test" | 
| 64109 | 349 |     val Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""")
 | 
| 350 |     val Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""")
 | |
| 351 |     val End = new Regex("""^End test on (.+), .+, elapsed time:.*$""")
 | |
| 65684 | 352 |     val Isabelle_Version = List(new Regex("""^Isabelle version: .* -- hg id (\S+)$"""))
 | 
| 353 |     val AFP_Version = List(new Regex("""^AFP version: .* -- hg id (\S+)$"""))
 | |
| 64104 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 354 |     val Bad_Init = new Regex("""^cp:.*: Disc quota exceeded$""")
 | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 355 | } | 
| 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 356 | |
| 64110 | 357 | object Jenkins | 
| 358 |   {
 | |
| 65664 | 359 | val log_prefix = "jenkins_" | 
| 64110 | 360 | val engine = "jenkins" | 
| 65663 | 361 |     val Host = new Regex("""^Building remotely on (\S+) \((\S+)\).*$""")
 | 
| 65665 | 362 |     val Start = new Regex("""^(?:Started by an SCM change|Started from command line by admin|).*$""")
 | 
| 64110 | 363 |     val Start_Date = new Regex("""^Build started at (.+)$""")
 | 
| 364 |     val No_End = new Regex("""$.""")
 | |
| 65674 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 365 | val Isabelle_Version = | 
| 65684 | 366 |       List(new Regex("""^(?:Build for Isabelle id|Isabelle id) (\w+).*$"""),
 | 
| 65685 | 367 |         new Regex("""^ISABELLE_CI_REPO_ID="(\w+)".*$"""),
 | 
| 368 |         new Regex("""^(\w{12}) tip.*$"""))
 | |
| 65674 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 369 | val AFP_Version = | 
| 65684 | 370 |       List(new Regex("""^(?:Build for AFP id|AFP id) (\w+).*$"""),
 | 
| 371 |         new Regex("""^ISABELLE_CI_AFP_ID="(\w+)".*$"""))
 | |
| 64110 | 372 | val CONFIGURATION = "=== CONFIGURATION ===" | 
| 373 | val BUILD = "=== BUILD ===" | |
| 374 | } | |
| 375 | ||
| 64105 | 376 | private def parse_meta_info(log_file: Log_File): Meta_Info = | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 377 |   {
 | 
| 64108 | 378 | def parse(engine: String, host: String, start: Date, | 
| 65684 | 379 | End: Regex, Isabelle_Version: List[Regex], AFP_Version: List[Regex]): Meta_Info = | 
| 64091 | 380 |     {
 | 
| 64296 
544481988e65
explicit identification of builds and correlated build groups;
 wenzelm parents: 
64196diff
changeset | 381 | val build_id = | 
| 
544481988e65
explicit identification of builds and correlated build groups;
 wenzelm parents: 
64196diff
changeset | 382 |       {
 | 
| 65714 | 383 | val prefix = proper_string(host) orElse proper_string(engine) getOrElse "build" | 
| 384 | prefix + ":" + start.time.ms | |
| 64296 
544481988e65
explicit identification of builds and correlated build groups;
 wenzelm parents: 
64196diff
changeset | 385 | } | 
| 65591 | 386 | val build_engine = if (engine == "") Nil else List(Prop.build_engine.name -> engine) | 
| 387 | val build_host = if (host == "") Nil else List(Prop.build_host.name -> host) | |
| 64108 | 388 | |
| 65599 | 389 | val start_date = List(Prop.build_start.name -> print_date(start)) | 
| 64091 | 390 | val end_date = | 
| 391 |         log_file.lines.last match {
 | |
| 64109 | 392 | case End(log_file.Strict_Date(end_date)) => | 
| 65599 | 393 | List(Prop.build_end.name -> print_date(end_date)) | 
| 64091 | 394 | case _ => Nil | 
| 395 | } | |
| 396 | ||
| 397 | val isabelle_version = | |
| 65591 | 398 | log_file.find_match(Isabelle_Version).map(Prop.isabelle_version.name -> _) | 
| 64091 | 399 | val afp_version = | 
| 65591 | 400 | log_file.find_match(AFP_Version).map(Prop.afp_version.name -> _) | 
| 64062 | 401 | |
| 65591 | 402 | Meta_Info((Prop.build_id.name -> build_id) :: build_engine ::: build_host ::: | 
| 64108 | 403 | start_date ::: end_date ::: isabelle_version.toList ::: afp_version.toList, | 
| 65611 | 404 | log_file.get_all_settings) | 
| 64091 | 405 | } | 
| 406 | ||
| 407 |     log_file.lines match {
 | |
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 408 | case line :: _ if line.startsWith(Build_History.META_INFO_MARKER) => | 
| 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 409 | Meta_Info(log_file.find_props(Build_History.META_INFO_MARKER).get, | 
| 65611 | 410 | log_file.get_all_settings) | 
| 64117 | 411 | |
| 65625 | 412 | case Identify.Start(log_file.Strict_Date(start)) :: _ => | 
| 65674 
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
 wenzelm parents: 
65670diff
changeset | 413 | parse(Identify.engine(log_file), "", start, Identify.No_End, | 
| 65625 | 414 | Identify.Isabelle_Version, Identify.AFP_Version) | 
| 415 | ||
| 64109 | 416 | case Isatest.Start(log_file.Strict_Date(start), host) :: _ => | 
| 417 | parse(Isatest.engine, host, start, Isatest.End, | |
| 65684 | 418 | Isatest.Isabelle_Version, Nil) | 
| 64099 | 419 | |
| 64109 | 420 | case AFP_Test.Start(log_file.Strict_Date(start), host) :: _ => | 
| 421 | parse(AFP_Test.engine, host, start, AFP_Test.End, | |
| 422 | AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) | |
| 64099 | 423 | |
| 64109 | 424 | case AFP_Test.Start_Old(log_file.Strict_Date(start)) :: _ => | 
| 425 | parse(AFP_Test.engine, "", start, AFP_Test.End, | |
| 426 | AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) | |
| 64099 | 427 | |
| 65665 | 428 | case Jenkins.Start() :: _ => | 
| 64110 | 429 |         log_file.lines.dropWhile(_ != Jenkins.BUILD) match {
 | 
| 430 | case Jenkins.BUILD :: _ :: Jenkins.Start_Date(log_file.Strict_Date(start)) :: _ => | |
| 65663 | 431 | val host = | 
| 432 |               log_file.lines.takeWhile(_ != Jenkins.CONFIGURATION).collectFirst({
 | |
| 433 | case Jenkins.Host(a, b) => a + "." + b | |
| 434 |               }).getOrElse("")
 | |
| 435 |             parse(Jenkins.engine, host, start.to(ZoneId.of("Europe/Berlin")), Jenkins.No_End,
 | |
| 64110 | 436 | Jenkins.Isabelle_Version, Jenkins.AFP_Version) | 
| 437 | case _ => Meta_Info.empty | |
| 438 | } | |
| 439 | ||
| 64341 | 440 |       case line :: _ if line.startsWith("\u0000") => Meta_Info.empty
 | 
| 64109 | 441 | case List(Isatest.End(_)) => Meta_Info.empty | 
| 442 | case _ :: AFP_Test.Bad_Init() :: _ => Meta_Info.empty | |
| 64105 | 443 | case Nil => Meta_Info.empty | 
| 64104 
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
 wenzelm parents: 
64103diff
changeset | 444 | |
| 64110 | 445 |       case _ => log_file.err("cannot detect log file format")
 | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 446 | } | 
| 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 447 | } | 
| 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 448 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 449 | |
| 64098 | 450 | |
| 65276 | 451 | /** build info: toplevel output of isabelle build or Admin/build_history **/ | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 452 | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 453 | val THEORY_TIMING_MARKER = "\ftheory_timing = " | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 454 | val ML_STATISTICS_MARKER = "\fML_statistics = " | 
| 65937 | 455 | val ERROR_MESSAGE_MARKER = "\ferror_message = " | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 456 | val SESSION_NAME = "session_name" | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 457 | |
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 458 | object Session_Status extends Enumeration | 
| 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 459 |   {
 | 
| 65633 | 460 | val existing, finished, failed, cancelled = Value | 
| 64061 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 461 | } | 
| 
1bbea2b55d22
some support for header and data fields, notably from afp-test;
 wenzelm parents: 
64054diff
changeset | 462 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 463 | sealed case class Session_Entry( | 
| 65643 | 464 | chapter: String = "", | 
| 465 | groups: List[String] = Nil, | |
| 466 | threads: Option[Int] = None, | |
| 467 | timing: Timing = Timing.zero, | |
| 468 | ml_timing: Timing = Timing.zero, | |
| 66913 | 469 | sources: Option[String] = None, | 
| 65643 | 470 | heap_size: Option[Long] = None, | 
| 471 | status: Option[Session_Status.Value] = None, | |
| 65937 | 472 | errors: List[String] = Nil, | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 473 | theory_timings: Map[String, Timing] = Map.empty, | 
| 65643 | 474 | ml_statistics: List[Properties.T] = Nil) | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 475 |   {
 | 
| 65631 | 476 | def proper_groups: Option[String] = if (groups.isEmpty) None else Some(cat_lines(groups)) | 
| 65643 | 477 | def finished: Boolean = status == Some(Session_Status.finished) | 
| 65937 | 478 | def failed: Boolean = status == Some(Session_Status.failed) | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 479 | } | 
| 64054 | 480 | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 481 | object Build_Info | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 482 |   {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 483 | val sessions_dummy: Map[String, Session_Entry] = | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 484 |       Map("" -> Session_Entry(theory_timings = Map("" -> Timing.zero)))
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 485 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 486 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 487 | sealed case class Build_Info(sessions: Map[String, Session_Entry]) | 
| 64054 | 488 |   {
 | 
| 65937 | 489 | def finished_sessions: List[String] = for ((a, b) <- sessions.toList if b.finished) yield a | 
| 490 | def failed_sessions: List[String] = for ((a, b) <- sessions.toList if b.failed) yield a | |
| 64054 | 491 | } | 
| 492 | ||
| 65646 | 493 | private def parse_build_info(log_file: Log_File, parse_ml_statistics: Boolean): Build_Info = | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 494 |   {
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 495 | object Chapter_Name | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 496 |     {
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 497 | def unapply(s: String): Some[(String, String)] = | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 498 |         space_explode('/', s) match {
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 499 | case List(chapter, name) => Some((chapter, name)) | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 500 |           case _ => Some(("", s))
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 501 | } | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 502 | } | 
| 64054 | 503 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 504 |     val Session_No_Groups = new Regex("""^Session (\S+)$""")
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 505 |     val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""")
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 506 | val Session_Finished1 = | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 507 |       new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 508 | val Session_Finished2 = | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 509 |       new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 510 | val Session_Timing = | 
| 65679 | 511 |       new Regex("""^Timing (\S+) \((\d+) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
 | 
| 64086 
ac7ae5067783
clarified status: started sessions may bomb without explicit FAILED or CANCELLED (cf. in afp-test-devel-2016-01-03.log);
 wenzelm parents: 
64085diff
changeset | 512 |     val Session_Started = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""")
 | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 513 |     val Session_Failed = new Regex("""^(\S+) FAILED""")
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 514 |     val Session_Cancelled = new Regex("""^(\S+) CANCELLED""")
 | 
| 66913 | 515 |     val Sources = new Regex("""^Sources (\S+) (\S{""" + SHA1.digest_length + """})$""")
 | 
| 64120 | 516 |     val Heap = new Regex("""^Heap (\S+) \((\d+) bytes\)$""")
 | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 517 | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 518 | object Theory_Timing | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 519 |     {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 520 | def unapply(line: String): Option[(String, (String, Timing))] = | 
| 67007 
978c584609de
tolerate odd negative times from old log files (before 1698e9ccef2d);
 wenzelm parents: 
66995diff
changeset | 521 |       {
 | 
| 
978c584609de
tolerate odd negative times from old log files (before 1698e9ccef2d);
 wenzelm parents: 
66995diff
changeset | 522 |         val line1 = line.replace('~', '-')
 | 
| 
978c584609de
tolerate odd negative times from old log files (before 1698e9ccef2d);
 wenzelm parents: 
66995diff
changeset | 523 |         Library.try_unprefix(THEORY_TIMING_MARKER, line1).map(log_file.parse_props(_)) match {
 | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 524 | case Some((SESSION_NAME, name) :: props) => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 525 |             (props, props) match {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 526 | case (Markup.Name(thy), Markup.Timing_Properties(t)) => Some((name, thy -> t)) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 527 | case _ => None | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 528 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 529 | case _ => None | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 530 | } | 
| 67007 
978c584609de
tolerate odd negative times from old log files (before 1698e9ccef2d);
 wenzelm parents: 
66995diff
changeset | 531 | } | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 532 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 533 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 534 | var chapter = Map.empty[String, String] | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 535 | var groups = Map.empty[String, List[String]] | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 536 | var threads = Map.empty[String, Int] | 
| 64054 | 537 | var timing = Map.empty[String, Timing] | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 538 | var ml_timing = Map.empty[String, Timing] | 
| 64086 
ac7ae5067783
clarified status: started sessions may bomb without explicit FAILED or CANCELLED (cf. in afp-test-devel-2016-01-03.log);
 wenzelm parents: 
64085diff
changeset | 539 | var started = Set.empty[String] | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 540 | var failed = Set.empty[String] | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 541 | var cancelled = Set.empty[String] | 
| 66913 | 542 | var sources = Map.empty[String, String] | 
| 65627 | 543 | var heap_sizes = Map.empty[String, Long] | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 544 | var theory_timings = Map.empty[String, Map[String, Timing]] | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 545 | var ml_statistics = Map.empty[String, List[Properties.T]] | 
| 65937 | 546 | var errors = Map.empty[String, List[String]] | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 547 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 548 | def all_sessions: Set[String] = | 
| 64120 | 549 | chapter.keySet ++ groups.keySet ++ threads.keySet ++ timing.keySet ++ ml_timing.keySet ++ | 
| 66913 | 550 | failed ++ cancelled ++ started ++ sources.keySet ++ heap_sizes.keySet ++ | 
| 551 | theory_timings.keySet ++ ml_statistics.keySet | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 552 | |
| 64054 | 553 | |
| 64062 | 554 |     for (line <- log_file.lines) {
 | 
| 64054 | 555 |       line match {
 | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 556 | case Session_No_Groups(Chapter_Name(chapt, name)) => | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 557 | chapter += (name -> chapt) | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 558 | groups += (name -> Nil) | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 559 | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 560 | case Session_Groups(Chapter_Name(chapt, name), grps) => | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 561 | chapter += (name -> chapt) | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 562 | groups += (name -> Word.explode(grps)) | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 563 | |
| 64086 
ac7ae5067783
clarified status: started sessions may bomb without explicit FAILED or CANCELLED (cf. in afp-test-devel-2016-01-03.log);
 wenzelm parents: 
64085diff
changeset | 564 | case Session_Started(name) => | 
| 
ac7ae5067783
clarified status: started sessions may bomb without explicit FAILED or CANCELLED (cf. in afp-test-devel-2016-01-03.log);
 wenzelm parents: 
64085diff
changeset | 565 | started += name | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 566 | |
| 64054 | 567 | case Session_Finished1(name, | 
| 568 | Value.Int(e1), Value.Int(e2), Value.Int(e3), | |
| 569 | Value.Int(c1), Value.Int(c2), Value.Int(c3)) => | |
| 570 | val elapsed = Time.hms(e1, e2, e3) | |
| 571 | val cpu = Time.hms(c1, c2, c3) | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 572 | timing += (name -> Timing(elapsed, cpu, Time.zero)) | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 573 | |
| 64054 | 574 | case Session_Finished2(name, | 
| 575 | Value.Int(e1), Value.Int(e2), Value.Int(e3)) => | |
| 576 | val elapsed = Time.hms(e1, e2, e3) | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 577 | timing += (name -> Timing(elapsed, Time.zero, Time.zero)) | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 578 | |
| 64054 | 579 | case Session_Timing(name, | 
| 580 | Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) => | |
| 581 | val elapsed = Time.seconds(e) | |
| 582 | val cpu = Time.seconds(c) | |
| 583 | val gc = Time.seconds(g) | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 584 | ml_timing += (name -> Timing(elapsed, cpu, gc)) | 
| 64054 | 585 | threads += (name -> t) | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 586 | |
| 66913 | 587 | case Sources(name, s) => | 
| 588 | sources += (name -> s) | |
| 589 | ||
| 64120 | 590 | case Heap(name, Value.Long(size)) => | 
| 591 | heap_sizes += (name -> size) | |
| 592 | ||
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 593 | case _ if line.startsWith(THEORY_TIMING_MARKER) && YXML.detect(line) => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 594 |           line match {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 595 | case Theory_Timing(name, theory_timing) => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 596 | theory_timings += (name -> (theory_timings.getOrElse(name, Map.empty) + theory_timing)) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 597 |             case _ => log_file.err("malformed theory_timing " + quote(line))
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 598 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 599 | |
| 65937 | 600 | case _ if parse_ml_statistics && line.startsWith(ML_STATISTICS_MARKER) && YXML.detect(line) => | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 601 |           Library.try_unprefix(ML_STATISTICS_MARKER, line).map(log_file.parse_props(_)) match {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 602 | case Some((SESSION_NAME, name) :: props) => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 603 | ml_statistics += (name -> (props :: ml_statistics.getOrElse(name, Nil))) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 604 |             case _ => log_file.err("malformed ML_statistics " + quote(line))
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 605 | } | 
| 64119 
8094eaa38d4b
inline session ML statistics into main build log;
 wenzelm parents: 
64117diff
changeset | 606 | |
| 65937 | 607 | case _ if line.startsWith(ERROR_MESSAGE_MARKER) && YXML.detect(line) => | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 608 |           Library.try_unprefix(ERROR_MESSAGE_MARKER, line).map(log_file.parse_props(_)) match {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 609 | case Some(List((SESSION_NAME, name), (Markup.CONTENT, msg))) => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 610 | errors += (name -> (Library.decode_lines(msg) :: errors.getOrElse(name, Nil))) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 611 |             case _ => log_file.err("malformed error message " + quote(line))
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 612 | } | 
| 65937 | 613 | |
| 64054 | 614 | case _ => | 
| 615 | } | |
| 616 | } | |
| 617 | ||
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 618 | val sessions = | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 619 | Map( | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 620 |         (for (name <- all_sessions.toList) yield {
 | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 621 | val status = | 
| 65633 | 622 | if (failed(name)) Session_Status.failed | 
| 623 | else if (cancelled(name)) Session_Status.cancelled | |
| 64086 
ac7ae5067783
clarified status: started sessions may bomb without explicit FAILED or CANCELLED (cf. in afp-test-devel-2016-01-03.log);
 wenzelm parents: 
64085diff
changeset | 624 | else if (timing.isDefinedAt(name) || ml_timing.isDefinedAt(name)) | 
| 65633 | 625 | Session_Status.finished | 
| 626 | else if (started(name)) Session_Status.failed | |
| 627 | else Session_Status.existing | |
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 628 | val entry = | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 629 | Session_Entry( | 
| 65643 | 630 | chapter = chapter.getOrElse(name, ""), | 
| 631 | groups = groups.getOrElse(name, Nil), | |
| 632 | threads = threads.get(name), | |
| 633 | timing = timing.getOrElse(name, Timing.zero), | |
| 634 | ml_timing = ml_timing.getOrElse(name, Timing.zero), | |
| 66913 | 635 | sources = sources.get(name), | 
| 65643 | 636 | heap_size = heap_sizes.get(name), | 
| 637 | status = Some(status), | |
| 65937 | 638 | errors = errors.getOrElse(name, Nil).reverse, | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 639 | theory_timings = theory_timings.getOrElse(name, Map.empty), | 
| 65643 | 640 | ml_statistics = ml_statistics.getOrElse(name, Nil).reverse) | 
| 64085 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 641 | (name -> entry) | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 642 | }):_*) | 
| 
1c451e5c145f
clarified parse_build_info: isabelle build output;
 wenzelm parents: 
64083diff
changeset | 643 | Build_Info(sessions) | 
| 64054 | 644 | } | 
| 64099 | 645 | |
| 646 | ||
| 647 | ||
| 65276 | 648 | /** session info: produced by isabelle build as session log.gz file **/ | 
| 64099 | 649 | |
| 650 | sealed case class Session_Info( | |
| 651 | session_timing: Properties.T, | |
| 652 | command_timings: List[Properties.T], | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 653 | theory_timings: List[Properties.T], | 
| 64099 | 654 | ml_statistics: List[Properties.T], | 
| 65934 | 655 | task_statistics: List[Properties.T], | 
| 656 | errors: List[String]) | |
| 66944 
05df740cb54b
more informative timeout message, notably for build_status;
 wenzelm parents: 
66913diff
changeset | 657 |   {
 | 
| 
05df740cb54b
more informative timeout message, notably for build_status;
 wenzelm parents: 
66913diff
changeset | 658 | def error(s: String): Session_Info = | 
| 
05df740cb54b
more informative timeout message, notably for build_status;
 wenzelm parents: 
66913diff
changeset | 659 | copy(errors = errors ::: List(s)) | 
| 
05df740cb54b
more informative timeout message, notably for build_status;
 wenzelm parents: 
66913diff
changeset | 660 | } | 
| 64099 | 661 | |
| 662 | private def parse_session_info( | |
| 663 | log_file: Log_File, | |
| 664 | command_timings: Boolean, | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 665 | theory_timings: Boolean, | 
| 64099 | 666 | ml_statistics: Boolean, | 
| 667 | task_statistics: Boolean): Session_Info = | |
| 668 |   {
 | |
| 65290 | 669 | Session_Info( | 
| 670 |       session_timing = log_file.find_props("\fTiming = ") getOrElse Nil,
 | |
| 671 |       command_timings = if (command_timings) log_file.filter_props("\fcommand_timing = ") else Nil,
 | |
| 66873 
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
 wenzelm parents: 
66863diff
changeset | 672 | theory_timings = if (theory_timings) log_file.filter_props(THEORY_TIMING_MARKER) else Nil, | 
| 65290 | 673 | ml_statistics = if (ml_statistics) log_file.filter_props(ML_STATISTICS_MARKER) else Nil, | 
| 65934 | 674 |       task_statistics = if (task_statistics) log_file.filter_props("\ftask_statistics = ") else Nil,
 | 
| 65937 | 675 | errors = log_file.filter_lines(ERROR_MESSAGE_MARKER).map(Library.decode_lines(_))) | 
| 64099 | 676 | } | 
| 65595 | 677 | |
| 68018 | 678 | def compress_errors(errors: List[String], cache: XZ.Cache = XZ.cache()): Option[Bytes] = | 
| 65937 | 679 | if (errors.isEmpty) None | 
| 68018 | 680 |     else {
 | 
| 681 | Some(Bytes(YXML.string_of_body(XML.Encode.list(XML.Encode.string)(errors))). | |
| 682 | compress(cache = cache)) | |
| 683 | } | |
| 65937 | 684 | |
| 68018 | 685 | def uncompress_errors(bytes: Bytes, cache: XZ.Cache = XZ.cache()): List[String] = | 
| 65937 | 686 | if (bytes.isEmpty) Nil | 
| 68018 | 687 |     else {
 | 
| 688 | XML.Decode.list(YXML.string_of_body(_))(YXML.parse_body(bytes.uncompress(cache = cache).text)) | |
| 689 | } | |
| 65937 | 690 | |
| 65595 | 691 | |
| 692 | ||
| 693 | /** persistent store **/ | |
| 694 | ||
| 65694 | 695 | /* SQL data model */ | 
| 696 | ||
| 697 | object Data | |
| 698 |   {
 | |
| 65702 | 699 | def build_log_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = | 
| 65700 | 700 |       SQL.Table("isabelle_build_log_" + name, columns, body)
 | 
| 701 | ||
| 702 | ||
| 65694 | 703 | /* main content */ | 
| 704 | ||
| 66857 | 705 |     val log_name = SQL.Column.string("log_name").make_primary_key
 | 
| 706 |     val session_name = SQL.Column.string("session_name").make_primary_key
 | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 707 |     val theory_name = SQL.Column.string("theory_name").make_primary_key
 | 
| 65694 | 708 |     val chapter = SQL.Column.string("chapter")
 | 
| 709 |     val groups = SQL.Column.string("groups")
 | |
| 710 |     val threads = SQL.Column.int("threads")
 | |
| 711 |     val timing_elapsed = SQL.Column.long("timing_elapsed")
 | |
| 712 |     val timing_cpu = SQL.Column.long("timing_cpu")
 | |
| 713 |     val timing_gc = SQL.Column.long("timing_gc")
 | |
| 714 |     val timing_factor = SQL.Column.double("timing_factor")
 | |
| 715 |     val ml_timing_elapsed = SQL.Column.long("ml_timing_elapsed")
 | |
| 716 |     val ml_timing_cpu = SQL.Column.long("ml_timing_cpu")
 | |
| 717 |     val ml_timing_gc = SQL.Column.long("ml_timing_gc")
 | |
| 718 |     val ml_timing_factor = SQL.Column.double("ml_timing_factor")
 | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 719 |     val theory_timing_elapsed = SQL.Column.long("theory_timing_elapsed")
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 720 |     val theory_timing_cpu = SQL.Column.long("theory_timing_cpu")
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 721 |     val theory_timing_gc = SQL.Column.long("theory_timing_gc")
 | 
| 65694 | 722 |     val heap_size = SQL.Column.long("heap_size")
 | 
| 723 |     val status = SQL.Column.string("status")
 | |
| 65937 | 724 |     val errors = SQL.Column.bytes("errors")
 | 
| 66913 | 725 |     val sources = SQL.Column.string("sources")
 | 
| 65694 | 726 |     val ml_statistics = SQL.Column.bytes("ml_statistics")
 | 
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 727 |     val known = SQL.Column.bool("known")
 | 
| 65694 | 728 | |
| 729 | val meta_info_table = | |
| 65702 | 730 |       build_log_table("meta_info", log_name :: Prop.all_props ::: Settings.all_settings)
 | 
| 65694 | 731 | |
| 732 | val sessions_table = | |
| 65702 | 733 |       build_log_table("sessions",
 | 
| 65694 | 734 | List(log_name, session_name, chapter, groups, threads, timing_elapsed, timing_cpu, | 
| 735 | timing_gc, timing_factor, ml_timing_elapsed, ml_timing_cpu, ml_timing_gc, ml_timing_factor, | |
| 66913 | 736 | heap_size, status, errors, sources)) | 
| 65694 | 737 | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 738 | val theories_table = | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 739 |       build_log_table("theories",
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 740 | List(log_name, session_name, theory_name, theory_timing_elapsed, theory_timing_cpu, | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 741 | theory_timing_gc)) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 742 | |
| 65694 | 743 | val ml_statistics_table = | 
| 65702 | 744 |       build_log_table("ml_statistics", List(log_name, session_name, ml_statistics))
 | 
| 65694 | 745 | |
| 746 | ||
| 66855 | 747 | /* AFP versions */ | 
| 748 | ||
| 749 | val isabelle_afp_versions_table: SQL.Table = | |
| 750 |     {
 | |
| 751 | val version1 = Prop.isabelle_version | |
| 752 | val version2 = Prop.afp_version | |
| 66857 | 753 |       build_log_table("isabelle_afp_versions", List(version1.make_primary_key, version2),
 | 
| 66855 | 754 | SQL.select(List(version1, version2), distinct = true) + meta_info_table + | 
| 66856 | 755 | " WHERE " + version1.defined + " AND " + version2.defined) | 
| 66855 | 756 | } | 
| 757 | ||
| 758 | ||
| 65705 | 759 | /* earliest pull date for repository version (PostgreSQL queries) */ | 
| 65694 | 760 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 761 | def pull_date(afp: Boolean = false) = | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 762 |       if (afp) SQL.Column.date("afp_pull_date")
 | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 763 |       else SQL.Column.date("pull_date")
 | 
| 65694 | 764 | |
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 765 | def pull_date_table(afp: Boolean = false): SQL.Table = | 
| 65709 | 766 |     {
 | 
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 767 | val (name, versions) = | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 768 |         if (afp) ("afp_pull_date", List(Prop.isabelle_version, Prop.afp_version))
 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 769 |         else ("pull_date", List(Prop.isabelle_version))
 | 
| 65694 | 770 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 771 | build_log_table(name, versions.map(_.make_primary_key) ::: List(pull_date(afp)), | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 772 |         "SELECT " + versions.mkString(", ") +
 | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 773 |           ", min(" + Prop.build_start + ") AS " + pull_date(afp) +
 | 
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 774 | " FROM " + meta_info_table + | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 775 |         " WHERE " + (versions ::: List(Prop.build_start)).map(_.defined).mkString(" AND ") +
 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 776 |         " GROUP BY " + versions.mkString(", "))
 | 
| 66855 | 777 | } | 
| 778 | ||
| 779 | ||
| 780 | /* recent entries */ | |
| 781 | ||
| 65736 | 782 | def recent_time(days: Int): SQL.Source = | 
| 783 | "now() - INTERVAL '" + days.max(0) + " days'" | |
| 784 | ||
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 785 | def recent_pull_date_table( | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 786 | days: Int, rev: String = "", afp_rev: Option[String] = None): SQL.Table = | 
| 65702 | 787 |     {
 | 
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 788 | val afp = afp_rev.isDefined | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 789 |       val rev2 = afp_rev.getOrElse("")
 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 790 | val table = pull_date_table(afp) | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 791 | |
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 792 | val version1 = Prop.isabelle_version | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 793 | val version2 = Prop.afp_version | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 794 | val eq1 = version1(table) + " = " + SQL.string(rev) | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 795 | val eq2 = version2(table) + " = " + SQL.string(rev2) | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 796 | |
| 65777 | 797 |       SQL.Table("recent_pull_date", table.columns,
 | 
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 798 | table.select(table.columns, | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 799 | "WHERE " + pull_date(afp)(table) + " > " + recent_time(days) + | 
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 800 | (if (rev != "" && rev2 == "") " OR " + eq1 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 801 | else if (rev == "" && rev2 != "") " OR " + eq2 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 802 |            else if (rev != "" && rev2 != "") " OR (" + eq1 + " AND " + eq2 + ")"
 | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 803 | else ""))) | 
| 65702 | 804 | } | 
| 65694 | 805 | |
| 65781 | 806 | def select_recent_log_names(days: Int): SQL.Source = | 
| 807 |     {
 | |
| 808 | val table1 = meta_info_table | |
| 809 | val table2 = recent_pull_date_table(days) | |
| 810 | table1.select(List(log_name), distinct = true) + SQL.join_inner + table2.query_named + | |
| 811 | " ON " + Prop.isabelle_version(table1) + " = " + Prop.isabelle_version(table2) | |
| 812 | } | |
| 813 | ||
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 814 | def select_recent_versions(days: Int, | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 815 | rev: String = "", afp_rev: Option[String] = None, sql: SQL.Source = ""): SQL.Source = | 
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 816 |     {
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 817 | val afp = afp_rev.isDefined | 
| 66858 | 818 | val version = Prop.isabelle_version | 
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 819 | val table1 = recent_pull_date_table(days, rev = rev, afp_rev = afp_rev) | 
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 820 | val table2 = meta_info_table | 
| 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 821 |       val aux_table = SQL.Table("aux", table2.columns, table2.select(sql = sql))
 | 
| 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 822 | |
| 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 823 | val columns = | 
| 66858 | 824 | table1.columns.map(c => c(table1)) ::: | 
| 825 | List(known.copy(expr = log_name(aux_table).defined)) | |
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 826 | SQL.select(columns, distinct = true) + | 
| 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 827 | table1.query_named + SQL.join_outer + aux_table.query_named + | 
| 66858 | 828 | " ON " + version(table1) + " = " + version(aux_table) + | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 829 | " ORDER BY " + pull_date(afp)(table1) + " DESC" | 
| 65783 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 830 | } | 
| 
d3d5cb2d6866
pick isabelle_version based on build_log database;
 wenzelm parents: 
65781diff
changeset | 831 | |
| 65724 | 832 | |
| 833 | /* universal view on main data */ | |
| 834 | ||
| 835 | val universal_table: SQL.Table = | |
| 836 |     {
 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 837 | val afp_pull_date = pull_date(afp = true) | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 838 | val version1 = Prop.isabelle_version | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 839 | val version2 = Prop.afp_version | 
| 65724 | 840 | val table1 = meta_info_table | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 841 | val table2 = pull_date_table(afp = true) | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 842 | val table3 = pull_date_table() | 
| 65724 | 843 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 844 | val a_columns = log_name :: afp_pull_date :: table1.columns.tail | 
| 65850 
5414c14c3984
clarified universal table: include ml_statistics;
 wenzelm parents: 
65804diff
changeset | 845 | val a_table = | 
| 
5414c14c3984
clarified universal table: include ml_statistics;
 wenzelm parents: 
65804diff
changeset | 846 |         SQL.Table("a", a_columns,
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 847 | SQL.select(List(log_name, afp_pull_date) ::: table1.columns.tail.map(_.apply(table1))) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 848 | table1 + SQL.join_outer + table2 + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 849 | " ON " + version1(table1) + " = " + version1(table2) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 850 | " AND " + version2(table1) + " = " + version2(table2)) | 
| 65724 | 851 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 852 | val b_columns = log_name :: pull_date() :: a_columns.tail | 
| 65850 
5414c14c3984
clarified universal table: include ml_statistics;
 wenzelm parents: 
65804diff
changeset | 853 | val b_table = | 
| 
5414c14c3984
clarified universal table: include ml_statistics;
 wenzelm parents: 
65804diff
changeset | 854 |         SQL.Table("b", b_columns,
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 855 | SQL.select( | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 856 | List(log_name(a_table), pull_date()(table3)) ::: a_columns.tail.map(_.apply(a_table))) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 857 | a_table.query_named + SQL.join_outer + table3 + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 858 | " ON " + version1(a_table) + " = " + version1(table3)) | 
| 65850 
5414c14c3984
clarified universal table: include ml_statistics;
 wenzelm parents: 
65804diff
changeset | 859 | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 860 | val c_columns = b_columns ::: sessions_table.columns.tail | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 861 | val c_table = | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 862 |         SQL.Table("c", c_columns,
 | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 863 | SQL.select(log_name(b_table) :: c_columns.tail) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 864 | b_table.query_named + SQL.join_inner + sessions_table + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 865 | " ON " + log_name(b_table) + " = " + log_name(sessions_table)) | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 866 | |
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 867 |       SQL.Table("isabelle_build_log", c_columns ::: List(ml_statistics),
 | 
| 65724 | 868 |         {
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 869 | SQL.select(c_columns.map(_.apply(c_table)) ::: List(ml_statistics)) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 870 | c_table.query_named + SQL.join_outer + ml_statistics_table + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 871 | " ON " + log_name(c_table) + " = " + log_name(ml_statistics_table) + | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 872 | " AND " + session_name(c_table) + " = " + session_name(ml_statistics_table) | 
| 65724 | 873 | }) | 
| 874 | } | |
| 65694 | 875 | } | 
| 876 | ||
| 877 | ||
| 878 | /* database access */ | |
| 879 | ||
| 65595 | 880 | def store(options: Options): Store = new Store(options) | 
| 881 | ||
| 65857 | 882 | class Store private[Build_Log](options: Options) | 
| 65595 | 883 |   {
 | 
| 68169 | 884 | val xml_cache: XML.Cache = XML.make_cache() | 
| 68018 | 885 | val xz_cache: XZ.Cache = XZ.make_cache() | 
| 65857 | 886 | |
| 65595 | 887 | def open_database( | 
| 888 |       user: String = options.string("build_log_database_user"),
 | |
| 889 |       password: String = options.string("build_log_database_password"),
 | |
| 890 |       database: String = options.string("build_log_database_name"),
 | |
| 891 |       host: String = options.string("build_log_database_host"),
 | |
| 892 |       port: Int = options.int("build_log_database_port"),
 | |
| 893 |       ssh_host: String = options.string("build_log_ssh_host"),
 | |
| 894 |       ssh_user: String = options.string("build_log_ssh_user"),
 | |
| 895 |       ssh_port: Int = options.int("build_log_ssh_port")): PostgreSQL.Database =
 | |
| 896 |     {
 | |
| 897 | PostgreSQL.open_database( | |
| 898 | user = user, password = password, database = database, host = host, port = port, | |
| 899 | ssh = | |
| 900 | if (ssh_host == "") None | |
| 67067 | 901 | else Some(SSH.open_session(options, host = ssh_host, user = ssh_user, port = port)), | 
| 65636 
df804cdba5f9
ssh_close for proper termination after use of database;
 wenzelm parents: 
65633diff
changeset | 902 | ssh_close = true) | 
| 65595 | 903 | } | 
| 65599 | 904 | |
| 65723 
3ee466e89047
clarified signature: PostgreSQL manages high-volume data, SQLite only sees small snapshots;
 wenzelm parents: 
65722diff
changeset | 905 | def update_database(db: PostgreSQL.Database, dirs: List[Path], ml_statistics: Boolean = false) | 
| 65694 | 906 |     {
 | 
| 907 | write_info(db, Log_File.find_files(dirs), ml_statistics = ml_statistics) | |
| 908 | ||
| 66863 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 909 | db.create_view(Data.pull_date_table()) | 
| 
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
 wenzelm parents: 
66858diff
changeset | 910 | db.create_view(Data.pull_date_table(afp = true)) | 
| 65724 | 911 | db.create_view(Data.universal_table) | 
| 65694 | 912 | } | 
| 913 | ||
| 65723 
3ee466e89047
clarified signature: PostgreSQL manages high-volume data, SQLite only sees small snapshots;
 wenzelm parents: 
65722diff
changeset | 914 | def snapshot_database(db: PostgreSQL.Database, sqlite_database: Path, | 
| 65705 | 915 | days: Int = 100, ml_statistics: Boolean = false) | 
| 65694 | 916 |     {
 | 
| 917 | Isabelle_System.mkdirs(sqlite_database.dir) | |
| 918 | sqlite_database.file.delete | |
| 919 | ||
| 920 | using(SQLite.open_database(sqlite_database))(db2 => | |
| 921 |       {
 | |
| 922 |         db.transaction {
 | |
| 923 |           db2.transaction {
 | |
| 65705 | 924 | // main content | 
| 925 | db2.create_table(Data.meta_info_table) | |
| 926 | db2.create_table(Data.sessions_table) | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 927 | db2.create_table(Data.theories_table) | 
| 65705 | 928 | db2.create_table(Data.ml_statistics_table) | 
| 929 | ||
| 930 | val recent_log_names = | |
| 65781 | 931 | db.using_statement(Data.select_recent_log_names(days))(stmt => | 
| 65779 | 932 | stmt.execute_query().iterator(_.string(Data.log_name)).toList) | 
| 65705 | 933 | |
| 934 |             for (log_name <- recent_log_names) {
 | |
| 935 | read_meta_info(db, log_name).foreach(meta_info => | |
| 936 | update_meta_info(db2, log_name, meta_info)) | |
| 937 | ||
| 938 | update_sessions(db2, log_name, read_build_info(db, log_name)) | |
| 939 | ||
| 65856 | 940 |               if (ml_statistics) {
 | 
| 941 | update_ml_statistics(db2, log_name, | |
| 942 | read_build_info(db, log_name, ml_statistics = true)) | |
| 943 | } | |
| 65705 | 944 | } | 
| 945 | ||
| 946 | // pull_date | |
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 947 | for (afp <- List(false, true)) | 
| 65694 | 948 |             {
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 949 |               val afp_rev = if (afp) Some("") else None
 | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 950 | val table = Data.pull_date_table(afp) | 
| 65694 | 951 | db2.create_table(table) | 
| 65698 | 952 | db2.using_statement(table.insert())(stmt2 => | 
| 65694 | 953 |               {
 | 
| 66880 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 954 | db.using_statement( | 
| 
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
 wenzelm parents: 
66874diff
changeset | 955 | Data.recent_pull_date_table(days, afp_rev = afp_rev).query)(stmt => | 
| 65694 | 956 |                 {
 | 
| 65740 | 957 | val res = stmt.execute_query() | 
| 958 |                   while (res.next()) {
 | |
| 65748 | 959 |                     for ((c, i) <- table.columns.zipWithIndex) {
 | 
| 960 | stmt2.string(i + 1) = res.get_string(c) | |
| 961 | } | |
| 65740 | 962 | stmt2.execute() | 
| 65694 | 963 | } | 
| 964 | }) | |
| 965 | }) | |
| 65709 | 966 | } | 
| 65705 | 967 | |
| 968 | // full view | |
| 65724 | 969 | db2.create_view(Data.universal_table) | 
| 65694 | 970 | } | 
| 971 | } | |
| 65708 | 972 | db2.rebuild | 
| 65694 | 973 | }) | 
| 974 | } | |
| 975 | ||
| 65688 | 976 | def domain(db: SQL.Database, table: SQL.Table, column: SQL.Column): Set[String] = | 
| 65698 | 977 | db.using_statement(table.select(List(column), distinct = true))(stmt => | 
| 65740 | 978 | stmt.execute_query().iterator(_.string(column)).toSet) | 
| 65688 | 979 | |
| 65705 | 980 | def update_meta_info(db: SQL.Database, log_name: String, meta_info: Meta_Info) | 
| 65632 | 981 |     {
 | 
| 65694 | 982 | val table = Data.meta_info_table | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 983 | db.using_statement(db.insert_permissive(table))(stmt => | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 984 |       {
 | 
| 65748 | 985 | stmt.string(1) = log_name | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 986 |         for ((c, i) <- table.columns.tail.zipWithIndex) {
 | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 987 | if (c.T == SQL.Type.Date) | 
| 65748 | 988 | stmt.date(i + 2) = meta_info.get_date(c) | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 989 | else | 
| 65748 | 990 | stmt.string(i + 2) = meta_info.get(c) | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 991 | } | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 992 | stmt.execute() | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 993 | }) | 
| 65600 | 994 | } | 
| 995 | ||
| 65705 | 996 | def update_sessions(db: SQL.Database, log_name: String, build_info: Build_Info) | 
| 65599 | 997 |     {
 | 
| 65694 | 998 | val table = Data.sessions_table | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 999 | db.using_statement(db.insert_permissive(table))(stmt => | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1000 |       {
 | 
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1001 | val sessions = | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1002 | if (build_info.sessions.isEmpty) Build_Info.sessions_dummy | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1003 | else build_info.sessions | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1004 |         for ((session_name, session) <- sessions) {
 | 
| 65748 | 1005 | stmt.string(1) = log_name | 
| 1006 | stmt.string(2) = session_name | |
| 65853 | 1007 | stmt.string(3) = proper_string(session.chapter) | 
| 65748 | 1008 | stmt.string(4) = session.proper_groups | 
| 1009 | stmt.int(5) = session.threads | |
| 1010 | stmt.long(6) = session.timing.elapsed.proper_ms | |
| 1011 | stmt.long(7) = session.timing.cpu.proper_ms | |
| 1012 | stmt.long(8) = session.timing.gc.proper_ms | |
| 1013 | stmt.double(9) = session.timing.factor | |
| 1014 | stmt.long(10) = session.ml_timing.elapsed.proper_ms | |
| 1015 | stmt.long(11) = session.ml_timing.cpu.proper_ms | |
| 1016 | stmt.long(12) = session.ml_timing.gc.proper_ms | |
| 1017 | stmt.double(13) = session.ml_timing.factor | |
| 1018 | stmt.long(14) = session.heap_size | |
| 1019 | stmt.string(15) = session.status.map(_.toString) | |
| 68018 | 1020 | stmt.bytes(16) = compress_errors(session.errors, cache = xz_cache) | 
| 66913 | 1021 | stmt.string(17) = session.sources | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1022 | stmt.execute() | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1023 | } | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1024 | }) | 
| 65642 | 1025 | } | 
| 1026 | ||
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1027 | def update_theories(db: SQL.Database, log_name: String, build_info: Build_Info) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1028 |     {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1029 | val table = Data.theories_table | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1030 | db.using_statement(db.insert_permissive(table))(stmt => | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1031 |       {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1032 | val sessions = | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1033 |           if (build_info.sessions.forall({ case (_, session) => session.theory_timings.isEmpty }))
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1034 | Build_Info.sessions_dummy | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1035 | else build_info.sessions | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1036 |         for {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1037 | (session_name, session) <- sessions | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1038 | (theory_name, timing) <- session.theory_timings | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1039 |         } {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1040 | stmt.string(1) = log_name | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1041 | stmt.string(2) = session_name | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1042 | stmt.string(3) = theory_name | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1043 | stmt.long(4) = timing.elapsed.ms | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1044 | stmt.long(5) = timing.cpu.ms | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1045 | stmt.long(6) = timing.gc.ms | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1046 | stmt.execute() | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1047 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1048 | }) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1049 | } | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1050 | |
| 65705 | 1051 | def update_ml_statistics(db: SQL.Database, log_name: String, build_info: Build_Info) | 
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1052 |     {
 | 
| 65694 | 1053 | val table = Data.ml_statistics_table | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1054 | db.using_statement(db.insert_permissive(table))(stmt => | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1055 |       {
 | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1056 | val ml_stats: List[(String, Option[Bytes])] = | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1057 | Par_List.map[(String, Session_Entry), (String, Option[Bytes])]( | 
| 68018 | 1058 |             { case (a, b) => (a, Properties.compress(b.ml_statistics, cache = xz_cache).proper) },
 | 
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1059 | build_info.sessions.iterator.filter(p => p._2.ml_statistics.nonEmpty).toList) | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1060 |         val entries = if (ml_stats.nonEmpty) ml_stats else List("" -> None)
 | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1061 |         for ((session_name, ml_statistics) <- entries) {
 | 
| 65748 | 1062 | stmt.string(1) = log_name | 
| 1063 | stmt.string(2) = session_name | |
| 1064 | stmt.bytes(3) = ml_statistics | |
| 65703 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1065 | stmt.execute() | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1066 | } | 
| 
cead65c19f2e
more direct insert_permissive statement, which avoids somewhat fragile nested transactions;
 wenzelm parents: 
65702diff
changeset | 1067 | }) | 
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1068 | } | 
| 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1069 | |
| 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1070 | def write_info(db: SQL.Database, files: List[JFile], ml_statistics: Boolean = false) | 
| 65642 | 1071 |     {
 | 
| 65705 | 1072 | abstract class Table_Status(table: SQL.Table) | 
| 65642 | 1073 |       {
 | 
| 65688 | 1074 | db.create_table(table) | 
| 65694 | 1075 | private var known: Set[String] = domain(db, table, Data.log_name) | 
| 65688 | 1076 | |
| 65642 | 1077 | def required(file: JFile): Boolean = !known(Log_File.plain_name(file.getName)) | 
| 65705 | 1078 | |
| 1079 | def update_db(db: SQL.Database, log_file: Log_File): Unit | |
| 65642 | 1080 | def update(log_file: Log_File) | 
| 1081 |         {
 | |
| 1082 |           if (!known(log_file.name)) {
 | |
| 1083 | update_db(db, log_file) | |
| 1084 | known += log_file.name | |
| 65618 | 1085 | } | 
| 65614 
325801edb37d
clarified transaction boundaries: more robust incremental write operations;
 wenzelm parents: 
65613diff
changeset | 1086 | } | 
| 65605 | 1087 | } | 
| 65642 | 1088 | val status = | 
| 1089 | List( | |
| 65705 | 1090 |           new Table_Status(Data.meta_info_table) {
 | 
| 1091 | override def update_db(db: SQL.Database, log_file: Log_File): Unit = | |
| 1092 | update_meta_info(db, log_file.name, log_file.parse_meta_info()) | |
| 1093 | }, | |
| 1094 |           new Table_Status(Data.sessions_table) {
 | |
| 1095 | override def update_db(db: SQL.Database, log_file: Log_File): Unit = | |
| 1096 | update_sessions(db, log_file.name, log_file.parse_build_info()) | |
| 1097 | }, | |
| 66874 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1098 |           new Table_Status(Data.theories_table) {
 | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1099 | override def update_db(db: SQL.Database, log_file: Log_File): Unit = | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1100 | update_theories(db, log_file.name, log_file.parse_build_info()) | 
| 
0b8da0fc9563
store theory timings in session in build_log database;
 wenzelm parents: 
66873diff
changeset | 1101 | }, | 
| 65705 | 1102 |           new Table_Status(Data.ml_statistics_table) {
 | 
| 1103 | override def update_db(db: SQL.Database, log_file: Log_File): Unit = | |
| 1104 |             if (ml_statistics) {
 | |
| 1105 | update_ml_statistics(db, log_file.name, | |
| 1106 | log_file.parse_build_info(ml_statistics = true)) | |
| 1107 | } | |
| 1108 | }) | |
| 65642 | 1109 | |
| 67743 | 1110 | for (file_group <- | 
| 1111 | files.filter(file => status.exists(_.required(file))). | |
| 1112 |               grouped(options.int("build_log_transaction_size") max 1))
 | |
| 1113 |       {
 | |
| 65642 | 1114 | val log_files = Par_List.map[JFile, Log_File](Log_File.apply _, file_group) | 
| 1115 |         db.transaction { log_files.foreach(log_file => status.foreach(_.update(log_file))) }
 | |
| 1116 | } | |
| 65605 | 1117 | } | 
| 1118 | ||
| 65621 | 1119 | def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] = | 
| 1120 |     {
 | |
| 65694 | 1121 | val table = Data.meta_info_table | 
| 65642 | 1122 | val columns = table.columns.tail | 
| 65699 | 1123 | db.using_statement(table.select(columns, Data.log_name.where_equal(log_name)))(stmt => | 
| 65621 | 1124 |       {
 | 
| 65740 | 1125 | val res = stmt.execute_query() | 
| 1126 | if (!res.next) None | |
| 65621 | 1127 |         else {
 | 
| 1128 | val results = | |
| 65642 | 1129 | columns.map(c => c.name -> | 
| 65621 | 1130 | (if (c.T == SQL.Type.Date) | 
| 65740 | 1131 | res.get_date(c).map(Log_File.Date_Format(_)) | 
| 65621 | 1132 | else | 
| 65740 | 1133 | res.get_string(c))) | 
| 65621 | 1134 | val n = Prop.all_props.length | 
| 1135 | val props = for ((x, Some(y)) <- results.take(n)) yield (x, y) | |
| 1136 | val settings = for ((x, Some(y)) <- results.drop(n)) yield (x, y) | |
| 1137 | Some(Meta_Info(props, settings)) | |
| 1138 | } | |
| 1139 | }) | |
| 1140 | } | |
| 1141 | ||
| 1142 | def read_build_info( | |
| 65629 | 1143 | db: SQL.Database, | 
| 1144 | log_name: String, | |
| 1145 | session_names: List[String] = Nil, | |
| 1146 | ml_statistics: Boolean = false): Build_Info = | |
| 65621 | 1147 |     {
 | 
| 65694 | 1148 | val table1 = Data.sessions_table | 
| 1149 | val table2 = Data.ml_statistics_table | |
| 65629 | 1150 | |
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1151 | val where_log_name = | 
| 65699 | 1152 | Data.log_name(table1).where_equal(log_name) + " AND " + | 
| 65701 | 1153 | Data.session_name(table1) + " <> ''" | 
| 65621 | 1154 | val where = | 
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1155 | if (session_names.isEmpty) where_log_name | 
| 65804 | 1156 | else where_log_name + " AND " + SQL.member(Data.session_name(table1).ident, session_names) | 
| 65629 | 1157 | |
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1158 | val columns1 = table1.columns.tail.map(_.apply(table1)) | 
| 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1159 | val (columns, from) = | 
| 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1160 |         if (ml_statistics) {
 | 
| 65694 | 1161 | val columns = columns1 ::: List(Data.ml_statistics(table2)) | 
| 65668 | 1162 | val join = | 
| 65775 | 1163 | table1 + SQL.join_outer + table2 + " ON " + | 
| 65738 | 1164 | Data.log_name(table1) + " = " + Data.log_name(table2) + " AND " + | 
| 1165 | Data.session_name(table1) + " = " + Data.session_name(table2) | |
| 65668 | 1166 | (columns, SQL.enclose(join)) | 
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1167 | } | 
| 65695 | 1168 | else (columns1, table1.ident) | 
| 65645 
2c704ae04db1
clarified database layout: bulky ml_statistics are stored/retrieved separately;
 wenzelm parents: 
65643diff
changeset | 1169 | |
| 65621 | 1170 | val sessions = | 
| 65698 | 1171 | db.using_statement(SQL.select(columns) + from + " " + where)(stmt => | 
| 65621 | 1172 |         {
 | 
| 65740 | 1173 | stmt.execute_query().iterator(res => | 
| 65621 | 1174 |           {
 | 
| 65740 | 1175 | val session_name = res.string(Data.session_name) | 
| 65626 | 1176 | val session_entry = | 
| 1177 | Session_Entry( | |
| 65740 | 1178 | chapter = res.string(Data.chapter), | 
| 1179 | groups = split_lines(res.string(Data.groups)), | |
| 1180 | threads = res.get_int(Data.threads), | |
| 65741 | 1181 | timing = res.timing(Data.timing_elapsed, Data.timing_cpu, Data.timing_gc), | 
| 65626 | 1182 | ml_timing = | 
| 65741 | 1183 | res.timing(Data.ml_timing_elapsed, Data.ml_timing_cpu, Data.ml_timing_gc), | 
| 66913 | 1184 | sources = res.get_string(Data.sources), | 
| 65740 | 1185 | heap_size = res.get_long(Data.heap_size), | 
| 1186 | status = res.get_string(Data.status).map(Session_Status.withName(_)), | |
| 68018 | 1187 | errors = uncompress_errors(res.bytes(Data.errors), cache = xz_cache), | 
| 65629 | 1188 | ml_statistics = | 
| 68018 | 1189 |                   if (ml_statistics) {
 | 
| 1190 | Properties.uncompress( | |
| 1191 | res.bytes(Data.ml_statistics), cache = xz_cache, Some(xml_cache)) | |
| 1192 | } | |
| 65629 | 1193 | else Nil) | 
| 65626 | 1194 | session_name -> session_entry | 
| 65621 | 1195 | }).toMap | 
| 1196 | }) | |
| 1197 | Build_Info(sessions) | |
| 1198 | } | |
| 65595 | 1199 | } | 
| 64045 | 1200 | } |