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