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