author | wenzelm |
Sat, 25 Nov 2023 20:41:18 +0100 | |
changeset 79064 | a54be9630ef8 |
parent 79063 | ad7f485195df |
child 79065 | 07799c394b6d |
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} |
64110 | 11 |
import java.time.format.{DateTimeFormatter, DateTimeParseException} |
64096 | 12 |
import java.util.Locale |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
13 |
|
65600 | 14 |
import scala.collection.immutable.SortedMap |
64054 | 15 |
import scala.collection.mutable |
16 |
import scala.util.matching.Regex |
|
17 |
||
18 |
||
75393 | 19 |
object Build_Log { |
64298 | 20 |
/** content **/ |
64101 | 21 |
|
64298 | 22 |
/* properties */ |
64150 | 23 |
|
75393 | 24 |
object Prop { |
65624 | 25 |
val build_tags = SQL.Column.string("build_tags") // lines |
26 |
val build_args = SQL.Column.string("build_args") // lines |
|
65591 | 27 |
val build_group_id = SQL.Column.string("build_group_id") |
28 |
val build_id = SQL.Column.string("build_id") |
|
29 |
val build_engine = SQL.Column.string("build_engine") |
|
30 |
val build_host = SQL.Column.string("build_host") |
|
31 |
val build_start = SQL.Column.date("build_start") |
|
32 |
val build_end = SQL.Column.date("build_end") |
|
33 |
val isabelle_version = SQL.Column.string("isabelle_version") |
|
34 |
val afp_version = SQL.Column.string("afp_version") |
|
35 |
||
65611 | 36 |
val all_props: List[SQL.Column] = |
65591 | 37 |
List(build_tags, build_args, build_group_id, build_id, build_engine, |
38 |
build_host, build_start, build_end, isabelle_version, afp_version) |
|
64298 | 39 |
} |
64150 | 40 |
|
41 |
||
64298 | 42 |
/* settings */ |
64080 | 43 |
|
75393 | 44 |
object Settings { |
65611 | 45 |
val ISABELLE_BUILD_OPTIONS = SQL.Column.string("ISABELLE_BUILD_OPTIONS") |
46 |
val ML_PLATFORM = SQL.Column.string("ML_PLATFORM") |
|
47 |
val ML_HOME = SQL.Column.string("ML_HOME") |
|
48 |
val ML_SYSTEM = SQL.Column.string("ML_SYSTEM") |
|
49 |
val ML_OPTIONS = SQL.Column.string("ML_OPTIONS") |
|
50 |
||
51 |
val ml_settings = List(ML_PLATFORM, ML_HOME, ML_SYSTEM, ML_OPTIONS) |
|
52 |
val all_settings = ISABELLE_BUILD_OPTIONS :: ml_settings |
|
64081 | 53 |
|
54 |
type Entry = (String, String) |
|
55 |
type T = List[Entry] |
|
64080 | 56 |
|
75393 | 57 |
object Entry { |
64081 | 58 |
def unapply(s: String): Option[Entry] = |
73712 | 59 |
for { (a, b) <- Properties.Eq.unapply(s) } |
60 |
yield (a, Library.perhaps_unquote(b)) |
|
73713 | 61 |
def getenv(a: String): String = |
73715
bf51c23f3f99
clarified signature -- avoid odd warning about scala/bug#6675;
wenzelm
parents:
73713
diff
changeset
|
62 |
Properties.Eq(a, quote(Isabelle_System.getenv(a))) |
64081 | 63 |
} |
64080 | 64 |
|
71992 | 65 |
def show(): String = |
64081 | 66 |
cat_lines( |
71992 | 67 |
List(Entry.getenv("ISABELLE_TOOL_JAVA_OPTIONS"), |
68 |
Entry.getenv(ISABELLE_BUILD_OPTIONS.name), "") ::: |
|
65611 | 69 |
ml_settings.map(c => Entry.getenv(c.name))) |
64080 | 70 |
} |
71 |
||
72 |
||
64298 | 73 |
/* file names */ |
74 |
||
75 |
def log_date(date: Date): String = |
|
76 |
String.format(Locale.ROOT, "%s.%05d", |
|
77 |
DateTimeFormatter.ofPattern("yyyy-MM-dd").format(date.rep), |
|
71163 | 78 |
java.lang.Long.valueOf((date.time - date.midnight.time).ms / 1000)) |
64298 | 79 |
|
80 |
def log_subdir(date: Date): Path = |
|
81 |
Path.explode("log") + Path.explode(date.rep.getYear.toString) |
|
82 |
||
83 |
def log_filename(engine: String, date: Date, more: List[String] = Nil): Path = |
|
84 |
Path.explode((engine :: log_date(date) :: more).mkString("", "_", ".log")) |
|
85 |
||
86 |
||
64100 | 87 |
|
64062 | 88 |
/** log file **/ |
64045 | 89 |
|
64155 | 90 |
def print_date(date: Date): String = Log_File.Date_Format(date) |
91 |
||
75393 | 92 |
object Log_File { |
65607 | 93 |
/* log file */ |
94 |
||
78856 | 95 |
val all_suffixes: List[String] = List(".log", ".log.gz", ".log.xz", ".gz", ".xz") |
96 |
||
75393 | 97 |
def plain_name(name: String): String = { |
78856 | 98 |
all_suffixes.find(name.endsWith) match { |
65609 | 99 |
case Some(s) => Library.try_unsuffix(s, name).get |
100 |
case None => name |
|
101 |
} |
|
102 |
} |
|
77748 | 103 |
def plain_name(file: JFile): String = plain_name(file.getName) |
65609 | 104 |
|
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
105 |
def apply(name: String, lines: List[String], cache: XML.Cache = XML.Cache.none): Log_File = |
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
106 |
new Log_File(plain_name(name), lines.map(s => cache.string(Library.trim_line(s))), cache) |
64062 | 107 |
|
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
108 |
def read(file: JFile, cache: XML.Cache = XML.Cache.none): Log_File = { |
64090 | 109 |
val name = file.getName |
65609 | 110 |
val text = |
75906
2167b9e3157a
clarified signature: support for adhoc file types;
wenzelm
parents:
75776
diff
changeset
|
111 |
if (File.is_gz(name)) File.read_gzip(file) |
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
112 |
else if (File.is_xz(name)) Bytes.read(file).uncompress_xz(cache = cache.compress).text |
65609 | 113 |
else File.read(file) |
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
114 |
apply(name, Library.trim_split_lines(text), cache = cache) |
64090 | 115 |
} |
116 |
||
64110 | 117 |
|
65607 | 118 |
/* log file collections */ |
119 |
||
78856 | 120 |
val log_prefixes: List[String] = |
121 |
List(Build_History.log_prefix, Identify.log_prefix, Identify.log_prefix2, |
|
122 |
Isatest.log_prefix, AFP_Test.log_prefix) |
|
123 |
||
124 |
val log_suffixes: List[String] = List(".log", ".log.gz", ".log.xz") |
|
125 |
||
65607 | 126 |
def is_log(file: JFile, |
78856 | 127 |
prefixes: List[String] = log_prefixes, |
128 |
suffixes: List[String] = log_suffixes |
|
75393 | 129 |
): Boolean = { |
65607 | 130 |
val name = file.getName |
65639 | 131 |
|
71621 | 132 |
prefixes.exists(name.startsWith) && |
133 |
suffixes.exists(name.endsWith) && |
|
65639 | 134 |
name != "isatest.log" && |
135 |
name != "afp-test.log" && |
|
136 |
name != "main.log" |
|
65607 | 137 |
} |
138 |
||
78857 | 139 |
def find_files(starts: List[JFile]): List[JFile] = |
140 |
starts.flatMap(start => File.find_files(start, pred = is_log(_), follow_links = true)) |
|
141 |
.sortBy(plain_name) |
|
142 |
||
65607 | 143 |
|
64110 | 144 |
/* date format */ |
145 |
||
75393 | 146 |
val Date_Format = { |
64101 | 147 |
val fmts = |
148 |
Date.Formatter.variants( |
|
64116 | 149 |
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
|
150 |
List(Locale.ENGLISH, Locale.GERMAN)) ::: |
64110 | 151 |
List( |
152 |
DateTimeFormatter.RFC_1123_DATE_TIME, |
|
69980 | 153 |
Date.Formatter.pattern("EEE MMM d HH:mm:ss yyyy").withZone(Date.timezone_berlin)) |
64101 | 154 |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
155 |
def tune_timezone(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
156 |
s match { |
64101 | 157 |
case "CET" | "MET" => "GMT+1" |
158 |
case "CEST" | "MEST" => "GMT+2" |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
159 |
case "EST" => "Europe/Berlin" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
160 |
case _ => s |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
161 |
} |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
162 |
def tune_weekday(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
163 |
s match { |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
164 |
case "Die" => "Di" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
165 |
case "Mit" => "Mi" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
166 |
case "Don" => "Do" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
167 |
case "Fre" => "Fr" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
168 |
case "Sam" => "Sa" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
169 |
case "Son" => "So" |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
170 |
case _ => s |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
171 |
} |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
172 |
|
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
173 |
def tune(s: String): String = |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
174 |
Word.implode( |
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
175 |
Word.explode(s) match { |
71621 | 176 |
case a :: "M\uFFFDr" :: bs => tune_weekday(a) :: "Mär" :: bs.map(tune_timezone) |
177 |
case a :: bs => tune_weekday(a) :: bs.map(tune_timezone) |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
178 |
case Nil => Nil |
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 |
) |
64101 | 181 |
|
182 |
Date.Format.make(fmts, tune) |
|
183 |
} |
|
64102 | 184 |
} |
185 |
||
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
186 |
class Log_File private( |
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
187 |
val name: String, |
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
188 |
val lines: List[String], |
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
189 |
val cache: XML.Cache |
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
190 |
) { |
64102 | 191 |
log_file => |
192 |
||
193 |
override def toString: String = name |
|
194 |
||
195 |
def text: String = cat_lines(lines) |
|
196 |
||
197 |
def err(msg: String): Nothing = |
|
77750 | 198 |
error("Bad log file " + quote(name) + ": " + msg) |
64102 | 199 |
|
200 |
||
201 |
/* date format */ |
|
64101 | 202 |
|
75393 | 203 |
object Strict_Date { |
64101 | 204 |
def unapply(s: String): Some[Date] = |
64102 | 205 |
try { Some(Log_File.Date_Format.parse(s)) } |
64101 | 206 |
catch { case exn: DateTimeParseException => log_file.err(exn.getMessage) } |
207 |
} |
|
208 |
||
209 |
||
71620 | 210 |
/* inlined text */ |
64062 | 211 |
|
71620 | 212 |
def filter(Marker: Protocol_Message.Marker): List[String] = |
78592 | 213 |
for (case Marker(text) <- lines) yield text |
64062 | 214 |
|
71620 | 215 |
def find(Marker: Protocol_Message.Marker): Option[String] = |
216 |
lines.collectFirst({ case Marker(text) => text }) |
|
64196
6688b9cd443b
more robust wrt. old versions that use clear-text properties (e.g. Timing in build_history_base);
wenzelm
parents:
64193
diff
changeset
|
217 |
|
65684 | 218 |
def find_match(regexes: List[Regex]): Option[String] = |
219 |
regexes match { |
|
220 |
case Nil => None |
|
221 |
case regex :: rest => |
|
222 |
lines.iterator.map(regex.unapplySeq(_)).find(res => res.isDefined && res.get.length == 1). |
|
223 |
map(res => res.get.head) orElse find_match(rest) |
|
224 |
} |
|
64062 | 225 |
|
226 |
||
227 |
/* settings */ |
|
228 |
||
73715
bf51c23f3f99
clarified signature -- avoid odd warning about scala/bug#6675;
wenzelm
parents:
73713
diff
changeset
|
229 |
def get_setting(name: String): Option[Settings.Entry] = |
bf51c23f3f99
clarified signature -- avoid odd warning about scala/bug#6675;
wenzelm
parents:
73713
diff
changeset
|
230 |
lines.collectFirst({ case Settings.Entry(a, b) if a == name => a -> b }) |
64045 | 231 |
|
65611 | 232 |
def get_all_settings: Settings.T = |
233 |
for { c <- Settings.all_settings; entry <- get_setting(c.name) } |
|
234 |
yield entry |
|
64062 | 235 |
|
236 |
||
237 |
/* properties (YXML) */ |
|
238 |
||
239 |
def parse_props(text: String): Properties.T = |
|
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
240 |
try { cache.props(XML.Decode.properties(YXML.parse_body(text, cache = cache))) } |
66046 | 241 |
catch { case _: XML.Error => log_file.err("malformed properties") } |
64062 | 242 |
|
71620 | 243 |
def filter_props(marker: Protocol_Message.Marker): List[Properties.T] = |
244 |
for (text <- filter(marker) if YXML.detect(text)) yield parse_props(text) |
|
64062 | 245 |
|
71620 | 246 |
def find_props(marker: Protocol_Message.Marker): Option[Properties.T] = |
247 |
for (text <- find(marker) if YXML.detect(text)) yield parse_props(text) |
|
64062 | 248 |
|
249 |
||
250 |
/* parse various formats */ |
|
251 |
||
64105 | 252 |
def parse_meta_info(): Meta_Info = Build_Log.parse_meta_info(log_file) |
253 |
||
65646 | 254 |
def parse_build_info(ml_statistics: Boolean = false): Build_Info = |
255 |
Build_Log.parse_build_info(log_file, ml_statistics) |
|
64105 | 256 |
|
64082 | 257 |
def parse_session_info( |
258 |
command_timings: Boolean = false, |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66863
diff
changeset
|
259 |
theory_timings: Boolean = false, |
64082 | 260 |
ml_statistics: Boolean = false, |
261 |
task_statistics: Boolean = false): Session_Info = |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66863
diff
changeset
|
262 |
Build_Log.parse_session_info( |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66863
diff
changeset
|
263 |
log_file, command_timings, theory_timings, ml_statistics, task_statistics) |
64045 | 264 |
} |
265 |
||
266 |
||
64098 | 267 |
|
75518
cb4af8c6152f
clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents:
75394
diff
changeset
|
268 |
/** digested meta info: produced by Admin/build_other in log.xz file **/ |
64045 | 269 |
|
75393 | 270 |
object Meta_Info { |
64108 | 271 |
val empty: Meta_Info = Meta_Info(Nil, Nil) |
64099 | 272 |
} |
64098 | 273 |
|
75393 | 274 |
sealed case class Meta_Info(props: Properties.T, settings: Settings.T) { |
64103 | 275 |
def is_empty: Boolean = props.isEmpty && settings.isEmpty |
65599 | 276 |
|
65611 | 277 |
def get(c: SQL.Column): Option[String] = |
278 |
Properties.get(props, c.name) orElse |
|
279 |
Properties.get(settings, c.name) |
|
280 |
||
281 |
def get_date(c: SQL.Column): Option[Date] = |
|
71621 | 282 |
get(c).map(Log_File.Date_Format.parse) |
64103 | 283 |
} |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
284 |
|
75393 | 285 |
object Identify { |
65625 | 286 |
val log_prefix = "isabelle_identify_" |
66995
9cb263dbb2f7
plain identify job for Isabelle + AFP, independent of any Isabelle technology;
wenzelm
parents:
66944
diff
changeset
|
287 |
val log_prefix2 = "plain_identify_" |
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
288 |
|
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
289 |
def engine(log_file: Log_File): String = |
77133
536c033fb6eb
removed somewhat pointless support for Jenkins log files: it has stopped working long ago;
wenzelm
parents:
77113
diff
changeset
|
290 |
if (log_file.name.startsWith(log_prefix2)) "plain_identify" else "identify" |
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
291 |
|
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
292 |
def content(date: Date, isabelle_version: Option[String], afp_version: Option[String]): String = |
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
293 |
terminate_lines( |
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
294 |
List("isabelle_identify: " + Build_Log.print_date(date), "") ::: |
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
295 |
isabelle_version.map("Isabelle version: " + _).toList ::: |
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
296 |
afp_version.map("AFP version: " + _).toList) |
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
297 |
|
65625 | 298 |
val Start = new Regex("""^isabelle_identify: (.+)$""") |
299 |
val No_End = new Regex("""$.""") |
|
65684 | 300 |
val Isabelle_Version = List(new Regex("""^Isabelle version: (\S+)$""")) |
301 |
val AFP_Version = List(new Regex("""^AFP version: (\S+)$""")) |
|
65625 | 302 |
} |
303 |
||
75393 | 304 |
object Isatest { |
65588 | 305 |
val log_prefix = "isatest-makeall-" |
64108 | 306 |
val engine = "isatest" |
64109 | 307 |
val Start = new Regex("""^------------------- starting test --- (.+) --- (.+)$""") |
308 |
val End = new Regex("""^------------------- test (?:successful|FAILED) --- (.+) --- .*$""") |
|
65684 | 309 |
val Isabelle_Version = List(new Regex("""^Isabelle version: (\S+)$""")) |
64095 | 310 |
} |
311 |
||
75393 | 312 |
object AFP_Test { |
65588 | 313 |
val log_prefix = "afp-test-devel-" |
64108 | 314 |
val engine = "afp-test" |
64109 | 315 |
val Start = new Regex("""^Start test(?: for .+)? at ([^,]+), (.*)$""") |
316 |
val Start_Old = new Regex("""^Start test(?: for .+)? at ([^,]+)$""") |
|
317 |
val End = new Regex("""^End test on (.+), .+, elapsed time:.*$""") |
|
65684 | 318 |
val Isabelle_Version = List(new Regex("""^Isabelle version: .* -- hg id (\S+)$""")) |
319 |
val AFP_Version = List(new Regex("""^AFP version: .* -- hg id (\S+)$""")) |
|
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
320 |
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
|
321 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
322 |
|
75393 | 323 |
object Jenkins { |
65664 | 324 |
val log_prefix = "jenkins_" |
64110 | 325 |
val engine = "jenkins" |
65663 | 326 |
val Host = new Regex("""^Building remotely on (\S+) \((\S+)\).*$""") |
65665 | 327 |
val Start = new Regex("""^(?:Started by an SCM change|Started from command line by admin|).*$""") |
64110 | 328 |
val Start_Date = new Regex("""^Build started at (.+)$""") |
329 |
val No_End = new Regex("""$.""") |
|
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
330 |
val Isabelle_Version = |
65684 | 331 |
List(new Regex("""^(?:Build for Isabelle id|Isabelle id) (\w+).*$"""), |
65685 | 332 |
new Regex("""^ISABELLE_CI_REPO_ID="(\w+)".*$"""), |
333 |
new Regex("""^(\w{12}) tip.*$""")) |
|
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
334 |
val AFP_Version = |
65684 | 335 |
List(new Regex("""^(?:Build for AFP id|AFP id) (\w+).*$"""), |
336 |
new Regex("""^ISABELLE_CI_AFP_ID="(\w+)".*$""")) |
|
64110 | 337 |
val CONFIGURATION = "=== CONFIGURATION ===" |
338 |
val BUILD = "=== BUILD ===" |
|
339 |
} |
|
340 |
||
75393 | 341 |
private def parse_meta_info(log_file: Log_File): Meta_Info = { |
64108 | 342 |
def parse(engine: String, host: String, start: Date, |
75393 | 343 |
End: Regex, Isabelle_Version: List[Regex], AFP_Version: List[Regex] |
344 |
): Meta_Info = { |
|
345 |
val build_id = { |
|
65714 | 346 |
val prefix = proper_string(host) orElse proper_string(engine) getOrElse "build" |
347 |
prefix + ":" + start.time.ms |
|
64296
544481988e65
explicit identification of builds and correlated build groups;
wenzelm
parents:
64196
diff
changeset
|
348 |
} |
65591 | 349 |
val build_engine = if (engine == "") Nil else List(Prop.build_engine.name -> engine) |
350 |
val build_host = if (host == "") Nil else List(Prop.build_host.name -> host) |
|
64108 | 351 |
|
65599 | 352 |
val start_date = List(Prop.build_start.name -> print_date(start)) |
64091 | 353 |
val end_date = |
354 |
log_file.lines.last match { |
|
64109 | 355 |
case End(log_file.Strict_Date(end_date)) => |
65599 | 356 |
List(Prop.build_end.name -> print_date(end_date)) |
64091 | 357 |
case _ => Nil |
358 |
} |
|
359 |
||
360 |
val isabelle_version = |
|
65591 | 361 |
log_file.find_match(Isabelle_Version).map(Prop.isabelle_version.name -> _) |
64091 | 362 |
val afp_version = |
65591 | 363 |
log_file.find_match(AFP_Version).map(Prop.afp_version.name -> _) |
64062 | 364 |
|
65591 | 365 |
Meta_Info((Prop.build_id.name -> build_id) :: build_engine ::: build_host ::: |
64108 | 366 |
start_date ::: end_date ::: isabelle_version.toList ::: afp_version.toList, |
65611 | 367 |
log_file.get_all_settings) |
64091 | 368 |
} |
369 |
||
370 |
log_file.lines match { |
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
371 |
case line :: _ if Protocol.Meta_Info_Marker.test_yxml(line) => |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
372 |
Meta_Info(log_file.find_props(Protocol.Meta_Info_Marker).get, log_file.get_all_settings) |
64117 | 373 |
|
65625 | 374 |
case Identify.Start(log_file.Strict_Date(start)) :: _ => |
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
375 |
parse(Identify.engine(log_file), "", start, Identify.No_End, |
65625 | 376 |
Identify.Isabelle_Version, Identify.AFP_Version) |
377 |
||
64109 | 378 |
case Isatest.Start(log_file.Strict_Date(start), host) :: _ => |
379 |
parse(Isatest.engine, host, start, Isatest.End, |
|
65684 | 380 |
Isatest.Isabelle_Version, Nil) |
64099 | 381 |
|
64109 | 382 |
case AFP_Test.Start(log_file.Strict_Date(start), host) :: _ => |
383 |
parse(AFP_Test.engine, host, start, AFP_Test.End, |
|
384 |
AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) |
|
64099 | 385 |
|
64109 | 386 |
case AFP_Test.Start_Old(log_file.Strict_Date(start)) :: _ => |
387 |
parse(AFP_Test.engine, "", start, AFP_Test.End, |
|
388 |
AFP_Test.Isabelle_Version, AFP_Test.AFP_Version) |
|
64099 | 389 |
|
64341 | 390 |
case line :: _ if line.startsWith("\u0000") => Meta_Info.empty |
64109 | 391 |
case List(Isatest.End(_)) => Meta_Info.empty |
392 |
case _ :: AFP_Test.Bad_Init() :: _ => Meta_Info.empty |
|
64105 | 393 |
case Nil => Meta_Info.empty |
64104
b70fa05d6746
more permissive: accept all historic isatest and afp-test logs;
wenzelm
parents:
64103
diff
changeset
|
394 |
|
64110 | 395 |
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
|
396 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
397 |
} |
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
398 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
399 |
|
64098 | 400 |
|
75518
cb4af8c6152f
clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents:
75394
diff
changeset
|
401 |
/** build info: toplevel output of isabelle build or Admin/build_other **/ |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
402 |
|
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
403 |
val SESSION_NAME = "session_name" |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
404 |
|
78608 | 405 |
enum Session_Status { case existing, finished, failed, cancelled } |
64061
1bbea2b55d22
some support for header and data fields, notably from afp-test;
wenzelm
parents:
64054
diff
changeset
|
406 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
407 |
sealed case class Session_Entry( |
65643 | 408 |
chapter: String = "", |
409 |
groups: List[String] = Nil, |
|
78836
dd350a41594c
defined statically known tables of Build_Log;
Fabian Huch <huch@in.tum.de>
parents:
78768
diff
changeset
|
410 |
hostname: Option[String] = None, |
65643 | 411 |
threads: Option[Int] = None, |
412 |
timing: Timing = Timing.zero, |
|
413 |
ml_timing: Timing = Timing.zero, |
|
66913 | 414 |
sources: Option[String] = None, |
77113 | 415 |
heap_size: Option[Space] = None, |
78608 | 416 |
status: Option[Session_Status] = None, |
65937 | 417 |
errors: List[String] = Nil, |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
418 |
theory_timings: Map[String, Timing] = Map.empty, |
75393 | 419 |
ml_statistics: List[Properties.T] = Nil |
420 |
) { |
|
65631 | 421 |
def proper_groups: Option[String] = if (groups.isEmpty) None else Some(cat_lines(groups)) |
65643 | 422 |
def finished: Boolean = status == Some(Session_Status.finished) |
65937 | 423 |
def failed: Boolean = status == Some(Session_Status.failed) |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
424 |
} |
64054 | 425 |
|
75393 | 426 |
object Build_Info { |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
427 |
val sessions_dummy: Map[String, Session_Entry] = |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
428 |
Map("" -> Session_Entry(theory_timings = Map("" -> Timing.zero))) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
429 |
} |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
430 |
|
75393 | 431 |
sealed case class Build_Info(sessions: Map[String, Session_Entry]) { |
65937 | 432 |
def finished_sessions: List[String] = for ((a, b) <- sessions.toList if b.finished) yield a |
433 |
def failed_sessions: List[String] = for ((a, b) <- sessions.toList if b.failed) yield a |
|
64054 | 434 |
} |
435 |
||
75393 | 436 |
private def parse_build_info(log_file: Log_File, parse_ml_statistics: Boolean): Build_Info = { |
437 |
object Chapter_Name { |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
438 |
def unapply(s: String): Some[(String, String)] = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
439 |
space_explode('/', s) match { |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
440 |
case List(chapter, name) => Some((chapter, name)) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
441 |
case _ => Some(("", s)) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
442 |
} |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
443 |
} |
64054 | 444 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
445 |
val Session_No_Groups = new Regex("""^Session (\S+)$""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
446 |
val Session_Groups = new Regex("""^Session (\S+) \((.*)\)$""") |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
447 |
val Session_Finished1 = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
448 |
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
|
449 |
val Session_Finished2 = |
72695 | 450 |
new Regex("""^Finished ([^\s/]+) \((\d+):(\d+):(\d+) elapsed time.*$""") |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
451 |
val Session_Timing = |
65679 | 452 |
new Regex("""^Timing (\S+) \((\d+) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""") |
77551 | 453 |
val Session_Started1 = new Regex("""^(?:Running|Building) (\S+) \.\.\.$""") |
78843
fc3ba0a1c82f
read relative cpu from build log;
Fabian Huch <huch@in.tum.de>
parents:
78836
diff
changeset
|
454 |
val Session_Started2 = new Regex("""^(?:Running|Building) (\S+) \(?on ([^\s/]+)/?(\d+)\+?(\S+)\)? \.\.\.$""") |
66913 | 455 |
val Sources = new Regex("""^Sources (\S+) (\S{""" + SHA1.digest_length + """})$""") |
64120 | 456 |
val Heap = new Regex("""^Heap (\S+) \((\d+) bytes\)$""") |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
457 |
|
75393 | 458 |
object Theory_Timing { |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
459 |
def unapply(line: String): Option[(String, (String, Timing))] = |
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
460 |
Protocol.Theory_Timing_Marker.unapply(line.replace('~', '-')).map(log_file.parse_props) |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
461 |
match { |
72753 | 462 |
case Some((SESSION_NAME, session) :: props) => |
463 |
for (theory <- Markup.Name.unapply(props)) |
|
74782 | 464 |
yield (session, theory -> Markup.Timing_Properties.get(props)) |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
465 |
case _ => None |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
466 |
} |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
467 |
} |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
468 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
469 |
var chapter = Map.empty[String, String] |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
470 |
var groups = Map.empty[String, List[String]] |
78836
dd350a41594c
defined statically known tables of Build_Log;
Fabian Huch <huch@in.tum.de>
parents:
78768
diff
changeset
|
471 |
var hostnames = Map.empty[String, String] |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
472 |
var threads = Map.empty[String, Int] |
64054 | 473 |
var timing = Map.empty[String, Timing] |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
474 |
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
|
475 |
var started = Set.empty[String] |
66913 | 476 |
var sources = Map.empty[String, String] |
77113 | 477 |
var heap_sizes = Map.empty[String, Space] |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
478 |
var theory_timings = Map.empty[String, Map[String, Timing]] |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
479 |
var ml_statistics = Map.empty[String, List[Properties.T]] |
65937 | 480 |
var errors = Map.empty[String, List[String]] |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
481 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
482 |
def all_sessions: Set[String] = |
64120 | 483 |
chapter.keySet ++ groups.keySet ++ threads.keySet ++ timing.keySet ++ ml_timing.keySet ++ |
72694 | 484 |
started ++ sources.keySet ++ heap_sizes.keySet ++ |
66913 | 485 |
theory_timings.keySet ++ ml_statistics.keySet |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
486 |
|
64054 | 487 |
|
64062 | 488 |
for (line <- log_file.lines) { |
64054 | 489 |
line match { |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
490 |
case Session_No_Groups(Chapter_Name(chapt, name)) => |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
491 |
chapter += (name -> chapt) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
492 |
groups += (name -> Nil) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
493 |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
494 |
case Session_Groups(Chapter_Name(chapt, name), grps) => |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
495 |
chapter += (name -> chapt) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
496 |
groups += (name -> Word.explode(grps)) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
497 |
|
77551 | 498 |
case Session_Started1(name) => |
499 |
started += name |
|
500 |
||
78843
fc3ba0a1c82f
read relative cpu from build log;
Fabian Huch <huch@in.tum.de>
parents:
78836
diff
changeset
|
501 |
case Session_Started2(name, hostname, numa_node, rel_cpus) => |
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
|
502 |
started += name |
78836
dd350a41594c
defined statically known tables of Build_Log;
Fabian Huch <huch@in.tum.de>
parents:
78768
diff
changeset
|
503 |
hostnames += (name -> hostname) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
504 |
|
64054 | 505 |
case Session_Finished1(name, |
506 |
Value.Int(e1), Value.Int(e2), Value.Int(e3), |
|
507 |
Value.Int(c1), Value.Int(c2), Value.Int(c3)) => |
|
508 |
val elapsed = Time.hms(e1, e2, e3) |
|
509 |
val cpu = Time.hms(c1, c2, c3) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
510 |
timing += (name -> Timing(elapsed, cpu, Time.zero)) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
511 |
|
64054 | 512 |
case Session_Finished2(name, |
513 |
Value.Int(e1), Value.Int(e2), Value.Int(e3)) => |
|
514 |
val elapsed = Time.hms(e1, e2, e3) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
515 |
timing += (name -> Timing(elapsed, Time.zero, Time.zero)) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
516 |
|
64054 | 517 |
case Session_Timing(name, |
518 |
Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) => |
|
519 |
val elapsed = Time.seconds(e) |
|
520 |
val cpu = Time.seconds(c) |
|
521 |
val gc = Time.seconds(g) |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
522 |
ml_timing += (name -> Timing(elapsed, cpu, gc)) |
64054 | 523 |
threads += (name -> t) |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
524 |
|
66913 | 525 |
case Sources(name, s) => |
526 |
sources += (name -> s) |
|
527 |
||
64120 | 528 |
case Heap(name, Value.Long(size)) => |
77113 | 529 |
heap_sizes += (name -> Space.bytes(size)) |
64120 | 530 |
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
531 |
case _ if Protocol.Theory_Timing_Marker.test_yxml(line) => |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
532 |
line match { |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
533 |
case Theory_Timing(name, theory_timing) => |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
534 |
theory_timings += (name -> (theory_timings.getOrElse(name, Map.empty) + theory_timing)) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
535 |
case _ => log_file.err("malformed theory_timing " + quote(line)) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
536 |
} |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
537 |
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
538 |
case _ if parse_ml_statistics && Protocol.ML_Statistics_Marker.test_yxml(line) => |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
539 |
Protocol.ML_Statistics_Marker.unapply(line).map(log_file.parse_props) match { |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
540 |
case Some((SESSION_NAME, name) :: props) => |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
541 |
ml_statistics += (name -> (props :: ml_statistics.getOrElse(name, Nil))) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
542 |
case _ => log_file.err("malformed ML_statistics " + quote(line)) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
543 |
} |
64119
8094eaa38d4b
inline session ML statistics into main build log;
wenzelm
parents:
64117
diff
changeset
|
544 |
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
545 |
case _ if Protocol.Error_Message_Marker.test_yxml(line) => |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
546 |
Protocol.Error_Message_Marker.unapply(line).map(log_file.parse_props) match { |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
547 |
case Some(List((SESSION_NAME, name), (Markup.CONTENT, msg))) => |
71620 | 548 |
errors += (name -> (msg :: errors.getOrElse(name, Nil))) |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
549 |
case _ => log_file.err("malformed error message " + quote(line)) |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
550 |
} |
65937 | 551 |
|
64054 | 552 |
case _ => |
553 |
} |
|
554 |
} |
|
555 |
||
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
556 |
val sessions = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
557 |
Map( |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
558 |
(for (name <- all_sessions.toList) yield { |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
559 |
val status = |
72694 | 560 |
if (timing.isDefinedAt(name) || ml_timing.isDefinedAt(name)) |
65633 | 561 |
Session_Status.finished |
562 |
else if (started(name)) Session_Status.failed |
|
563 |
else Session_Status.existing |
|
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
564 |
val entry = |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
565 |
Session_Entry( |
65643 | 566 |
chapter = chapter.getOrElse(name, ""), |
567 |
groups = groups.getOrElse(name, Nil), |
|
78836
dd350a41594c
defined statically known tables of Build_Log;
Fabian Huch <huch@in.tum.de>
parents:
78768
diff
changeset
|
568 |
hostname = hostnames.get(name), |
65643 | 569 |
threads = threads.get(name), |
570 |
timing = timing.getOrElse(name, Timing.zero), |
|
571 |
ml_timing = ml_timing.getOrElse(name, Timing.zero), |
|
66913 | 572 |
sources = sources.get(name), |
65643 | 573 |
heap_size = heap_sizes.get(name), |
574 |
status = Some(status), |
|
65937 | 575 |
errors = errors.getOrElse(name, Nil).reverse, |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
576 |
theory_timings = theory_timings.getOrElse(name, Map.empty), |
65643 | 577 |
ml_statistics = ml_statistics.getOrElse(name, Nil).reverse) |
64085
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
578 |
(name -> entry) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
579 |
}):_*) |
1c451e5c145f
clarified parse_build_info: isabelle build output;
wenzelm
parents:
64083
diff
changeset
|
580 |
Build_Info(sessions) |
64054 | 581 |
} |
64099 | 582 |
|
583 |
||
584 |
||
72860 | 585 |
/** session info: produced by isabelle build as session database **/ |
64099 | 586 |
|
587 |
sealed case class Session_Info( |
|
588 |
session_timing: Properties.T, |
|
589 |
command_timings: List[Properties.T], |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66863
diff
changeset
|
590 |
theory_timings: List[Properties.T], |
64099 | 591 |
ml_statistics: List[Properties.T], |
65934 | 592 |
task_statistics: List[Properties.T], |
75393 | 593 |
errors: List[String] |
594 |
) { |
|
66944
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66913
diff
changeset
|
595 |
def error(s: String): Session_Info = |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66913
diff
changeset
|
596 |
copy(errors = errors ::: List(s)) |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66913
diff
changeset
|
597 |
} |
64099 | 598 |
|
599 |
private def parse_session_info( |
|
600 |
log_file: Log_File, |
|
601 |
command_timings: Boolean, |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66863
diff
changeset
|
602 |
theory_timings: Boolean, |
64099 | 603 |
ml_statistics: Boolean, |
75393 | 604 |
task_statistics: Boolean |
605 |
): Session_Info = { |
|
65290 | 606 |
Session_Info( |
72012 | 607 |
session_timing = log_file.find_props(Protocol.Session_Timing_Marker) getOrElse Nil, |
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
608 |
command_timings = |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
609 |
if (command_timings) log_file.filter_props(Protocol.Command_Timing_Marker) else Nil, |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
610 |
theory_timings = |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
611 |
if (theory_timings) log_file.filter_props(Protocol.Theory_Timing_Marker) else Nil, |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
612 |
ml_statistics = |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
613 |
if (ml_statistics) log_file.filter_props(Protocol.ML_Statistics_Marker) else Nil, |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
614 |
task_statistics = |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
615 |
if (task_statistics) log_file.filter_props(Protocol.Task_Statistics_Marker) else Nil, |
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71621
diff
changeset
|
616 |
errors = log_file.filter(Protocol.Error_Message_Marker)) |
64099 | 617 |
} |
65595 | 618 |
|
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
619 |
def compress_errors( |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
620 |
errors: List[String], |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
621 |
cache: Compress.Cache = Compress.Cache.none |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
622 |
): Option[Bytes] = |
65937 | 623 |
if (errors.isEmpty) None |
68018 | 624 |
else { |
625 |
Some(Bytes(YXML.string_of_body(XML.Encode.list(XML.Encode.string)(errors))). |
|
626 |
compress(cache = cache)) |
|
627 |
} |
|
65937 | 628 |
|
73033 | 629 |
def uncompress_errors(bytes: Bytes, cache: XML.Cache = XML.Cache.make()): List[String] = |
72885 | 630 |
if (bytes.is_empty) Nil |
68018 | 631 |
else { |
73033 | 632 |
XML.Decode.list(YXML.string_of_body)( |
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
633 |
YXML.parse_body(bytes.uncompress(cache = cache.compress).text, cache = cache)) |
68018 | 634 |
} |
65937 | 635 |
|
65595 | 636 |
|
637 |
||
638 |
/** persistent store **/ |
|
639 |
||
65694 | 640 |
/* SQL data model */ |
641 |
||
79064 | 642 |
object Column { |
66857 | 643 |
val log_name = SQL.Column.string("log_name").make_primary_key |
644 |
val session_name = SQL.Column.string("session_name").make_primary_key |
|
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
645 |
val theory_name = SQL.Column.string("theory_name").make_primary_key |
65694 | 646 |
val chapter = SQL.Column.string("chapter") |
647 |
val groups = SQL.Column.string("groups") |
|
78836
dd350a41594c
defined statically known tables of Build_Log;
Fabian Huch <huch@in.tum.de>
parents:
78768
diff
changeset
|
648 |
val hostname = SQL.Column.string("hostname") |
65694 | 649 |
val threads = SQL.Column.int("threads") |
650 |
val timing_elapsed = SQL.Column.long("timing_elapsed") |
|
651 |
val timing_cpu = SQL.Column.long("timing_cpu") |
|
652 |
val timing_gc = SQL.Column.long("timing_gc") |
|
653 |
val timing_factor = SQL.Column.double("timing_factor") |
|
654 |
val ml_timing_elapsed = SQL.Column.long("ml_timing_elapsed") |
|
655 |
val ml_timing_cpu = SQL.Column.long("ml_timing_cpu") |
|
656 |
val ml_timing_gc = SQL.Column.long("ml_timing_gc") |
|
657 |
val ml_timing_factor = SQL.Column.double("ml_timing_factor") |
|
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
658 |
val theory_timing_elapsed = SQL.Column.long("theory_timing_elapsed") |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
659 |
val theory_timing_cpu = SQL.Column.long("theory_timing_cpu") |
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
660 |
val theory_timing_gc = SQL.Column.long("theory_timing_gc") |
65694 | 661 |
val heap_size = SQL.Column.long("heap_size") |
662 |
val status = SQL.Column.string("status") |
|
65937 | 663 |
val errors = SQL.Column.bytes("errors") |
66913 | 664 |
val sources = SQL.Column.string("sources") |
65694 | 665 |
val ml_statistics = SQL.Column.bytes("ml_statistics") |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65781
diff
changeset
|
666 |
val known = SQL.Column.bool("known") |
65694 | 667 |
|
79064 | 668 |
def pull_date(afp: Boolean = false): SQL.Column = |
669 |
if (afp) SQL.Column.date("afp_pull_date") |
|
670 |
else SQL.Column.date("pull_date") |
|
671 |
} |
|
672 |
||
673 |
object private_data extends SQL.Data("isabelle_build_log") { |
|
674 |
override def tables: SQL.Tables = |
|
675 |
SQL.Tables( |
|
676 |
meta_info_table, |
|
677 |
sessions_table, |
|
678 |
theories_table, |
|
679 |
ml_statistics_table) |
|
680 |
||
681 |
||
682 |
/* main content */ |
|
683 |
||
65694 | 684 |
val meta_info_table = |
79064 | 685 |
make_table(Column.log_name :: Prop.all_props ::: Settings.all_settings, name = "meta_info") |
65694 | 686 |
|
687 |
val sessions_table = |
|
78266 | 688 |
make_table( |
79064 | 689 |
List(Column.log_name, Column.session_name, Column.chapter, Column.groups, Column.hostname, |
690 |
Column.threads, Column.timing_elapsed, Column.timing_cpu, Column.timing_gc, |
|
691 |
Column.timing_factor, Column.ml_timing_elapsed, Column.ml_timing_cpu, Column.ml_timing_gc, |
|
692 |
Column.ml_timing_factor, Column.heap_size, Column.status, Column.errors, Column.sources), |
|
78266 | 693 |
name = "sessions") |
65694 | 694 |
|
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
695 |
val theories_table = |
78266 | 696 |
make_table( |
79064 | 697 |
List(Column.log_name, Column.session_name, Column.theory_name, Column.theory_timing_elapsed, |
698 |
Column.theory_timing_cpu, Column.theory_timing_gc), |
|
78266 | 699 |
name = "theories") |
66874
0b8da0fc9563
store theory timings in session in build_log database;
wenzelm
parents:
66873
diff
changeset
|
700 |
|
65694 | 701 |
val ml_statistics_table = |
79064 | 702 |
make_table(List(Column.log_name, Column.session_name, Column.ml_statistics), |
703 |
name = "ml_statistics") |
|
65694 | 704 |
|
705 |
||
65705 | 706 |
/* earliest pull date for repository version (PostgreSQL queries) */ |
65694 | 707 |
|
75393 | 708 |
def pull_date_table(afp: Boolean = false): SQL.Table = { |
66863
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
709 |
val (name, versions) = |
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
710 |
if (afp) ("afp_pull_date", List(Prop.isabelle_version, Prop.afp_version)) |
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
711 |
else ("pull_date", List(Prop.isabelle_version)) |
65694 | 712 |
|
79064 | 713 |
make_table(versions.map(_.make_primary_key) ::: List(Column.pull_date(afp)), |
78266 | 714 |
body = |
715 |
"SELECT " + versions.mkString(", ") + |
|
79064 | 716 |
", min(" + Prop.build_start + ") AS " + Column.pull_date(afp) + |
78266 | 717 |
" FROM " + meta_info_table + |
718 |
" WHERE " + SQL.AND((versions ::: List(Prop.build_start)).map(_.defined)) + |
|
719 |
" GROUP BY " + versions.mkString(", "), |
|
720 |
name = name) |
|
66855 | 721 |
} |
722 |
||
723 |
||
724 |
/* recent entries */ |
|
725 |
||
78921
2fee5fba3116
proper default for disjunction (amending 9f7a94117666);
wenzelm
parents:
78900
diff
changeset
|
726 |
def recent(c: SQL.Column, days: Int, default: PostgreSQL.Source = ""): PostgreSQL.Source = |
2fee5fba3116
proper default for disjunction (amending 9f7a94117666);
wenzelm
parents:
78900
diff
changeset
|
727 |
if (days <= 0) default |
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
728 |
else c.ident + " > now() - INTERVAL '" + days + " days'" |
65736 | 729 |
|
66863
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
730 |
def recent_pull_date_table( |
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
731 |
days: Int = 0, |
75393 | 732 |
rev: String = "", |
733 |
afp_rev: Option[String] = None |
|
734 |
): SQL.Table = { |
|
66863
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
735 |
val afp = afp_rev.isDefined |
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
736 |
val rev2 = afp_rev.getOrElse("") |
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
737 |
val table = pull_date_table(afp) |
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
738 |
|
77376 | 739 |
val eq_rev = if_proper(rev, Prop.isabelle_version(table).equal(rev)) |
740 |
val eq_rev2 = if_proper(rev2, Prop.afp_version(table).equal(rev2)) |
|
66863
6acd1a2bd146
clarified afp_pull_date: both repository versions are relevant;
wenzelm
parents:
66858
diff
changeset
|
741 |
|
65777 | 742 |
SQL.Table("recent_pull_date", table.columns, |
77381
a86e346b20d8
misc tuning and clarification: more uniform use of optional "sql" in SQL.Table.delete/select;
wenzelm
parents:
77376
diff
changeset
|
743 |
table.select(table.columns, sql = |
78153 | 744 |
SQL.where_or( |
79064 | 745 |
recent(Column.pull_date(afp)(table), days, default = SQL.TRUE), |
78153 | 746 |
SQL.and(eq_rev, eq_rev2)))) |
65702 | 747 |
} |
65694 | 748 |
|
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
749 |
def select_recent_log_names(days: Int = 0): PostgreSQL.Source = { |
65781 | 750 |
val table1 = meta_info_table |
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
751 |
val table2 = recent_pull_date_table(days = days) |
79064 | 752 |
table1.select(List(Column.log_name), distinct = true, sql = |
77381
a86e346b20d8
misc tuning and clarification: more uniform use of optional "sql" in SQL.Table.delete/select;
wenzelm
parents:
77376
diff
changeset
|
753 |
SQL.join_inner + table2.query_named + |
a86e346b20d8
misc tuning and clarification: more uniform use of optional "sql" in SQL.Table.delete/select;
wenzelm
parents:
77376
diff
changeset
|
754 |
" ON " + Prop.isabelle_version(table1) + " = " + Prop.isabelle_version(table2)) |
65781 | 755 |
} |
756 |
||
65724 | 757 |
|
758 |
/* universal view on main data */ |
|
759 |
||
75393 | 760 |
val universal_table: SQL.Table = { |
79064 | 761 |
val afp_pull_date = Column.pull_date(afp = true) |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
762 |
val version1 = Prop.isabelle_version |
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
763 |
val version2 = Prop.afp_version |
65724 | 764 |
val table1 = meta_info_table |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
765 |
val table2 = pull_date_table(afp = true) |
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
766 |
val table3 = pull_date_table() |
65724 | 767 |
|
79064 | 768 |
val a_columns = Column.log_name :: afp_pull_date :: table1.columns.tail |
65850
5414c14c3984
clarified universal table: include ml_statistics;
wenzelm
parents:
65804
diff
changeset
|
769 |
val a_table = |
5414c14c3984
clarified universal table: include ml_statistics;
wenzelm
parents:
65804
diff
changeset
|
770 |
SQL.Table("a", a_columns, |
79064 | 771 |
SQL.select(List(Column.log_name, afp_pull_date) ::: |
772 |
table1.columns.tail.map(_.apply(table1))) + |
|
77376 | 773 |
table1 + SQL.join_outer + table2 + " ON " + |
774 |
SQL.and( |
|
775 |
version1(table1).ident + " = " + version1(table2).ident, |
|
776 |
version2(table1).ident + " = " + version2(table2).ident)) |
|
65724 | 777 |
|
79064 | 778 |
val b_columns = Column.log_name :: Column.pull_date() :: a_columns.tail |
65850
5414c14c3984
clarified universal table: include ml_statistics;
wenzelm
parents:
65804
diff
changeset
|
779 |
val b_table = |
5414c14c3984
clarified universal table: include ml_statistics;
wenzelm
parents:
65804
diff
changeset
|
780 |
SQL.Table("b", b_columns, |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
781 |
SQL.select( |
79064 | 782 |
List(Column.log_name(a_table), Column.pull_date()(table3)) ::: |
783 |
a_columns.tail.map(_.apply(a_table))) + |
|
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
784 |
a_table.query_named + SQL.join_outer + table3 + |
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
785 |
" ON " + version1(a_table) + " = " + version1(table3)) |
65850
5414c14c3984
clarified universal table: include ml_statistics;
wenzelm
parents:
65804
diff
changeset
|
786 |
|
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
787 |
val c_columns = b_columns ::: sessions_table.columns.tail |
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
788 |
val c_table = |
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
789 |
SQL.Table("c", c_columns, |
79064 | 790 |
SQL.select(Column.log_name(b_table) :: c_columns.tail) + |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
791 |
b_table.query_named + SQL.join_inner + sessions_table + |
79064 | 792 |
" ON " + Column.log_name(b_table) + " = " + Column.log_name(sessions_table)) |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
793 |
|
79064 | 794 |
make_table(c_columns ::: List(Column.ml_statistics), |
78266 | 795 |
body = |
79064 | 796 |
SQL.select(c_columns.map(_.apply(c_table)) ::: List(Column.ml_statistics)) + |
77376 | 797 |
c_table.query_named + SQL.join_outer + ml_statistics_table + " ON " + |
798 |
SQL.and( |
|
79064 | 799 |
Column.log_name(c_table).ident + " = " + Column.log_name(ml_statistics_table).ident, |
800 |
Column.session_name(c_table).ident + " = " + |
|
801 |
Column.session_name(ml_statistics_table).ident)) |
|
65724 | 802 |
} |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
803 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
804 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
805 |
/* access data */ |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
806 |
|
79063 | 807 |
def read_domain( |
808 |
db: SQL.Database, |
|
809 |
table: SQL.Table, |
|
810 |
column: SQL.Column, |
|
811 |
restriction: Option[Iterable[String]] = None, |
|
812 |
cache: XML.Cache = XML.Cache.make() |
|
813 |
): Set[String] = { |
|
814 |
db.execute_query_statement( |
|
815 |
table.select(List(column), |
|
816 |
sql = restriction match { |
|
817 |
case None => "" |
|
818 |
case Some(names) => column.where_member(names) |
|
819 |
}, |
|
820 |
distinct = true), |
|
821 |
Set.from[String], res => cache.string(res.string(column))) |
|
822 |
} |
|
823 |
||
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
824 |
def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] = { |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
825 |
val table = meta_info_table |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
826 |
val columns = table.columns.tail |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
827 |
db.execute_query_statementO[Meta_Info]( |
79064 | 828 |
table.select(columns, sql = Column.log_name.where_equal(log_name)), |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
829 |
{ res => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
830 |
val results = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
831 |
columns.map(c => c.name -> |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
832 |
(if (c.T == SQL.Type.Date) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
833 |
res.get_date(c).map(Log_File.Date_Format(_)) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
834 |
else |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
835 |
res.get_string(c))) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
836 |
val n = Prop.all_props.length |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
837 |
val props = for (case (x, Some(y)) <- results.take(n)) yield (x, y) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
838 |
val settings = for (case (x, Some(y)) <- results.drop(n)) yield (x, y) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
839 |
Meta_Info(props, settings) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
840 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
841 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
842 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
843 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
844 |
def read_build_info( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
845 |
db: SQL.Database, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
846 |
log_name: String, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
847 |
session_names: List[String] = Nil, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
848 |
ml_statistics: Boolean = false, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
849 |
cache: XML.Cache = XML.Cache.make() |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
850 |
): Build_Info = { |
79064 | 851 |
val table1 = sessions_table |
852 |
val table2 = ml_statistics_table |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
853 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
854 |
val columns1 = table1.columns.tail.map(_.apply(table1)) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
855 |
val (columns, from) = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
856 |
if (ml_statistics) { |
79064 | 857 |
val columns = columns1 ::: List(Column.ml_statistics(table2)) |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
858 |
val join = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
859 |
table1.ident + SQL.join_outer + table2.ident + " ON " + |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
860 |
SQL.and( |
79064 | 861 |
Column.log_name(table1).ident + " = " + Column.log_name(table2).ident, |
862 |
Column.session_name(table1).ident + " = " + Column.session_name(table2).ident) |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
863 |
(columns, SQL.enclose(join)) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
864 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
865 |
else (columns1, table1.ident) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
866 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
867 |
val where = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
868 |
SQL.where_and( |
79064 | 869 |
Column.log_name(table1).equal(log_name), |
870 |
Column.session_name(table1).ident + " <> ''", |
|
871 |
if_proper(session_names, Column.session_name(table1).member(session_names))) |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
872 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
873 |
val sessions = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
874 |
db.execute_query_statement( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
875 |
SQL.select(columns, sql = from + where), |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
876 |
Map.from[String, Session_Entry], |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
877 |
{ res => |
79064 | 878 |
val session_name = res.string(Column.session_name) |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
879 |
val session_entry = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
880 |
Session_Entry( |
79064 | 881 |
chapter = res.string(Column.chapter), |
882 |
groups = split_lines(res.string(Column.groups)), |
|
883 |
hostname = res.get_string(Column.hostname), |
|
884 |
threads = res.get_int(Column.threads), |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
885 |
timing = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
886 |
res.timing( |
79064 | 887 |
Column.timing_elapsed, |
888 |
Column.timing_cpu, |
|
889 |
Column.timing_gc), |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
890 |
ml_timing = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
891 |
res.timing( |
79064 | 892 |
Column.ml_timing_elapsed, |
893 |
Column.ml_timing_cpu, |
|
894 |
Column.ml_timing_gc), |
|
895 |
sources = res.get_string(Column.sources), |
|
896 |
heap_size = res.get_long(Column.heap_size).map(Space.bytes), |
|
897 |
status = res.get_string(Column.status).map(Session_Status.valueOf), |
|
898 |
errors = uncompress_errors(res.bytes(Column.errors), cache = cache), |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
899 |
ml_statistics = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
900 |
if (ml_statistics) { |
79064 | 901 |
Properties.uncompress(res.bytes(Column.ml_statistics), cache = cache) |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
902 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
903 |
else Nil) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
904 |
session_name -> session_entry |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
905 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
906 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
907 |
Build_Info(sessions) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
908 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
909 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
910 |
def update_meta_info(db: SQL.Database, log_name: String, meta_info: Meta_Info): Unit = |
79064 | 911 |
db.execute_statement(db.insert_permissive(meta_info_table), |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
912 |
{ stmt => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
913 |
stmt.string(1) = log_name |
79064 | 914 |
for ((c, i) <- meta_info_table.columns.tail.zipWithIndex) { |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
915 |
if (c.T == SQL.Type.Date) stmt.date(i + 2) = meta_info.get_date(c) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
916 |
else stmt.string(i + 2) = meta_info.get(c) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
917 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
918 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
919 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
920 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
921 |
def update_sessions( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
922 |
db: SQL.Database, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
923 |
cache: Compress.Cache, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
924 |
log_name: String, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
925 |
build_info: Build_Info, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
926 |
): Unit = { |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
927 |
val sessions = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
928 |
if (build_info.sessions.isEmpty) Build_Info.sessions_dummy |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
929 |
else build_info.sessions |
79064 | 930 |
db.execute_batch_statement(db.insert_permissive(sessions_table), |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
931 |
for ((session_name, session) <- sessions) yield { (stmt: SQL.Statement) => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
932 |
stmt.string(1) = log_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
933 |
stmt.string(2) = session_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
934 |
stmt.string(3) = proper_string(session.chapter) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
935 |
stmt.string(4) = session.proper_groups |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
936 |
stmt.string(5) = session.hostname |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
937 |
stmt.int(6) = session.threads |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
938 |
stmt.long(7) = session.timing.elapsed.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
939 |
stmt.long(8) = session.timing.cpu.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
940 |
stmt.long(9) = session.timing.gc.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
941 |
stmt.double(10) = session.timing.factor |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
942 |
stmt.long(11) = session.ml_timing.elapsed.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
943 |
stmt.long(12) = session.ml_timing.cpu.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
944 |
stmt.long(13) = session.ml_timing.gc.proper_ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
945 |
stmt.double(14) = session.ml_timing.factor |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
946 |
stmt.long(15) = session.heap_size.map(_.bytes) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
947 |
stmt.string(16) = session.status.map(_.toString) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
948 |
stmt.bytes(17) = compress_errors(session.errors, cache = cache) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
949 |
stmt.string(18) = session.sources |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
950 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
951 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
952 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
953 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
954 |
def update_theories(db: SQL.Database, log_name: String, build_info: Build_Info): Unit = { |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
955 |
val sessions = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
956 |
if (build_info.sessions.forall({ case (_, session) => session.theory_timings.isEmpty })) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
957 |
Build_Info.sessions_dummy |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
958 |
else build_info.sessions |
79064 | 959 |
db.execute_batch_statement(db.insert_permissive(theories_table), |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
960 |
for { |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
961 |
(session_name, session) <- sessions |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
962 |
(theory_name, timing) <- session.theory_timings |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
963 |
} yield { (stmt: SQL.Statement) => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
964 |
stmt.string(1) = log_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
965 |
stmt.string(2) = session_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
966 |
stmt.string(3) = theory_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
967 |
stmt.long(4) = timing.elapsed.ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
968 |
stmt.long(5) = timing.cpu.ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
969 |
stmt.long(6) = timing.gc.ms |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
970 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
971 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
972 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
973 |
|
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
974 |
def update_ml_statistics( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
975 |
db: SQL.Database, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
976 |
cache: Compress.Cache, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
977 |
log_name: String, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
978 |
build_info: Build_Info |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
979 |
): Unit = { |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
980 |
val ml_stats: List[(String, Option[Bytes])] = |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
981 |
Par_List.map[(String, Session_Entry), (String, Option[Bytes])]( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
982 |
{ case (a, b) => (a, Properties.compress(b.ml_statistics, cache = cache).proper) }, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
983 |
build_info.sessions.iterator.filter(p => p._2.ml_statistics.nonEmpty).toList) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
984 |
val entries = if (ml_stats.nonEmpty) ml_stats else List("" -> None) |
79064 | 985 |
db.execute_batch_statement(db.insert_permissive(ml_statistics_table), |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
986 |
for ((session_name, ml_statistics) <- entries) yield { (stmt: SQL.Statement) => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
987 |
stmt.string(1) = log_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
988 |
stmt.string(2) = session_name |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
989 |
stmt.bytes(3) = ml_statistics |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
990 |
} |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
991 |
) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
992 |
} |
65694 | 993 |
} |
994 |
||
995 |
||
996 |
/* database access */ |
|
997 |
||
73031
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
wenzelm
parents:
73025
diff
changeset
|
998 |
def store(options: Options, cache: XML.Cache = XML.Cache.make()): Store = |
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
wenzelm
parents:
73025
diff
changeset
|
999 |
new Store(options, cache) |
65595 | 1000 |
|
78343 | 1001 |
class Store private[Build_Log](val options: Options, val cache: XML.Cache) { |
77746 | 1002 |
override def toString: String = { |
1003 |
val s = |
|
78768
280a228dc2f1
prefer Exn.result: avoid accidental capture of interrupts, similar to ML;
wenzelm
parents:
78619
diff
changeset
|
1004 |
Exn.result { open_database() } match { |
77746 | 1005 |
case Exn.Res(db) => |
1006 |
val db_name = db.toString |
|
1007 |
db.close() |
|
1008 |
"database = " + db_name |
|
1009 |
case Exn.Exn(_) => "no database" |
|
1010 |
} |
|
1011 |
"Store(" + s + ")" |
|
1012 |
} |
|
1013 |
||
78347 | 1014 |
def open_database(server: SSH.Server = SSH.no_server): PostgreSQL.Database = |
1015 |
PostgreSQL.open_database_server(options, server = server, |
|
1016 |
user = options.string("build_log_database_user"), |
|
1017 |
password = options.string("build_log_database_password"), |
|
1018 |
database = options.string("build_log_database_name"), |
|
1019 |
host = options.string("build_log_database_host"), |
|
1020 |
port = options.int("build_log_database_port"), |
|
1021 |
ssh_host = options.string("build_log_ssh_host"), |
|
1022 |
ssh_port = options.int("build_log_ssh_port"), |
|
78863
f627ab8c276c
discontinued pointless option (reverting 63d55ba90a9f): performance tuning works better via SQL.Database.execute_batch_statement;
wenzelm
parents:
78862
diff
changeset
|
1023 |
ssh_user = options.string("build_log_ssh_user")) |
65599 | 1024 |
|
78851 | 1025 |
def init_database(db: SQL.Database, minimal: Boolean = false): Unit = |
79063 | 1026 |
private_data.transaction_lock(db, create = true, label = "Build_Log.init_database") { |
78851 | 1027 |
if (!minimal) { |
1028 |
db.create_view(private_data.pull_date_table()) |
|
1029 |
db.create_view(private_data.pull_date_table(afp = true)) |
|
1030 |
} |
|
1031 |
db.create_view(private_data.universal_table) |
|
1032 |
} |
|
1033 |
||
75393 | 1034 |
def snapshot_database( |
1035 |
db: PostgreSQL.Database, |
|
1036 |
sqlite_database: Path, |
|
1037 |
days: Int = 100, |
|
1038 |
ml_statistics: Boolean = false |
|
1039 |
): Unit = { |
|
72375 | 1040 |
Isabelle_System.make_directory(sqlite_database.dir) |
65694 | 1041 |
sqlite_database.file.delete |
1042 |
||
75394 | 1043 |
using(SQLite.open_database(sqlite_database)) { db2 => |
79061 | 1044 |
private_data.transaction_lock(db, label = "Build_Log.snapshot_database") { |
65694 | 1045 |
db2.transaction { |
65705 | 1046 |
// main content |
78849 | 1047 |
db2.create_table(private_data.meta_info_table) |
1048 |
db2.create_table(private_data.sessions_table) |
|
1049 |
db2.create_table(private_data.theories_table) |
|
1050 |
db2.create_table(private_data.ml_statistics_table) |
|
65705 | 1051 |
|
1052 |
val recent_log_names = |
|
77552 | 1053 |
db.execute_query_statement( |
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
1054 |
private_data.select_recent_log_names(days = days), |
79064 | 1055 |
List.from[String], res => res.string(Column.log_name)) |
65705 | 1056 |
|
1057 |
for (log_name <- recent_log_names) { |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1058 |
private_data.read_meta_info(db, log_name).foreach(meta_info => |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1059 |
private_data.update_meta_info(db2, log_name, meta_info)) |
65705 | 1060 |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1061 |
private_data.update_sessions(db2, cache.compress, log_name, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1062 |
private_data.read_build_info(db, log_name, cache = cache)) |
65705 | 1063 |
|
65856 | 1064 |
if (ml_statistics) { |
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1065 |
private_data.update_ml_statistics(db2, cache.compress, log_name, |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79061
diff
changeset
|
1066 |
private_data.read_build_info(db, log_name, ml_statistics = true, cache = cache)) |
65856 | 1067 |
} |
65705 | 1068 |
} |
1069 |
||
1070 |
// pull_date |
|
75393 | 1071 |
for (afp <- List(false, true)) { |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
1072 |
val afp_rev = if (afp) Some("") else None |
78849 | 1073 |
val table = private_data.pull_date_table(afp) |
65694 | 1074 |
db2.create_table(table) |
75394 | 1075 |
db2.using_statement(table.insert()) { stmt2 => |
66880
486f4af28db9
more thorough treatment of afp_version and afp_pull_date;
wenzelm
parents:
66874
diff
changeset
|
1076 |
db.using_statement( |
78900
9f7a94117666
clarified "recent" time: days <= 0 means infinity (no constraint);
wenzelm
parents:
78894
diff
changeset
|
1077 |
private_data.recent_pull_date_table(days = days, afp_rev = afp_rev).query) { stmt => |
78352 | 1078 |
using(stmt.execute_query()) { res => |
1079 |
while (res.next()) { |
|
1080 |
for ((c, i) <- table.columns.zipWithIndex) { |
|
1081 |
stmt2.string(i + 1) = res.get_string(c) |
|
1082 |
} |
|
1083 |
stmt2.execute() |
|
65748 | 1084 |
} |
65694 | 1085 |
} |
75394 | 1086 |
} |
1087 |
} |
|
65709 | 1088 |
} |
65705 | 1089 |
|
1090 |
// full view |
|
78849 | 1091 |
db2.create_view(private_data.universal_table) |
65694 | 1092 |
} |
1093 |
} |
|
77664
f5d3ade80d15
more specific vacuum operation, which is also relevant to PostgreSQL;
wenzelm
parents:
77552
diff
changeset
|
1094 |
db2.vacuum() |
75394 | 1095 |
} |
65694 | 1096 |
} |
1097 |
||
77748 | 1098 |
def write_info(db: SQL.Database, files: List[JFile], |
1099 |
ml_statistics: Boolean = false, |
|
1100 |
progress: Progress = new Progress, |
|
1101 |
errors: Multi_Map[String, String] = Multi_Map.empty |
|
1102 |
): Multi_Map[String, String] = { |
|
78851 | 1103 |
init_database(db) |
1104 |
||
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1105 |
val errors_result = Synchronized(errors) |
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1106 |
def add_error(name: String, exn: Throwable): Unit = |
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1107 |
errors_result.change(_.insert(name, Exn.print(exn))) |
77748 | 1108 |
|
78859
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1109 |
val files_domain = { |
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1110 |
val names = files.map(Log_File.plain_name).toSet |
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1111 |
if (names.size > 100) None else Some(names) |
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1112 |
} |
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1113 |
|
75393 | 1114 |
abstract class Table_Status(table: SQL.Table) { |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1115 |
private val known = |
79063 | 1116 |
Synchronized( |
79064 | 1117 |
private_data.read_domain(db, table, Column.log_name, |
79063 | 1118 |
restriction = files_domain, cache = cache)) |
65688 | 1119 |
|
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1120 |
def required(file: JFile): Boolean = !(known.value)(Log_File.plain_name(file)) |
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1121 |
def required(log_file: Log_File): Boolean = !(known.value)(log_file.name) |
65705 | 1122 |
|
1123 |
def update_db(db: SQL.Database, log_file: Log_File): Unit |
|
75393 | 1124 |
def update(log_file: Log_File): Unit = { |
77748 | 1125 |
if (required(log_file)) { |
65642 | 1126 |
update_db(db, log_file) |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1127 |
known.change(_ + log_file.name) |
65618 | 1128 |
} |
65614
325801edb37d
clarified transaction boundaries: more robust incremental write operations;
wenzelm
parents:
65613
diff
changeset
|
1129 |
} |
65605 | 1130 |
} |
78859
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1131 |
|
79063 | 1132 |
val status = |
1133 |
private_data.transaction_lock(db, label = "build_log_database.status") { |
|
1134 |
val status1 = |
|
1135 |
if (ml_statistics) { |
|
1136 |
List( |
|
1137 |
new Table_Status(private_data.ml_statistics_table) { |
|
1138 |
override def update_db(db: SQL.Database, log_file: Log_File): Unit = |
|
1139 |
private_data.update_ml_statistics(db, cache.compress, log_file.name, |
|
1140 |
log_file.parse_build_info(ml_statistics = true)) |
|
1141 |
}) |
|
1142 |
} |
|
1143 |
else Nil |
|
1144 |
val status2 = |
|
1145 |
List( |
|
1146 |
new Table_Status(private_data.meta_info_table) { |
|
1147 |
override def update_db(db: SQL.Database, log_file: Log_File): Unit = |
|
1148 |
private_data.update_meta_info(db, log_file.name, log_file.parse_meta_info()) |
|
1149 |
}, |
|
1150 |
new Table_Status(private_data.sessions_table) { |
|
1151 |
override def update_db(db: SQL.Database, log_file: Log_File): Unit = |
|
1152 |
private_data.update_sessions(db, cache.compress, log_file.name, |
|
1153 |
log_file.parse_build_info()) |
|
1154 |
}, |
|
1155 |
new Table_Status(private_data.theories_table) { |
|
1156 |
override def update_db(db: SQL.Database, log_file: Log_File): Unit = |
|
1157 |
private_data.update_theories(db, log_file.name, log_file.parse_build_info()) |
|
1158 |
}) |
|
1159 |
status1 ::: status2 |
|
78859
aeb511a520f4
performance tuning: more careful database access;
wenzelm
parents:
78858
diff
changeset
|
1160 |
} |
65642 | 1161 |
|
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1162 |
val consumer = |
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1163 |
Consumer_Thread.fork[Log_File]("build_log_database")( |
78880 | 1164 |
limit = 1, |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1165 |
consume = { log_file => |
78877
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1166 |
val t0 = progress.start.time |
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1167 |
val t1 = progress.now().time |
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1168 |
|
79063 | 1169 |
private_data.transaction_lock(db, label = "build_log_database.consumer") { |
78862
cc8391b92747
clarified database transactions (see also 2c704ae04db1, 7bd0a250183b);
wenzelm
parents:
78859
diff
changeset
|
1170 |
try { status.foreach(_.update(log_file)) } |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1171 |
catch { case exn: Throwable => add_error(log_file.name, exn) } |
78862
cc8391b92747
clarified database transactions (see also 2c704ae04db1, 7bd0a250183b);
wenzelm
parents:
78859
diff
changeset
|
1172 |
} |
78877
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1173 |
|
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1174 |
val t2 = progress.now().time |
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1175 |
|
78880 | 1176 |
progress.echo(verbose = true, msg = |
1177 |
"Log " + quote(log_file.name) + " (" + |
|
1178 |
(t1 - t0).message_hms + " start time, " + |
|
1179 |
(t2 - t1).message + " elapsed time)") |
|
78877
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1180 |
|
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1181 |
true |
78880 | 1182 |
}) |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1183 |
|
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1184 |
try { |
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1185 |
for (file <- files.iterator if status.exists(_.required(file))) { |
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78984
diff
changeset
|
1186 |
Exn.result { Log_File.read(file, cache = cache) } match { |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1187 |
case Exn.Res(log_file) => consumer.send(log_file) |
78877
45d570945fe4
more detailed progress for build_log_database, to see better what happens when;
wenzelm
parents:
78875
diff
changeset
|
1188 |
case Exn.Exn(exn) => add_error(Log_File.plain_name(file), exn) |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1189 |
} |
77748 | 1190 |
} |
65642 | 1191 |
} |
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1192 |
finally { consumer.shutdown() } |
77745 | 1193 |
|
78866
1bd52b048f8e
more parallelism via consumer thread: with mailbox limit to avoid ressource problems;
wenzelm
parents:
78863
diff
changeset
|
1194 |
errors_result.value |
65605 | 1195 |
} |
65595 | 1196 |
} |
77744 | 1197 |
|
1198 |
||
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1199 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1200 |
/** build history **/ |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1201 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1202 |
object History { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1203 |
sealed case class Entry( |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1204 |
known: Boolean, |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1205 |
isabelle_version: String, |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1206 |
afp_version: Option[String], |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1207 |
pull_date: Date |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1208 |
) { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1209 |
def unknown: Boolean = !known |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1210 |
def versions: (String, Option[String]) = (isabelle_version, afp_version) |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1211 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1212 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1213 |
object Run { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1214 |
val empty: Run = Run() |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1215 |
def longest(runs: List[Run]): Run = runs.foldLeft(empty)(_ max _) |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1216 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1217 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1218 |
sealed case class Run(entries: List[Entry] = Nil) { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1219 |
def is_empty: Boolean = entries.isEmpty |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1220 |
val length: Int = entries.length |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1221 |
def max(other: Run): Run = if (length >= other.length) this else other |
79009
3641cd880bb3
clarified operation: pick current pull_date instead of previous one;
wenzelm
parents:
78995
diff
changeset
|
1222 |
def median: Option[Entry] = |
3641cd880bb3
clarified operation: pick current pull_date instead of previous one;
wenzelm
parents:
78995
diff
changeset
|
1223 |
if (is_empty) None else Some(entries((length - 1) / 2)) |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1224 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1225 |
override def toString: String = { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1226 |
val s = if (is_empty) "" else "length = " + length + ", median = " + median.get.pull_date |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1227 |
"Build_Log.History.Run(" + s + ")" |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1228 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1229 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1230 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1231 |
def retrieve( |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1232 |
db: SQL.Database, |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1233 |
days: Int, |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1234 |
rev: String, |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1235 |
afp_rev: Option[String], |
78995
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1236 |
sql: PostgreSQL.Source, |
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1237 |
filter: Entry => Boolean = _ => true |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1238 |
): History = { |
79061 | 1239 |
val entries = private_data.transaction_lock(db, label = "Build_Log.History.retrieve") { |
1240 |
val afp = afp_rev.isDefined |
|
1241 |
val select_recent_versions = { |
|
1242 |
val table1 = private_data.recent_pull_date_table(days = days, rev = rev, afp_rev = afp_rev) |
|
1243 |
val table2 = private_data.meta_info_table |
|
1244 |
val aux_table = SQL.Table("aux", table2.columns, table2.select(sql = SQL.where(sql))) |
|
79011 | 1245 |
|
79061 | 1246 |
val columns = |
1247 |
table1.columns.map(c => c(table1)) ::: |
|
79064 | 1248 |
List(Column.known.copy(expr = Column.log_name(aux_table).defined)) |
79011 | 1249 |
|
79061 | 1250 |
SQL.select(columns, distinct = true) + |
1251 |
table1.query_named + SQL.join_outer + aux_table.query_named + |
|
1252 |
" ON " + Prop.isabelle_version(table1) + " = " + Prop.isabelle_version(aux_table) + |
|
79064 | 1253 |
SQL.order_by(List(Column.pull_date(afp)(table1)), descending = true) |
79061 | 1254 |
} |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1255 |
|
79011 | 1256 |
db.execute_query_statement(select_recent_versions, List.from[Entry], |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1257 |
{ res => |
79064 | 1258 |
val known = res.bool(Column.known) |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1259 |
val isabelle_version = res.string(Prop.isabelle_version) |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1260 |
val afp_version = if (afp) proper_string(res.string(Prop.afp_version)) else None |
79064 | 1261 |
val pull_date = res.date(Column.pull_date(afp)) |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1262 |
Entry(known, isabelle_version, afp_version, pull_date) |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1263 |
}) |
79061 | 1264 |
} |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1265 |
|
78995
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1266 |
new History(entries.filter(filter)) |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1267 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1268 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1269 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1270 |
final class History private(val entries: List[History.Entry]) { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1271 |
override def toString: String = "Build_Log.History(" + entries.length + ")" |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1272 |
|
78995
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1273 |
def unknown_runs(filter: History.Run => Boolean = _ => true): List[History.Run] = { |
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1274 |
var rest = entries |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1275 |
val result = new mutable.ListBuffer[History.Run] |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1276 |
while (rest.nonEmpty) { |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1277 |
val (a, b) = Library.take_prefix[History.Entry](_.unknown, rest.dropWhile(_.known)) |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1278 |
val run = History.Run(a) |
78995
b9d59669904a
clarified signature: more operations and options concerning Isabelle hg;
wenzelm
parents:
78992
diff
changeset
|
1279 |
if (!run.is_empty && filter(run)) result += run |
78991
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1280 |
rest = b |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1281 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1282 |
result.toList |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1283 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1284 |
} |
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1285 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1286 |
|
ae2f5fd0bb5d
clarified signature and modules: more explicit Build_Log.History;
wenzelm
parents:
78985
diff
changeset
|
1287 |
|
77749 | 1288 |
/** maintain build_log database **/ |
77744 | 1289 |
|
78857 | 1290 |
def build_log_database(options: Options, logs: List[Path], |
77748 | 1291 |
progress: Progress = new Progress, |
77751 | 1292 |
vacuum: Boolean = false, |
77748 | 1293 |
ml_statistics: Boolean = false, |
77744 | 1294 |
snapshot: Option[Path] = None |
1295 |
): Unit = { |
|
1296 |
val store = Build_Log.store(options) |
|
77745 | 1297 |
|
78857 | 1298 |
val log_files = Log_File.find_files(logs.map(_.file)) |
77745 | 1299 |
|
77744 | 1300 |
using(store.open_database()) { db => |
77751 | 1301 |
if (vacuum) db.vacuum() |
77748 | 1302 |
|
1303 |
progress.echo("Updating database " + db + " ...") |
|
1304 |
val errors = |
|
78878
d03bbdd9e735
just one pass is sufficient (see also cc8391b92747, 3e8a897042d9);
wenzelm
parents:
78877
diff
changeset
|
1305 |
store.write_info(db, log_files, ml_statistics = ml_statistics, progress = progress) |
77748 | 1306 |
|
1307 |
if (errors.isEmpty) { |
|
1308 |
for (path <- snapshot) { |
|
78894 | 1309 |
progress.echo("Writing database snapshot " + path.expand) |
77748 | 1310 |
store.snapshot_database(db, path) |
1311 |
} |
|
1312 |
} |
|
1313 |
else { |
|
1314 |
error(cat_lines(List.from( |
|
77750 | 1315 |
for ((name, rev_errs) <- errors.iterator_list) yield { |
1316 |
val err = "The error(s) above occurred in " + quote(name) |
|
1317 |
cat_lines((err :: rev_errs).reverse) |
|
1318 |
} |
|
1319 |
))) |
|
77748 | 1320 |
} |
77744 | 1321 |
} |
1322 |
} |
|
77749 | 1323 |
|
1324 |
||
1325 |
/* Isabelle tool wrapper */ |
|
1326 |
||
1327 |
val isabelle_tool = Isabelle_Tool("build_log_database", "update build_log database from log files", |
|
1328 |
Scala_Project.here, |
|
1329 |
{ args => |
|
1330 |
var ml_statistics: Boolean = false |
|
1331 |
var snapshot: Option[Path] = None |
|
77751 | 1332 |
var vacuum = false |
78858 | 1333 |
var logs: List[Path] = Nil |
77749 | 1334 |
var options = Options.init() |
1335 |
var verbose = false |
|
1336 |
||
1337 |
val getopts = Getopts(""" |
|
1338 |
Usage: isabelle build_log_database [OPTIONS] |
|
1339 |
||
1340 |
Options are: |
|
1341 |
-M include ML statistics |
|
1342 |
-S FILE snapshot to SQLite db file |
|
77751 | 1343 |
-V vacuum cleaning of database |
78858 | 1344 |
-d LOG include log file start location |
77749 | 1345 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
1346 |
-v verbose |
|
1347 |
||
78858 | 1348 |
Update the build_log database server from log files, which are recursively |
1349 |
collected from given start locations (files or directories). |
|
77749 | 1350 |
""", |
1351 |
"M" -> (_ => ml_statistics = true), |
|
1352 |
"S:" -> (arg => snapshot = Some(Path.explode(arg))), |
|
77751 | 1353 |
"V" -> (_ => vacuum = true), |
78858 | 1354 |
"d:" -> (arg => logs = logs ::: List(Path.explode(arg))), |
77749 | 1355 |
"o:" -> (arg => options = options + arg), |
1356 |
"v" -> (_ => verbose = true)) |
|
1357 |
||
1358 |
val more_args = getopts(args) |
|
1359 |
if (more_args.nonEmpty) getopts.usage() |
|
1360 |
||
1361 |
val progress = new Console_Progress(verbose = verbose) |
|
1362 |
||
78858 | 1363 |
build_log_database(options, logs, progress = progress, vacuum = vacuum, |
77749 | 1364 |
ml_statistics = ml_statistics, snapshot = snapshot) |
1365 |
}) |
|
64045 | 1366 |
} |