| author | wenzelm |
| Mon, 03 Apr 2017 21:17:47 +0200 | |
| changeset 65362 | 908a27a4b9c9 |
| parent 65360 | 3ff88fece1f6 |
| child 65371 | ce09e947c1d5 |
| permissions | -rw-r--r-- |
| 62631 | 1 |
/* Title: Pure/Thy/sessions.scala |
2 |
Author: Makarius |
|
3 |
||
| 62973 | 4 |
Isabelle session information. |
| 62631 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
9 |
import java.nio.ByteBuffer |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
10 |
import java.nio.channels.FileChannel |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
11 |
import java.nio.file.StandardOpenOption |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
12 |
import java.sql.PreparedStatement |
| 62631 | 13 |
|
14 |
import scala.collection.SortedSet |
|
15 |
import scala.collection.mutable |
|
16 |
||
17 |
||
18 |
object Sessions |
|
19 |
{
|
|
| 65360 | 20 |
/* base info and source dependencies */ |
| 62883 | 21 |
|
| 65360 | 22 |
def is_pure(name: String): Boolean = name == Thy_Header.PURE |
| 64856 | 23 |
|
24 |
object Base |
|
25 |
{
|
|
| 65360 | 26 |
def pure(options: Options): Base = session_base(options, Thy_Header.PURE) |
27 |
||
| 64856 | 28 |
lazy val bootstrap: Base = |
29 |
Base(keywords = Thy_Header.bootstrap_header, syntax = Thy_Header.bootstrap_syntax) |
|
30 |
} |
|
31 |
||
32 |
sealed case class Base( |
|
33 |
loaded_theories: Set[String] = Set.empty, |
|
34 |
known_theories: Map[String, Document.Node.Name] = Map.empty, |
|
35 |
keywords: Thy_Header.Keywords = Nil, |
|
36 |
syntax: Outer_Syntax = Outer_Syntax.empty, |
|
37 |
sources: List[(Path, SHA1.Digest)] = Nil, |
|
38 |
session_graph: Graph_Display.Graph = Graph_Display.empty_graph) |
|
| 65355 | 39 |
{
|
40 |
def loaded_theory(name: Document.Node.Name): Boolean = |
|
41 |
loaded_theories.contains(name.theory) |
|
42 |
} |
|
| 64856 | 43 |
|
| 65251 | 44 |
sealed case class Deps(deps: Map[String, Base]) |
45 |
{
|
|
46 |
def is_empty: Boolean = deps.isEmpty |
|
47 |
def apply(name: String): Base = deps(name) |
|
48 |
def sources(name: String): List[SHA1.Digest] = deps(name).sources.map(_._2) |
|
49 |
} |
|
| 64856 | 50 |
|
| 65251 | 51 |
def dependencies( |
52 |
progress: Progress = No_Progress, |
|
53 |
inlined_files: Boolean = false, |
|
54 |
verbose: Boolean = false, |
|
55 |
list_files: Boolean = false, |
|
56 |
check_keywords: Set[String] = Set.empty, |
|
57 |
tree: Tree): Deps = |
|
58 |
Deps((Map.empty[String, Base] /: tree.topological_order)( |
|
59 |
{ case (deps, (name, info)) =>
|
|
60 |
if (progress.stopped) throw Exn.Interrupt() |
|
61 |
||
62 |
try {
|
|
| 65359 | 63 |
val parent_base = |
64 |
info.parent match {
|
|
65 |
case None => Base.bootstrap |
|
66 |
case Some(parent) => deps(parent) |
|
67 |
} |
|
68 |
val resources = new Resources(name, parent_base) |
|
| 65251 | 69 |
|
70 |
if (verbose || list_files) {
|
|
71 |
val groups = |
|
72 |
if (info.groups.isEmpty) "" |
|
73 |
else info.groups.mkString(" (", " ", ")")
|
|
74 |
progress.echo("Session " + info.chapter + "/" + name + groups)
|
|
75 |
} |
|
76 |
||
77 |
val thy_deps = |
|
78 |
{
|
|
79 |
val root_theories = |
|
80 |
info.theories.flatMap({
|
|
81 |
case (global, _, thys) => |
|
82 |
thys.map(thy => |
|
| 65359 | 83 |
(resources.init_name(global, info.dir + resources.thy_path(thy)), info.pos)) |
| 65251 | 84 |
}) |
| 65359 | 85 |
val thy_deps = resources.thy_info.dependencies(root_theories) |
| 65251 | 86 |
|
87 |
thy_deps.errors match {
|
|
88 |
case Nil => thy_deps |
|
89 |
case errs => error(cat_lines(errs)) |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
val known_theories = |
|
| 65359 | 94 |
(parent_base.known_theories /: thy_deps.deps)({ case (known, dep) =>
|
| 65251 | 95 |
val name = dep.name |
96 |
known.get(name.theory) match {
|
|
97 |
case Some(name1) if name != name1 => |
|
98 |
error("Duplicate theory " + quote(name.node) + " vs. " + quote(name1.node))
|
|
99 |
case _ => |
|
100 |
known + (name.theory -> name) + (Long_Name.base_name(name.theory) -> name) |
|
101 |
} |
|
102 |
}) |
|
103 |
||
104 |
val loaded_theories = thy_deps.loaded_theories |
|
105 |
val keywords = thy_deps.keywords |
|
106 |
val syntax = thy_deps.syntax |
|
107 |
||
108 |
val theory_files = thy_deps.deps.map(dep => Path.explode(dep.name.node)) |
|
109 |
val loaded_files = |
|
110 |
if (inlined_files) {
|
|
111 |
val pure_files = |
|
| 65360 | 112 |
if (is_pure(name)) {
|
113 |
val roots = Thy_Header.ml_roots.map(p => info.dir + Path.explode(p._1)) |
|
114 |
val files = |
|
115 |
roots.flatMap(root => resources.loaded_files(syntax, File.read(root))). |
|
116 |
map(file => info.dir + Path.explode(file)) |
|
117 |
roots ::: files |
|
118 |
} |
|
| 65251 | 119 |
else Nil |
120 |
pure_files ::: thy_deps.loaded_files |
|
121 |
} |
|
122 |
else Nil |
|
123 |
||
124 |
val all_files = |
|
125 |
(theory_files ::: loaded_files ::: |
|
126 |
info.files.map(file => info.dir + file) ::: |
|
127 |
info.document_files.map(file => info.dir + file._1 + file._2)).map(_.expand) |
|
128 |
||
129 |
if (list_files) |
|
130 |
progress.echo(cat_lines(all_files.map(_.implode).sorted.map(" " + _)))
|
|
131 |
||
132 |
if (check_keywords.nonEmpty) |
|
133 |
Check_Keywords.check_keywords(progress, syntax.keywords, check_keywords, theory_files) |
|
134 |
||
135 |
val sources = all_files.map(p => (p, SHA1.digest(p.file))) |
|
136 |
||
137 |
val session_graph = |
|
138 |
Present.session_graph(info.parent getOrElse "", |
|
| 65359 | 139 |
parent_base.loaded_theories, thy_deps.deps) |
| 65251 | 140 |
|
141 |
val base = |
|
142 |
Base(loaded_theories, known_theories, keywords, syntax, sources, session_graph) |
|
143 |
deps + (name -> base) |
|
144 |
} |
|
145 |
catch {
|
|
146 |
case ERROR(msg) => |
|
147 |
cat_error(msg, "The error(s) above occurred in session " + |
|
148 |
quote(name) + Position.here(info.pos)) |
|
149 |
} |
|
150 |
})) |
|
151 |
||
152 |
def session_base(options: Options, session: String, dirs: List[Path] = Nil): Base = |
|
153 |
{
|
|
154 |
val (_, tree) = load(options, dirs = dirs).selection(sessions = List(session)) |
|
155 |
dependencies(tree = tree)(session) |
|
156 |
} |
|
157 |
||
158 |
||
159 |
/* session tree */ |
|
| 62631 | 160 |
|
161 |
sealed case class Info( |
|
162 |
chapter: String, |
|
163 |
select: Boolean, |
|
164 |
pos: Position.T, |
|
165 |
groups: List[String], |
|
166 |
dir: Path, |
|
167 |
parent: Option[String], |
|
168 |
description: String, |
|
169 |
options: Options, |
|
170 |
theories: List[(Boolean, Options, List[Path])], |
|
171 |
files: List[Path], |
|
172 |
document_files: List[(Path, Path)], |
|
173 |
meta_digest: SHA1.Digest) |
|
174 |
{
|
|
175 |
def timeout: Time = Time.seconds(options.real("timeout") * options.real("timeout_scale"))
|
|
176 |
} |
|
177 |
||
178 |
object Tree |
|
179 |
{
|
|
180 |
def apply(infos: Seq[(String, Info)]): Tree = |
|
181 |
{
|
|
182 |
val graph1 = |
|
183 |
(Graph.string[Info] /: infos) {
|
|
184 |
case (graph, (name, info)) => |
|
185 |
if (graph.defined(name)) |
|
186 |
error("Duplicate session " + quote(name) + Position.here(info.pos) +
|
|
187 |
Position.here(graph.get_node(name).pos)) |
|
188 |
else graph.new_node(name, info) |
|
189 |
} |
|
190 |
val graph2 = |
|
191 |
(graph1 /: graph1.iterator) {
|
|
192 |
case (graph, (name, (info, _))) => |
|
193 |
info.parent match {
|
|
194 |
case None => graph |
|
195 |
case Some(parent) => |
|
196 |
if (!graph.defined(parent)) |
|
197 |
error("Bad parent session " + quote(parent) + " for " +
|
|
198 |
quote(name) + Position.here(info.pos)) |
|
199 |
||
200 |
try { graph.add_edge_acyclic(parent, name) }
|
|
201 |
catch {
|
|
202 |
case exn: Graph.Cycles[_] => |
|
203 |
error(cat_lines(exn.cycles.map(cycle => |
|
204 |
"Cyclic session dependency of " + |
|
205 |
cycle.map(c => quote(c.toString)).mkString(" via "))) +
|
|
206 |
Position.here(info.pos)) |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
new Tree(graph2) |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
final class Tree private(val graph: Graph[String, Info]) |
|
215 |
extends PartialFunction[String, Info] |
|
216 |
{
|
|
217 |
def apply(name: String): Info = graph.get_node(name) |
|
218 |
def isDefinedAt(name: String): Boolean = graph.defined(name) |
|
219 |
||
220 |
def selection( |
|
221 |
requirements: Boolean = false, |
|
222 |
all_sessions: Boolean = false, |
|
223 |
exclude_session_groups: List[String] = Nil, |
|
224 |
exclude_sessions: List[String] = Nil, |
|
225 |
session_groups: List[String] = Nil, |
|
226 |
sessions: List[String] = Nil): (List[String], Tree) = |
|
227 |
{
|
|
228 |
val bad_sessions = |
|
229 |
SortedSet((exclude_sessions ::: sessions).filterNot(isDefinedAt(_)): _*).toList |
|
230 |
if (bad_sessions.nonEmpty) error("Undefined session(s): " + commas_quote(bad_sessions))
|
|
231 |
||
232 |
val excluded = |
|
233 |
{
|
|
234 |
val exclude_group = exclude_session_groups.toSet |
|
235 |
val exclude_group_sessions = |
|
236 |
(for {
|
|
237 |
(name, (info, _)) <- graph.iterator |
|
238 |
if apply(name).groups.exists(exclude_group) |
|
239 |
} yield name).toList |
|
240 |
graph.all_succs(exclude_group_sessions ::: exclude_sessions).toSet |
|
241 |
} |
|
242 |
||
243 |
val pre_selected = |
|
244 |
{
|
|
245 |
if (all_sessions) graph.keys |
|
246 |
else {
|
|
247 |
val select_group = session_groups.toSet |
|
248 |
val select = sessions.toSet |
|
249 |
(for {
|
|
250 |
(name, (info, _)) <- graph.iterator |
|
251 |
if info.select || select(name) || apply(name).groups.exists(select_group) |
|
252 |
} yield name).toList |
|
253 |
} |
|
254 |
}.filterNot(excluded) |
|
255 |
||
256 |
val selected = |
|
257 |
if (requirements) (graph.all_preds(pre_selected).toSet -- pre_selected).toList |
|
258 |
else pre_selected |
|
259 |
||
260 |
val graph1 = graph.restrict(graph.all_preds(selected).toSet) |
|
261 |
(selected, new Tree(graph1)) |
|
262 |
} |
|
263 |
||
264 |
def ancestors(name: String): List[String] = |
|
265 |
graph.all_preds(List(name)).tail.reverse |
|
266 |
||
267 |
def topological_order: List[(String, Info)] = |
|
268 |
graph.topological_order.map(name => (name, apply(name))) |
|
269 |
||
270 |
override def toString: String = graph.keys_iterator.mkString("Sessions.Tree(", ", ", ")")
|
|
271 |
} |
|
272 |
||
273 |
||
274 |
/* parser */ |
|
275 |
||
| 62864 | 276 |
val ROOT = Path.explode("ROOT")
|
277 |
val ROOTS = Path.explode("ROOTS")
|
|
278 |
||
| 62631 | 279 |
private val CHAPTER = "chapter" |
280 |
private val SESSION = "session" |
|
281 |
private val IN = "in" |
|
282 |
private val DESCRIPTION = "description" |
|
283 |
private val OPTIONS = "options" |
|
284 |
private val GLOBAL_THEORIES = "global_theories" |
|
285 |
private val THEORIES = "theories" |
|
286 |
private val FILES = "files" |
|
287 |
private val DOCUMENT_FILES = "document_files" |
|
288 |
||
289 |
lazy val root_syntax = |
|
| 63443 | 290 |
Outer_Syntax.init() + "(" + ")" + "+" + "," + "=" + "[" + "]" + IN +
|
291 |
(CHAPTER, Keyword.THY_DECL) + |
|
292 |
(SESSION, Keyword.THY_DECL) + |
|
293 |
(DESCRIPTION, Keyword.QUASI_COMMAND) + |
|
294 |
(OPTIONS, Keyword.QUASI_COMMAND) + |
|
295 |
(GLOBAL_THEORIES, Keyword.QUASI_COMMAND) + |
|
296 |
(THEORIES, Keyword.QUASI_COMMAND) + |
|
297 |
(FILES, Keyword.QUASI_COMMAND) + |
|
298 |
(DOCUMENT_FILES, Keyword.QUASI_COMMAND) |
|
| 62631 | 299 |
|
| 62968 | 300 |
private object Parser extends Parse.Parser with Options.Parser |
| 62631 | 301 |
{
|
302 |
private abstract class Entry |
|
303 |
private sealed case class Chapter(name: String) extends Entry |
|
304 |
private sealed case class Session_Entry( |
|
305 |
pos: Position.T, |
|
306 |
name: String, |
|
307 |
groups: List[String], |
|
308 |
path: String, |
|
309 |
parent: Option[String], |
|
310 |
description: String, |
|
311 |
options: List[Options.Spec], |
|
312 |
theories: List[(Boolean, List[Options.Spec], List[String])], |
|
313 |
files: List[String], |
|
314 |
document_files: List[(String, String)]) extends Entry |
|
315 |
||
316 |
private val chapter: Parser[Chapter] = |
|
317 |
{
|
|
318 |
val chapter_name = atom("chapter name", _.is_name)
|
|
319 |
||
320 |
command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) }
|
|
321 |
} |
|
322 |
||
323 |
private val session_entry: Parser[Session_Entry] = |
|
324 |
{
|
|
325 |
val session_name = atom("session name", _.is_name)
|
|
326 |
||
327 |
val option = |
|
| 62968 | 328 |
option_name ~ opt($$$("=") ~! option_value ^^
|
329 |
{ case _ ~ x => x }) ^^ { case x ~ y => (x, y) }
|
|
| 62631 | 330 |
val options = $$$("[") ~> rep1sep(option, $$$(",")) <~ $$$("]")
|
331 |
||
332 |
val theories = |
|
333 |
($$$(GLOBAL_THEORIES) | $$$(THEORIES)) ~! |
|
| 62969 | 334 |
((options | success(Nil)) ~ rep(theory_name)) ^^ |
| 62631 | 335 |
{ case x ~ (y ~ z) => (x == GLOBAL_THEORIES, y, z) }
|
336 |
||
337 |
val document_files = |
|
338 |
$$$(DOCUMENT_FILES) ~! |
|
339 |
(($$$("(") ~! ($$$(IN) ~! (path ~ $$$(")"))) ^^
|
|
340 |
{ case _ ~ (_ ~ (x ~ _)) => x } | success("document")) ~
|
|
341 |
rep1(path)) ^^ { case _ ~ (x ~ y) => y.map((x, _)) }
|
|
342 |
||
343 |
command(SESSION) ~! |
|
344 |
(position(session_name) ~ |
|
345 |
(($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
346 |
(($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~
|
|
347 |
($$$("=") ~!
|
|
348 |
(opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~
|
|
349 |
(($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~
|
|
350 |
(($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
351 |
rep1(theories) ~ |
|
352 |
(($$$(FILES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
353 |
(rep(document_files) ^^ (x => x.flatten))))) ^^ |
|
354 |
{ case _ ~ ((a, pos) ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h ~ i))) =>
|
|
355 |
Session_Entry(pos, a, b, c, d, e, f, g, h, i) } |
|
356 |
} |
|
357 |
||
358 |
def parse(options: Options, select: Boolean, dir: Path): List[(String, Info)] = |
|
359 |
{
|
|
360 |
def make_info(entry_chapter: String, entry: Session_Entry): (String, Info) = |
|
361 |
{
|
|
362 |
try {
|
|
363 |
val name = entry.name |
|
364 |
||
365 |
if (name == "") error("Bad session name")
|
|
| 65360 | 366 |
if (is_pure(name) && entry.parent.isDefined) error("Illegal parent session")
|
367 |
if (!is_pure(name) && !entry.parent.isDefined) error("Missing parent session")
|
|
| 62631 | 368 |
|
369 |
val session_options = options ++ entry.options |
|
370 |
||
371 |
val theories = |
|
372 |
entry.theories.map({ case (global, opts, thys) =>
|
|
373 |
(global, session_options ++ opts, thys.map(Path.explode(_))) }) |
|
374 |
val files = entry.files.map(Path.explode(_)) |
|
375 |
val document_files = |
|
376 |
entry.document_files.map({ case (s1, s2) => (Path.explode(s1), Path.explode(s2)) })
|
|
377 |
||
378 |
val meta_digest = |
|
379 |
SHA1.digest((entry_chapter, name, entry.parent, entry.options, |
|
380 |
entry.theories, entry.files, entry.document_files).toString) |
|
381 |
||
382 |
val info = |
|
383 |
Info(entry_chapter, select, entry.pos, entry.groups, dir + Path.explode(entry.path), |
|
384 |
entry.parent, entry.description, session_options, theories, files, |
|
385 |
document_files, meta_digest) |
|
386 |
||
387 |
(name, info) |
|
388 |
} |
|
389 |
catch {
|
|
390 |
case ERROR(msg) => |
|
391 |
error(msg + "\nThe error(s) above occurred in session entry " + |
|
392 |
quote(entry.name) + Position.here(entry.pos)) |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
val root = dir + ROOT |
|
397 |
if (root.is_file) {
|
|
398 |
val toks = Token.explode(root_syntax.keywords, File.read(root)) |
|
399 |
val start = Token.Pos.file(root.implode) |
|
400 |
||
401 |
parse_all(rep(chapter | session_entry), Token.reader(toks, start)) match {
|
|
402 |
case Success(result, _) => |
|
403 |
var entry_chapter = "Unsorted" |
|
404 |
val infos = new mutable.ListBuffer[(String, Info)] |
|
405 |
result.foreach {
|
|
406 |
case Chapter(name) => entry_chapter = name |
|
407 |
case entry: Session_Entry => infos += make_info(entry_chapter, entry) |
|
408 |
} |
|
409 |
infos.toList |
|
410 |
case bad => error(bad.toString) |
|
411 |
} |
|
412 |
} |
|
413 |
else Nil |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
||
| 62635 | 418 |
/* load sessions from certain directories */ |
| 62631 | 419 |
|
420 |
private def is_session_dir(dir: Path): Boolean = |
|
421 |
(dir + ROOT).is_file || (dir + ROOTS).is_file |
|
422 |
||
423 |
private def check_session_dir(dir: Path): Path = |
|
424 |
if (is_session_dir(dir)) dir |
|
425 |
else error("Bad session root directory: " + dir.toString)
|
|
426 |
||
| 62635 | 427 |
def load(options: Options, dirs: List[Path] = Nil, select_dirs: List[Path] = Nil): Tree = |
| 62631 | 428 |
{
|
| 62635 | 429 |
def load_dir(select: Boolean, dir: Path): List[(String, Info)] = |
430 |
load_root(select, dir) ::: load_roots(select, dir) |
|
| 62631 | 431 |
|
| 62635 | 432 |
def load_root(select: Boolean, dir: Path): List[(String, Info)] = |
| 62631 | 433 |
Parser.parse(options, select, dir) |
434 |
||
| 62635 | 435 |
def load_roots(select: Boolean, dir: Path): List[(String, Info)] = |
| 62631 | 436 |
{
|
437 |
val roots = dir + ROOTS |
|
438 |
if (roots.is_file) {
|
|
439 |
for {
|
|
440 |
line <- split_lines(File.read(roots)) |
|
441 |
if !(line == "" || line.startsWith("#"))
|
|
442 |
dir1 = |
|
443 |
try { check_session_dir(dir + Path.explode(line)) }
|
|
444 |
catch {
|
|
445 |
case ERROR(msg) => |
|
446 |
error(msg + "\nThe error(s) above occurred in session catalog " + roots.toString) |
|
447 |
} |
|
| 62635 | 448 |
info <- load_dir(select, dir1) |
| 62631 | 449 |
} yield info |
450 |
} |
|
451 |
else Nil |
|
452 |
} |
|
453 |
||
454 |
val default_dirs = Isabelle_System.components().filter(is_session_dir(_)) |
|
455 |
dirs.foreach(check_session_dir(_)) |
|
456 |
select_dirs.foreach(check_session_dir(_)) |
|
457 |
||
458 |
Tree( |
|
459 |
for {
|
|
460 |
(select, dir) <- (default_dirs ::: dirs).map((false, _)) ::: select_dirs.map((true, _)) |
|
| 62635 | 461 |
info <- load_dir(select, dir) |
| 62631 | 462 |
} yield info) |
463 |
} |
|
| 62632 | 464 |
|
465 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
466 |
|
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
467 |
/** heap file with SHA1 digest **/ |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
468 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
469 |
private val sha1_prefix = "SHA1:" |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
470 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
471 |
def read_heap_digest(heap: Path): Option[String] = |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
472 |
{
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
473 |
if (heap.is_file) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
474 |
val file = FileChannel.open(heap.file.toPath, StandardOpenOption.READ) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
475 |
try {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
476 |
val len = file.size |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
477 |
val n = sha1_prefix.length + SHA1.digest_length |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
478 |
if (len >= n) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
479 |
file.position(len - n) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
480 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
481 |
val buf = ByteBuffer.allocate(n) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
482 |
var i = 0 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
483 |
var m = 0 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
484 |
do {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
485 |
m = file.read(buf) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
486 |
if (m != -1) i += m |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
487 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
488 |
while (m != -1 && n > i) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
489 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
490 |
if (i == n) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
491 |
val prefix = new String(buf.array(), 0, sha1_prefix.length, UTF8.charset) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
492 |
val s = new String(buf.array(), sha1_prefix.length, SHA1.digest_length, UTF8.charset) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
493 |
if (prefix == sha1_prefix) Some(s) else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
494 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
495 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
496 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
497 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
498 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
499 |
finally { file.close }
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
500 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
501 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
502 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
503 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
504 |
def write_heap_digest(heap: Path): String = |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
505 |
read_heap_digest(heap) match {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
506 |
case None => |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
507 |
val s = SHA1.digest(heap).rep |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
508 |
File.append(heap, sha1_prefix + s) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
509 |
s |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
510 |
case Some(s) => s |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
511 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
512 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
513 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
514 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
515 |
/** persistent store **/ |
| 62632 | 516 |
|
| 65296 | 517 |
object Session_Info |
518 |
{
|
|
| 65326 | 519 |
val session_name = SQL.Column.string("session_name", primary_key = true)
|
520 |
||
| 65296 | 521 |
// Build_Log.Session_Info |
522 |
val session_timing = SQL.Column.bytes("session_timing")
|
|
523 |
val command_timings = SQL.Column.bytes("command_timings")
|
|
524 |
val ml_statistics = SQL.Column.bytes("ml_statistics")
|
|
525 |
val task_statistics = SQL.Column.bytes("task_statistics")
|
|
526 |
val build_log_columns = |
|
527 |
List(session_name, session_timing, command_timings, ml_statistics, task_statistics) |
|
528 |
||
529 |
// Build.Session_Info |
|
530 |
val sources = SQL.Column.string("sources")
|
|
531 |
val input_heaps = SQL.Column.string("input_heaps")
|
|
532 |
val output_heap = SQL.Column.string("output_heap")
|
|
533 |
val return_code = SQL.Column.int("return_code")
|
|
534 |
val build_columns = List(sources, input_heaps, output_heap, return_code) |
|
535 |
||
536 |
val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns)
|
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
537 |
|
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
538 |
def where_session_name(name: String): String = |
| 65322 | 539 |
"WHERE " + session_name.sql_name + " = " + SQL.quote_string(name) |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
540 |
|
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
541 |
def select_statement(db: SQL.Database, name: String, columns: List[SQL.Column]) |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
542 |
: PreparedStatement = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
543 |
db.select_statement(table, columns, where_session_name(name)) |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
544 |
|
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
545 |
def delete_statement(db: SQL.Database, name: String): PreparedStatement = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
546 |
db.delete_statement(table, where_session_name(name)) |
| 65296 | 547 |
} |
548 |
||
| 62632 | 549 |
def store(system_mode: Boolean = false): Store = new Store(system_mode) |
550 |
||
| 63996 | 551 |
class Store private[Sessions](system_mode: Boolean) |
| 62632 | 552 |
{
|
| 65278 | 553 |
/* file names */ |
554 |
||
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
555 |
def database(name: String): Path = Path.basic("log") + Path.basic(name).ext("db")
|
| 65278 | 556 |
def log(name: String): Path = Path.basic("log") + Path.basic(name)
|
557 |
def log_gz(name: String): Path = log(name).ext("gz")
|
|
558 |
||
559 |
||
| 65286 | 560 |
/* SQL database content */ |
| 65283 | 561 |
|
562 |
val xml_cache: XML.Cache = new XML.Cache() |
|
563 |
||
564 |
def encode_properties(ps: Properties.T): Bytes = |
|
565 |
Bytes(YXML.string_of_body(XML.Encode.properties(ps))) |
|
566 |
||
567 |
def decode_properties(bs: Bytes): Properties.T = |
|
568 |
xml_cache.props(XML.Decode.properties(YXML.parse_body(bs.text))) |
|
569 |
||
570 |
def compress_properties(ps: List[Properties.T], options: XZ.Options = XZ.options()): Bytes = |
|
571 |
{
|
|
572 |
if (ps.isEmpty) Bytes.empty |
|
573 |
else Bytes(YXML.string_of_body(XML.Encode.list(XML.Encode.properties)(ps))).compress(options) |
|
574 |
} |
|
575 |
||
576 |
def uncompress_properties(bs: Bytes): List[Properties.T] = |
|
577 |
{
|
|
578 |
if (bs.isEmpty) Nil |
|
579 |
else |
|
580 |
XML.Decode.list(XML.Decode.properties)(YXML.parse_body(bs.uncompress().text)). |
|
581 |
map(xml_cache.props(_)) |
|
582 |
} |
|
583 |
||
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
584 |
def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
585 |
using(Session_Info.select_statement(db, name, List(column)))(stmt => |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
586 |
{
|
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
587 |
val rs = stmt.executeQuery |
| 65324 | 588 |
if (!rs.next) Bytes.empty else db.bytes(rs, column) |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
589 |
}) |
| 65285 | 590 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
591 |
def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
592 |
uncompress_properties(read_bytes(db, name, column)) |
| 65286 | 593 |
|
| 65283 | 594 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
595 |
/* output */ |
| 62632 | 596 |
|
597 |
val browser_info: Path = |
|
598 |
if (system_mode) Path.explode("~~/browser_info")
|
|
599 |
else Path.explode("$ISABELLE_BROWSER_INFO")
|
|
600 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
601 |
val output_dir: Path = |
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
602 |
if (system_mode) Path.explode("~~/heaps/$ML_IDENTIFIER")
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
603 |
else Path.explode("$ISABELLE_OUTPUT")
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
604 |
|
| 65298 | 605 |
override def toString: String = "Store(output_dir = " + output_dir.expand + ")" |
606 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
607 |
def prepare_output() { Isabelle_System.mkdirs(output_dir + Path.basic("log")) }
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
608 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
609 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
610 |
/* input */ |
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
611 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
612 |
private val input_dirs = |
| 62632 | 613 |
if (system_mode) List(output_dir) |
| 62633 | 614 |
else {
|
615 |
val ml_ident = Path.explode("$ML_IDENTIFIER").expand
|
|
616 |
output_dir :: Path.split(Isabelle_System.getenv_strict("ISABELLE_PATH")).map(_ + ml_ident)
|
|
617 |
} |
|
| 62632 | 618 |
|
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
619 |
def find_database_heap(name: String): Option[(Path, Option[String])] = |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
620 |
input_dirs.find(dir => (dir + database(name)).is_file).map(dir => |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
621 |
(dir + database(name), read_heap_digest(dir + Path.basic(name)))) |
| 62632 | 622 |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
623 |
def find_database(name: String): Option[Path] = |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
624 |
input_dirs.map(_ + database(name)).find(_.is_file) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
625 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
626 |
def heap(name: String): Path = |
| 65288 | 627 |
input_dirs.map(_ + Path.basic(name)).find(_.is_file) getOrElse |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
628 |
error("Unknown logic " + quote(name) + " -- no heap file found in:\n" +
|
| 62769 | 629 |
cat_lines(input_dirs.map(dir => " " + dir.expand.implode))) |
| 65287 | 630 |
|
631 |
||
| 65296 | 632 |
/* session info */ |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
633 |
|
| 65296 | 634 |
def write_session_info( |
|
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
635 |
db: SQL.Database, |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
636 |
name: String, |
|
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
637 |
build_log: Build_Log.Session_Info, |
|
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
638 |
build: Build.Session_Info) |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
639 |
{
|
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
640 |
db.transaction {
|
| 65296 | 641 |
db.create_table(Session_Info.table) |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
642 |
using(Session_Info.delete_statement(db, name))(_.execute) |
| 65296 | 643 |
using(db.insert_statement(Session_Info.table))(stmt => |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
644 |
{
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
645 |
db.set_string(stmt, 1, name) |
| 65296 | 646 |
db.set_bytes(stmt, 2, encode_properties(build_log.session_timing)) |
647 |
db.set_bytes(stmt, 3, compress_properties(build_log.command_timings)) |
|
648 |
db.set_bytes(stmt, 4, compress_properties(build_log.ml_statistics)) |
|
649 |
db.set_bytes(stmt, 5, compress_properties(build_log.task_statistics)) |
|
| 65284 | 650 |
db.set_string(stmt, 6, cat_lines(build.sources)) |
651 |
db.set_string(stmt, 7, cat_lines(build.input_heaps)) |
|
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
652 |
db.set_string(stmt, 8, build.output_heap getOrElse "") |
| 65283 | 653 |
db.set_int(stmt, 9, build.return_code) |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
654 |
stmt.execute() |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
655 |
}) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
656 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
657 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
658 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
659 |
def read_session_timing(db: SQL.Database, name: String): Properties.T = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
660 |
decode_properties(read_bytes(db, name, Session_Info.session_timing)) |
| 65286 | 661 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
662 |
def read_command_timings(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
663 |
read_properties(db, name, Session_Info.command_timings) |
| 65286 | 664 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
665 |
def read_ml_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
666 |
read_properties(db, name, Session_Info.ml_statistics) |
| 65286 | 667 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
668 |
def read_task_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
669 |
read_properties(db, name, Session_Info.task_statistics) |
| 65286 | 670 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
671 |
def read_build_log(db: SQL.Database, name: String, |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
672 |
command_timings: Boolean = false, |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
673 |
ml_statistics: Boolean = false, |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
674 |
task_statistics: Boolean = false): Build_Log.Session_Info = |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
675 |
{
|
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
676 |
Build_Log.Session_Info( |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
677 |
session_timing = read_session_timing(db, name), |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
678 |
command_timings = if (command_timings) read_command_timings(db, name) else Nil, |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
679 |
ml_statistics = if (ml_statistics) read_ml_statistics(db, name) else Nil, |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
680 |
task_statistics = if (task_statistics) read_task_statistics(db, name) else Nil) |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
681 |
} |
| 65285 | 682 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
683 |
def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
684 |
using(Session_Info.select_statement(db, name, Session_Info.build_columns))(stmt => |
| 65285 | 685 |
{
|
686 |
val rs = stmt.executeQuery |
|
687 |
if (!rs.next) None |
|
688 |
else {
|
|
689 |
Some( |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
690 |
Build.Session_Info( |
| 65324 | 691 |
split_lines(db.string(rs, Session_Info.sources)), |
692 |
split_lines(db.string(rs, Session_Info.input_heaps)), |
|
693 |
db.string(rs, Session_Info.output_heap) match { case "" => None case s => Some(s) },
|
|
694 |
db.int(rs, Session_Info.return_code))) |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
695 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
696 |
}) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
697 |
} |
| 62631 | 698 |
} |