author | wenzelm |
Sat, 08 Oct 2016 22:08:31 +0200 | |
changeset 64116 | 6cfd429a4296 |
parent 64111 | b2290b9d0175 |
child 64117 | c2b41b073d8a |
permissions | -rw-r--r-- |
64045 | 1 |
/* Title: Pure/Tools/build_log.scala |
2 |
Author: Makarius |
|
3 |
||
64110 | 4 |
Build log parsing for current and historic formats. |
64045 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
64100 | 10 |
import java.io.{File => JFile} |
11 |
import java.time.ZoneId |
|
64110 | 12 |
import java.time.format.{DateTimeFormatter, DateTimeParseException} |
64096 | 13 |
import java.util.Locale |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
14 |
|
64054 | 15 |
import scala.collection.mutable |
16 |
import scala.util.matching.Regex |
|
17 |
||
18 |
||
64045 | 19 |
object Build_Log |
20 |
{ |
|
64101 | 21 |
/** directory content **/ |
22 |
||
23 |
def is_log(file: JFile): Boolean = |
|
24 |
List(".log", ".log.gz", ".log.xz").exists(ext => file.getName.endsWith(ext)) |
|
25 |
||
26 |
def isatest_files(dir: Path): List[JFile] = |
|
27 |
File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("isatest-makeall-")) |
|
28 |
||
29 |
def afp_test_files(dir: Path): List[JFile] = |
|
30 |
File.find_files(dir.file, file => is_log(file) && file.getName.startsWith("afp-test-devel-")) |
|
31 |
||
32 |
||
33 |
||
64081 | 34 |
/** settings **/ |
64080 | 35 |
|
64081 | 36 |
object Settings |
37 |
{ |
|
38 |
val build_settings = List("ISABELLE_BUILD_OPTIONS") |
|
39 |
val ml_settings = List("ML_PLATFORM", "ML_HOME", "ML_SYSTEM", "ML_OPTIONS") |
|
40 |
val all_settings = build_settings ::: ml_settings |
|
41 |
||
42 |
type Entry = (String, String) |
|
43 |
type T = List[Entry] |
|
64080 | 44 |
|
64081 | 45 |
object Entry |
46 |
{ |
|
47 |
def unapply(s: String): Option[Entry] = |
|
48 |
s.indexOf('=') match { |
|
49 |
case -1 => None |
|
50 |
case i => |
|
51 |
val a = s.substring(0, i) |
|
52 |
val b = Library.perhaps_unquote(s.substring(i + 1)) |
|
53 |
Some((a, b)) |
|
54 |
} |
|
55 |
def apply(a: String, b: String): String = a + "=" + quote(b) |
|
56 |
def getenv(a: String): String = apply(a, Isabelle_System.getenv(a)) |
|
57 |
} |
|
64080 | 58 |
|
64081 | 59 |
def show(): String = |
60 |
cat_lines( |
|
61 |
build_settings.map(Entry.getenv(_)) ::: List("") ::: ml_settings.map(Entry.getenv(_))) |
|
64080 | 62 |
} |
63 |
||
64 |
||
64100 | 65 |
|
64062 | 66 |
/** log file **/ |
64045 | 67 |
|
64062 | 68 |
object Log_File |
69 |
{ |
|
70 |
def apply(name: String, lines: List[String]): Log_File = |
|
71 |
new Log_File(name, lines) |
|
72 |
||
73 |
def apply(name: String, text: String): Log_File = |
|
64063 | 74 |
Log_File(name, Library.trim_split_lines(text)) |
64090 | 75 |
|
76 |
def apply(file: JFile): Log_File = |
|
77 |
{ |
|
78 |
val name = file.getName |
|
79 |
val (base_name, text) = |
|
80 |
Library.try_unsuffix(".gz", name) match { |
|
81 |
case Some(base_name) => (base_name, File.read_gzip(file)) |
|
82 |
case None => |
|
83 |
Library.try_unsuffix(".xz", name) match { |
|
84 |
case Some(base_name) => (base_name, File.read_xz(file)) |
|
85 |
case None => (name, File.read(file)) |
|
86 |
} |
|
87 |
} |
|
88 |
apply(base_name, text) |
|
89 |
} |
|
90 |
||
91 |
def apply(path: Path): Log_File = apply(path.file) |
|
64101 | 92 |
|
64110 | 93 |
|
94 |
/* date format */ |
|
95 |
||
64101 | 96 |
val Date_Format = |
97 |
{ |
|
98 |
val fmts = |
|
99 |
Date.Formatter.variants( |
|
64116 | 100 |
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
|
101 |
List(Locale.ENGLISH, Locale.GERMAN)) ::: |
64110 | 102 |
List( |
103 |
DateTimeFormatter.RFC_1123_DATE_TIME, |
|
104 |
Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(ZoneId.of("Europe/Berlin"))) |
|
64101 | 105 |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
106 |
def tune_timezone(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
107 |
s match { |
64101 | 108 |
case "CET" | "MET" => "GMT+1" |
109 |
case "CEST" | "MEST" => "GMT+2" |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
110 |
case "EST" => "Europe/Berlin" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
111 |
case _ => s |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
112 |
} |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
113 |
def tune_weekday(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
114 |
s match { |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
115 |
case "Die" => "Di" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
116 |
case "Mit" => "Mi" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
117 |
case "Don" => "Do" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
118 |
case "Fre" => "Fr" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
119 |
case "Sam" => "Sa" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
120 |
case "Son" => "So" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
121 |
case _ => s |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
122 |
} |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
123 |
|
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
124 |
def tune(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
125 |
Word.implode( |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
126 |
Word.explode(s) match { |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
case Nil => Nil |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
130 |
} |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
131 |
) |
64101 | 132 |
|
133 |
Date.Format.make(fmts, tune) |
|
134 |
} |
|
64102 | 135 |
} |
136 |
||
137 |
class Log_File private(val name: String, val lines: List[String]) |
|
138 |
{ |
|
139 |
log_file => |
|
140 |
||
141 |
override def toString: String = name |
|
142 |
||
143 |
def text: String = cat_lines(lines) |
|
144 |
||
145 |
def err(msg: String): Nothing = |
|
146 |
error("Error in log file " + quote(name) + ": " + msg) |
|
147 |
||
148 |
||
149 |
/* date format */ |
|
64101 | 150 |
|
151 |
object Strict_Date |
|
152 |
{ |
|
153 |
def unapply(s: String): Some[Date] = |
|
64102 | 154 |
try { Some(Log_File.Date_Format.parse(s)) } |
64101 | 155 |
catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) } |
156 |
} |
|
157 |
||
158 |
||
64062 | 159 |
/* inlined content */ |
160 |
||
161 |
def find[A](f: String => Option[A]): Option[A] = |
|
162 |
lines.iterator.map(f).find(_.isDefined).map(_.get) |
|
163 |
||
164 |
def find_match(regex: Regex): Option[String] = |
|
165 |
lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1). |
|
166 |
map(res => res.get.head) |
|
167 |
||
168 |
||
169 |
/* settings */ |
|
170 |
||
64091 | 171 |
def get_setting(a: String): Option[Settings.Entry] = |
172 |
lines.find(_.startsWith(a + "=")) match { |
|
173 |
case Some(line) => Settings.Entry.unapply(line) |
|
174 |
case None => None |
|
175 |
} |
|
64045 | 176 |
|
64091 | 177 |
def get_settings(as: List[String]): Settings.T = |
178 |
for { a <- as; entry <- get_setting(a) } yield entry |
|
64062 | 179 |
|
180 |
||
181 |
/* properties (YXML) */ |
|
182 |
||
183 |
val xml_cache = new XML.Cache() |
|
184 |
||
185 |
def parse_props(text: String): Properties.T = |
|
186 |
xml_cache.props(XML.Decode.properties(YXML.parse_body(text))) |
|
187 |
||
188 |
def filter_props(prefix: String): List[Properties.T] = |
|
189 |
for (line <- lines; s <- Library.try_unprefix(prefix, line)) yield parse_props(s) |
|
64045 | 190 |
|
64062 | 191 |
def find_line(prefix: String): Option[String] = |
192 |
find(Library.try_unprefix(prefix, _)) |
|
193 |
||
194 |
def find_props(prefix: String): Option[Properties.T] = |
|
195 |
find_line(prefix).map(parse_props(_)) |
|
196 |
||
197 |
||
198 |
/* parse various formats */ |
|
199 |
||
64105 | 200 |
def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file) |
201 |
||
202 |
def parse_build_info(): Build_Info = Build_Log.parse_build_info(log_file) |
|
203 |
||
64082 | 204 |
def parse_session_info( |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
205 |
default_name: String = "", |
64082 | 206 |
command_timings: Boolean = false, |
207 |
ml_statistics: Boolean = false, |
|
208 |
task_statistics: Boolean = false): Session_Info = |
|
209 |
Build_Log.parse_session_info( |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
210 |
log_file, default_name, command_timings, ml_statistics, task_statistics) |
64045 | 211 |
} |
212 |
||
213 |
||
64098 | 214 |
|
64105 | 215 |
/** meta info **/ |
64045 | 216 |
|
64099 | 217 |
object Field |
64045 | 218 |
{ |
64108 | 219 |
val build_engine = "build_engine" |
64099 | 220 |
val build_host = "build_host" |
221 |
val build_start = "build_start" |
|
222 |
val build_end = "build_end" |
|
223 |
val isabelle_version = "isabelle_version" |
|
224 |
val afp_version = "afp_version" |
|
64045 | 225 |
} |
64054 | 226 |
|
64108 | 227 |
object Meta_Info |
64099 | 228 |
{ |
64108 | 229 |
val empty: Meta_Info = Meta_Info(Nil, Nil) |
64099 | 230 |
} |
64098 | 231 |
|
64108 | 232 |
sealed case class Meta_Info(props: Properties.T, settings: List[(String, String)]) |
64103 | 233 |
{ |
234 |
def is_empty: Boolean = props.isEmpty && settings.isEmpty |
|
235 |
} |
|
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
236 |
|
64095 | 237 |
object Isatest |
238 |
{ |
|
64108 | 239 |
val engine = "isatest" |
64109 | 240 |
val Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""") |
241 |
val End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""") |
|
64095 | 242 |
val Isabelle_Version = new Regex("""^Isabelle version: (\S+)$""") |
243 |
val No_AFP_Version = new Regex("""$.""") |
|
244 |
} |
|
245 |
||
64109 | 246 |
object AFP_Test |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
247 |
{ |
64108 | 248 |
val engine = "afp-test" |
64109 | 249 |
val Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""") |
250 |
val Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""") |
|
251 |
val End = new Regex("""^End test on (.+), .+, elapsed time:.*$""") |
|
64087 | 252 |
val Isabelle_Version = new Regex("""^Isabelle version: .* -- hg id (\S+)$""") |
253 |
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
|
254 |
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
|
255 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
256 |
|
64110 | 257 |
object Jenkins |
258 |
{ |
|
259 |
val engine = "jenkins" |
|
260 |
val Start = new Regex("""^Started .*$""") |
|
261 |
val Start_Date = new Regex("""^Build started at (.+)$""") |
|
262 |
val No_End = new Regex("""$.""") |
|
263 |
val Isabelle_Version = new Regex("""^Isabelle id (\S+)$""") |
|
264 |
val AFP_Version = new Regex("""^AFP id (\S+)$""") |
|
265 |
val CONFIGURATION = "=== CONFIGURATION ===" |
|
266 |
val BUILD = "=== BUILD ===" |
|
267 |
val FINISHED = "Finished: " |
|
268 |
} |
|
269 |
||
64105 | 270 |
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
|
271 |
{ |
64108 | 272 |
def parse(engine: String, host: String, start: Date, |
64109 | 273 |
End: Regex, Isabelle_Version: Regex, AFP_Version: Regex): Meta_Info = |
64091 | 274 |
{ |
64108 | 275 |
val build_engine = if (engine == "") Nil else List(Field.build_engine -> engine) |
276 |
val build_host = if (host == "") Nil else List(Field.build_host -> host) |
|
277 |
||
278 |
val start_date = List(Field.build_start -> start.toString) |
|
64091 | 279 |
val end_date = |
280 |
log_file.lines.last match { |
|
64109 | 281 |
case End(log_file.Strict_Date(end_date)) => |
64091 | 282 |
List(Field.build_end -> end_date.toString) |
283 |
case _ => Nil |
|
284 |
} |
|
285 |
||
286 |
val isabelle_version = |
|
64095 | 287 |
log_file.find_match(Isabelle_Version).map(Field.isabelle_version -> _) |
64091 | 288 |
val afp_version = |
64095 | 289 |
log_file.find_match(AFP_Version).map(Field.afp_version -> _) |
64062 | 290 |
|
64108 | 291 |
Meta_Info(build_engine ::: build_host ::: |
292 |
start_date ::: end_date ::: isabelle_version.toList ::: afp_version.toList, |
|
64091 | 293 |
log_file.get_settings(Settings.all_settings)) |
294 |
} |
|
295 |
||
296 |
log_file.lines match { |
|
64109 | 297 |
case Isatest.Start(log_file.Strict_Date(start), host) :: _ => |
298 |
parse(Isatest.engine, host, start, Isatest.End, |
|
64108 | 299 |
Isatest.Isabelle_Version, Isatest.No_AFP_Version) |
64099 | 300 |
|
64109 | 301 |
case AFP_Test.Start(log_file.Strict_Date(start), host) :: _ => |
302 |
parse(AFP_Test.engine, host, start, AFP_Test.End, |
|
303 |
AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) |
|
64099 | 304 |
|
64109 | 305 |
case AFP_Test.Start_Old(log_file.Strict_Date(start)) :: _ => |
306 |
parse(AFP_Test.engine, "", start, AFP_Test.End, |
|
307 |
AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) |
|
64099 | 308 |
|
64110 | 309 |
case Jenkins.Start() :: _ |
310 |
if log_file.lines.contains(Jenkins.CONFIGURATION) || |
|
311 |
log_file.lines.last.startsWith(Jenkins.FINISHED) => |
|
312 |
log_file.lines.dropWhile(_ != Jenkins.BUILD) match { |
|
313 |
case Jenkins.BUILD :: _ :: Jenkins.Start_Date(log_file.Strict_Date(start)) :: _ => |
|
64111 | 314 |
parse(Jenkins.engine, "", start.to(ZoneId.of("Europe/Berlin")), Jenkins.No_End, |
64110 | 315 |
Jenkins.Isabelle_Version, Jenkins.AFP_Version) |
316 |
case _ => Meta_Info.empty |
|
317 |
} |
|
318 |
||
64105 | 319 |
case line :: _ if line.startsWith("\0") => Meta_Info.empty |
64109 | 320 |
case List(Isatest.End(_)) => Meta_Info.empty |
321 |
case _ :: AFP_Test.Bad_Init() :: _ => Meta_Info.empty |
|
64105 | 322 |
case Nil => Meta_Info.empty |
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
323 |
|
64110 | 324 |
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
|
325 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
326 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
327 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
328 |
|
64098 | 329 |
|
330 |
/** build info: produced by isabelle build **/ |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
331 |
|
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
332 |
object Session_Status extends Enumeration |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
333 |
{ |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
334 |
val EXISTING = Value("existing") |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
335 |
val FINISHED = Value("finished") |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
336 |
val FAILED = Value("failed") |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
337 |
val CANCELLED = Value("cancelled") |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
338 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
339 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
340 |
sealed case class Session_Entry( |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
341 |
chapter: String, |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
342 |
groups: List[String], |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
343 |
threads: Option[Int], |
64089 | 344 |
timing: Timing, |
345 |
ml_timing: Timing, |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
346 |
status: Session_Status.Value) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
347 |
{ |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
348 |
def finished: Boolean = status == Session_Status.FINISHED |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
349 |
} |
64054 | 350 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
351 |
sealed case class Build_Info(sessions: Map[String, Session_Entry]) |
64054 | 352 |
{ |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
353 |
def session(name: String): Session_Entry = sessions(name) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
354 |
def get_session(name: String): Option[Session_Entry] = sessions.get(name) |
64054 | 355 |
|
64089 | 356 |
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
|
357 |
get_session(name) match { |
64089 | 358 |
case Some(entry) => f(entry) |
359 |
case None => x |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
360 |
} |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
361 |
|
64089 | 362 |
def finished(name: String): Boolean = get_default(name, _.finished, false) |
363 |
def timing(name: String): Timing = get_default(name, _.timing, Timing.zero) |
|
364 |
def ml_timing(name: String): Timing = get_default(name, _.ml_timing, Timing.zero) |
|
64054 | 365 |
} |
366 |
||
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
367 |
private def parse_build_info(log_file: Log_File): Build_Info = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
368 |
{ |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
369 |
object Chapter_Name |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
370 |
{ |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
371 |
def unapply(s: String): Some[(String, String)] = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
372 |
space_explode('/', s) match { |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
373 |
case List(chapter, name) => Some((chapter, name)) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
374 |
case _ => Some(("", s)) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
375 |
} |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
376 |
} |
64054 | 377 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
378 |
val Session_No_Groups = new Regex("""^Session (\S+)$""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
379 |
val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
380 |
val Session_Finished1 = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
381 |
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
|
382 |
val Session_Finished2 = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
383 |
new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
384 |
val Session_Timing = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
385 |
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
|
386 |
val Session_Started = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""") |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
387 |
val Session_Failed = new Regex("""^(\S+) FAILED""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
388 |
val Session_Cancelled = new Regex("""^(\S+) CANCELLED""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
389 |
|
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
390 |
var chapter = Map.empty[String, String] |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
391 |
var groups = Map.empty[String, List[String]] |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
392 |
var threads = Map.empty[String, Int] |
64054 | 393 |
var timing = Map.empty[String, Timing] |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
394 |
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
|
395 |
var started = Set.empty[String] |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
396 |
var failed = Set.empty[String] |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
397 |
var cancelled = Set.empty[String] |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
398 |
def all_sessions: Set[String] = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
399 |
chapter.keySet ++ groups.keySet ++ threads.keySet ++ |
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
|
400 |
timing.keySet ++ ml_timing.keySet ++ failed ++ cancelled ++ started |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
401 |
|
64054 | 402 |
|
64062 | 403 |
for (line <- log_file.lines) { |
64054 | 404 |
line match { |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
405 |
case Session_No_Groups(Chapter_Name(chapt, name)) => |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
406 |
chapter += (name -> chapt) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
407 |
groups += (name -> Nil) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
408 |
case Session_Groups(Chapter_Name(chapt, name), grps) => |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
409 |
chapter += (name -> chapt) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
410 |
groups += (name -> Word.explode(grps)) |
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
|
411 |
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
|
412 |
started += name |
64054 | 413 |
case Session_Finished1(name, |
414 |
Value.Int(e1), Value.Int(e2), Value.Int(e3), |
|
415 |
Value.Int(c1), Value.Int(c2), Value.Int(c3)) => |
|
416 |
val elapsed = Time.hms(e1, e2, e3) |
|
417 |
val cpu = Time.hms(c1, c2, c3) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
418 |
timing += (name -> Timing(elapsed, cpu, Time.zero)) |
64054 | 419 |
case Session_Finished2(name, |
420 |
Value.Int(e1), Value.Int(e2), Value.Int(e3)) => |
|
421 |
val elapsed = Time.hms(e1, e2, e3) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
422 |
timing += (name -> Timing(elapsed, Time.zero, Time.zero)) |
64054 | 423 |
case Session_Timing(name, |
424 |
Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) => |
|
425 |
val elapsed = Time.seconds(e) |
|
426 |
val cpu = Time.seconds(c) |
|
427 |
val gc = Time.seconds(g) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
428 |
ml_timing += (name -> Timing(elapsed, cpu, gc)) |
64054 | 429 |
threads += (name -> t) |
430 |
case _ => |
|
431 |
} |
|
432 |
} |
|
433 |
||
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
434 |
val sessions = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
435 |
Map( |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
436 |
(for (name <- all_sessions.toList) yield { |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
437 |
val status = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
438 |
if (failed(name)) Session_Status.FAILED |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
else if (started(name)) Session_Status.FAILED |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
443 |
else Session_Status.EXISTING |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
444 |
val entry = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
445 |
Session_Entry( |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
446 |
chapter.getOrElse(name, ""), |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
447 |
groups.getOrElse(name, Nil), |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
448 |
threads.get(name), |
64089 | 449 |
timing.getOrElse(name, Timing.zero), |
450 |
ml_timing.getOrElse(name, Timing.zero), |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
451 |
status) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
452 |
(name -> entry) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
453 |
}):_*) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
454 |
Build_Info(sessions) |
64054 | 455 |
} |
64099 | 456 |
|
457 |
||
458 |
||
459 |
/** session info: produced by "isabelle build" **/ |
|
460 |
||
461 |
sealed case class Session_Info( |
|
462 |
session_name: String, |
|
463 |
session_timing: Properties.T, |
|
464 |
command_timings: List[Properties.T], |
|
465 |
ml_statistics: List[Properties.T], |
|
466 |
task_statistics: List[Properties.T]) |
|
467 |
||
468 |
private def parse_session_info( |
|
469 |
log_file: Log_File, |
|
470 |
default_name: String, |
|
471 |
command_timings: Boolean, |
|
472 |
ml_statistics: Boolean, |
|
473 |
task_statistics: Boolean): Session_Info = |
|
474 |
{ |
|
475 |
val xml_cache = new XML.Cache() |
|
476 |
||
477 |
val session_name = |
|
478 |
log_file.find_line("\fSession.name = ") match { |
|
479 |
case None => default_name |
|
480 |
case Some(name) if default_name == "" || default_name == name => name |
|
481 |
case Some(name) => log_file.err("log from different session " + quote(name)) |
|
482 |
} |
|
483 |
val session_timing = log_file.find_props("\fTiming = ") getOrElse Nil |
|
484 |
val command_timings_ = |
|
485 |
if (command_timings) log_file.filter_props("\fcommand_timing = ") else Nil |
|
486 |
val ml_statistics_ = |
|
487 |
if (ml_statistics) log_file.filter_props("\fML_statistics = ") else Nil |
|
488 |
val task_statistics_ = |
|
489 |
if (task_statistics) log_file.filter_props("\ftask_statistics = ") else Nil |
|
490 |
||
491 |
Session_Info(session_name, session_timing, command_timings_, ml_statistics_, task_statistics_) |
|
492 |
} |
|
64045 | 493 |
} |