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