| author | wenzelm |
| Tue, 04 Nov 2025 22:09:26 +0100 | |
| changeset 83507 | 989304e45ad7 |
| parent 83315 | 03dfb684a50d |
| child 83509 | d17e990ebd40 |
| permissions | -rw-r--r-- |
| 61276 | 1 |
/* Title: Pure/System/progress.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Progress context for system processes. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 73897 | 10 |
import java.util.{Map => JMap}
|
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
11 |
import scala.collection.mutable |
| 64201 | 12 |
|
13 |
||
| 75393 | 14 |
object Progress {
|
| 78503 | 15 |
/* output */ |
16 |
||
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
17 |
sealed abstract class Msg {
|
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
18 |
def verbose: Boolean |
|
83285
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
19 |
def status: Boolean |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
20 |
def message: Message |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
21 |
} |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
22 |
|
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
23 |
type Output = List[Msg] |
| 83304 | 24 |
type Session_Output = List[(String, Msg)] |
| 78155 | 25 |
|
| 83284 | 26 |
def output_theory(msg: Msg): Msg = |
27 |
msg match {
|
|
28 |
case thy: Theory if thy.verbose => thy.copy(verbose = false) |
|
29 |
case _ => msg |
|
30 |
} |
|
31 |
||
| 78611 | 32 |
enum Kind { case writeln, warning, error_message }
|
| 78503 | 33 |
sealed case class Message( |
| 78611 | 34 |
kind: Kind, |
| 78503 | 35 |
text: String, |
|
83285
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
36 |
override val verbose: Boolean = false, |
|
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
37 |
override val status: Boolean = false |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
38 |
) extends Msg {
|
| 78503 | 39 |
override def message: Message = this |
40 |
||
| 83270 | 41 |
lazy val output_text: String = |
|
77502
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
42 |
kind match {
|
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
43 |
case Kind.writeln => Output.writeln_text(text) |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
44 |
case Kind.warning => Output.warning_text(text) |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
45 |
case Kind.error_message => Output.error_message_text(text) |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
46 |
} |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
47 |
|
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
48 |
override def toString: String = output_text |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
49 |
} |
|
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
50 |
|
| 78503 | 51 |
sealed case class Theory( |
52 |
theory: String, |
|
53 |
session: String = "", |
|
| 83223 | 54 |
percentage: Option[Int] = None, |
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83286
diff
changeset
|
55 |
cumulated_time: Time = Time.zero, |
|
83285
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
56 |
override val verbose: Boolean = true, |
|
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
57 |
override val status: Boolean = false |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
58 |
) extends Msg {
|
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
59 |
override def message: Message = |
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83286
diff
changeset
|
60 |
Message(Kind.writeln, print_session + print_theory + print_percentage + print_cumulated_time, |
|
83285
ec2bd302560c
support explicit message status, e.g. for specific output;
wenzelm
parents:
83284
diff
changeset
|
61 |
verbose = verbose, status = status) |
| 68987 | 62 |
|
| 77504 | 63 |
def print_session: String = if_proper(session, session + ": ") |
| 68987 | 64 |
def print_theory: String = "theory " + theory |
65 |
def print_percentage: String = |
|
66 |
percentage match { case None => "" case Some(p) => " " + p + "%" }
|
|
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83286
diff
changeset
|
67 |
def print_cumulated_time: String = |
|
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83286
diff
changeset
|
68 |
if (cumulated_time.is_relevant) " (" + cumulated_time.message + " cumulated time)" else ""
|
| 68957 | 69 |
} |
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
70 |
|
|
83315
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83309
diff
changeset
|
71 |
object Nodes_Status {
|
|
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83309
diff
changeset
|
72 |
def empty(session: String): Nodes_Status = |
| 83507 | 73 |
Nodes_Status(Date.now(), Nil, Document_Status.Nodes_Status.empty, session = session) |
|
83315
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83309
diff
changeset
|
74 |
} |
|
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83309
diff
changeset
|
75 |
|
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
76 |
sealed case class Nodes_Status( |
| 83507 | 77 |
now: Date, |
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
78 |
domain: List[Document.Node.Name], |
| 83223 | 79 |
document_status: Document_Status.Nodes_Status, |
| 83227 | 80 |
session: String = "", |
81 |
old: Option[Document_Status.Nodes_Status] = None |
|
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
82 |
) {
|
| 83223 | 83 |
def apply(name: Document.Node.Name): Document_Status.Node_Status = |
84 |
document_status(name) |
|
85 |
||
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
86 |
def theory( |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
87 |
name: Document.Node.Name, |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
88 |
node_status: Document_Status.Node_Status, |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
89 |
status: Boolean = false): Theory = |
| 83229 | 90 |
Theory(theory = name.theory, session = session, |
91 |
percentage = Some(node_status.percentage), |
|
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
92 |
cumulated_time = node_status.cumulated_time, |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
93 |
status = status) |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
94 |
|
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
95 |
def old_percentage(name: Document.Node.Name): Int = |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
96 |
if (old.isEmpty) 0 else old.get(name).percentage |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
97 |
|
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
98 |
def completed_theories: List[Theory] = |
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
99 |
domain.flatMap({ name =>
|
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
100 |
val st = apply(name) |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
101 |
val p = st.percentage |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
102 |
if (p == 100 && p != old_percentage(name)) Some(theory(name, st)) else None |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
103 |
}) |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
104 |
|
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
105 |
def status_theories: List[Theory] = |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
106 |
domain.flatMap({ name =>
|
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
107 |
val st = apply(name) |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
108 |
val p = st.percentage |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
109 |
if (st.progress || (p < 100 && p != old_percentage(name))) {
|
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
110 |
Some(theory(name, st, status = true)) |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
111 |
} |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
112 |
else None |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83290
diff
changeset
|
113 |
}) |
| 83507 | 114 |
|
115 |
def status_commands(threshold: Time): List[Progress.Message] = |
|
116 |
List.from( |
|
117 |
for {
|
|
118 |
name <- domain.iterator |
|
119 |
st = apply(name) |
|
120 |
command_timings <- st.command_timings.valuesIterator |
|
121 |
run <- command_timings.long_running(now, threshold).iterator |
|
122 |
} yield {
|
|
123 |
val text = |
|
124 |
if_proper(session, session + ": ") + |
|
125 |
"long-running command " + quote(run.name) + |
|
126 |
" (" + run.time(now).message + " at line " + run.line +
|
|
127 |
" of theory " + quote(name.theory) + ")" |
|
128 |
Progress.Message(Progress.Kind.writeln, text, verbose = true, status = true) |
|
129 |
}) |
|
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
130 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
131 |
|
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
132 |
|
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
133 |
/* status lines (e.g. at bottom of output) */ |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
134 |
|
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
135 |
trait Status extends Progress {
|
| 83507 | 136 |
def status_threshold: Time = Time.zero |
137 |
def status_detailed: Boolean = false |
|
138 |
||
|
83286
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
139 |
def status_output(msgs: Progress.Output): Unit |
|
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
140 |
|
| 83271 | 141 |
def status_hide(status: Progress.Output): Unit = () |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
142 |
|
| 83304 | 143 |
protected var _status: Progress.Session_Output = Nil |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
144 |
|
| 83304 | 145 |
def status_clear(): Progress.Session_Output = synchronized {
|
| 83271 | 146 |
val status = _status |
147 |
_status = Nil |
|
| 83304 | 148 |
status_hide(status.map(_._2)) |
| 83271 | 149 |
status |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
150 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
151 |
|
| 83304 | 152 |
private def output_status(status: Progress.Session_Output): Unit = synchronized {
|
| 83271 | 153 |
_status = Nil |
| 83304 | 154 |
status_output(status.map(_._2)) |
| 83271 | 155 |
_status = status |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
156 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
157 |
|
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
158 |
override def output(msgs: Progress.Output): Unit = synchronized {
|
|
83302
71ad306ee61f
proper support for output_theory, notably for isabelle.jedit.Session_Build.progress;
wenzelm
parents:
83298
diff
changeset
|
159 |
if (msgs.nonEmpty) {
|
| 83271 | 160 |
val status = status_clear() |
|
83286
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
161 |
status_output(msgs) |
|
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
162 |
output_status(status) |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
163 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
164 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
165 |
|
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
166 |
override def nodes_status(nodes_status: Progress.Nodes_Status): Unit = synchronized {
|
| 83304 | 167 |
val old_status = status_clear() |
| 83309 | 168 |
val new_status = {
|
169 |
val buf = new mutable.ListBuffer[(String, Progress.Msg)] |
|
170 |
val session = nodes_status.session |
|
171 |
for (old <- old_status if old._1 < session) buf += old |
|
| 83507 | 172 |
if (status_detailed) {
|
173 |
for (thy <- nodes_status.status_theories) buf += (session -> thy) |
|
174 |
for (msg <- nodes_status.status_commands(status_threshold)) {
|
|
175 |
buf += (session -> msg) |
|
176 |
} |
|
177 |
} |
|
| 83309 | 178 |
for (old <- old_status if old._1 > session) buf += old |
179 |
buf.toList |
|
180 |
} |
|
| 83304 | 181 |
|
| 83271 | 182 |
output(nodes_status.completed_theories) |
| 83304 | 183 |
output_status(new_status) |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
184 |
} |
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
185 |
} |
|
68410
4e27f5c361d2
clarified signature: more uniform theory_message (see also d7920eb7de54);
wenzelm
parents:
68330
diff
changeset
|
186 |
} |
|
4e27f5c361d2
clarified signature: more uniform theory_message (see also d7920eb7de54);
wenzelm
parents:
68330
diff
changeset
|
187 |
|
| 75393 | 188 |
class Progress {
|
| 78876 | 189 |
def now(): Date = Date.now() |
190 |
val start: Date = now() |
|
191 |
||
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
192 |
def verbose: Boolean = false |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
193 |
final def do_output(msg: Progress.Msg): Boolean = !msg.verbose || verbose |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
194 |
|
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
195 |
def output(msgs: Progress.Output): Unit = {}
|
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
196 |
|
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
197 |
final def output_text(msgs: Progress.Output, terminate: Boolean = false): String = {
|
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
198 |
val lines = msgs.flatMap(msg => if (do_output(msg)) Some(msg.message.output_text) else None) |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
199 |
if (terminate) Library.terminate_lines(lines) else cat_lines(lines) |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
200 |
} |
|
77502
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
201 |
|
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
202 |
final def echo(msg: String, verbose: Boolean = false): Unit = |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
203 |
output(List(Progress.Message(Progress.Kind.writeln, msg, verbose = verbose))) |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
204 |
final def echo_warning(msg: String, verbose: Boolean = false): Unit = |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
205 |
output(List(Progress.Message(Progress.Kind.warning, msg, verbose = verbose))) |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
206 |
final def echo_error_message(msg: String, verbose: Boolean = false): Unit = |
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
207 |
output(List(Progress.Message(Progress.Kind.error_message, msg, verbose = verbose))) |
|
77502
2e2b2bd6b2d2
clarified signature: require just one "override def echo(message: Progress.Message): Unit";
wenzelm
parents:
77499
diff
changeset
|
208 |
|
|
77506
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
209 |
final def echo_if(cond: Boolean, msg: String): Unit = if (cond) echo(msg) |
|
77499
8fc94efa954a
clarified signature: more uniform Progress.verbose, avoid adhoc "override def theory()";
wenzelm
parents:
77498
diff
changeset
|
210 |
|
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
211 |
final def theory(theory: Progress.Theory): Unit = output(List(theory)) |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
212 |
|
|
83214
911fbc338de7
clarified signature: more explicit type Progress.Nodes_Status;
wenzelm
parents:
83205
diff
changeset
|
213 |
def nodes_status(nodes_status: Progress.Nodes_Status): Unit = {}
|
| 64909 | 214 |
|
| 78432 | 215 |
final def capture[A](e: => A, msg: String, err: Throwable => String): Exn.Result[A] = {
|
216 |
echo(msg) |
|
217 |
try { Exn.Res(e) }
|
|
218 |
catch { case exn: Throwable => echo_error_message(err(exn)); Exn.Exn[A](exn) }
|
|
219 |
} |
|
220 |
||
|
77506
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
221 |
final def timeit[A]( |
|
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
222 |
body: => A, |
|
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
223 |
message: Exn.Result[A] => String = null, |
|
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
224 |
enabled: Boolean = true |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
225 |
): A = Timing.timeit(body, message = message, enabled = enabled, output = echo(_)) |
| 65921 | 226 |
|
| 77524 | 227 |
@volatile private var is_stopped = false |
| 73367 | 228 |
def stop(): Unit = { is_stopped = true }
|
| 75393 | 229 |
def stopped: Boolean = {
|
| 73367 | 230 |
if (Thread.interrupted()) is_stopped = true |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
231 |
is_stopped |
|
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
232 |
} |
|
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
233 |
|
|
77506
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
234 |
final def interrupt_handler[A](e: => A): A = POSIX_Interrupt.handler { stop() } { e }
|
|
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
235 |
final def expose_interrupt(): Unit = if (stopped) throw Exn.Interrupt() |
| 61276 | 236 |
override def toString: String = if (stopped) "Progress(stopped)" else "Progress" |
| 64201 | 237 |
|
|
77506
a8175b950173
more robust signature: avoid totally adhoc overriding (see also Build_Process.progress vs. build_progress);
wenzelm
parents:
77504
diff
changeset
|
238 |
final def bash(script: String, |
| 80230 | 239 |
ssh: SSH.System = SSH.Local, |
|
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
79887
diff
changeset
|
240 |
cwd: Path = Path.current, |
| 82706 | 241 |
env: JMap[String, String] = Isabelle_System.Settings.env(), // ignored for remote ssh |
| 64201 | 242 |
redirect: Boolean = false, |
| 65930 | 243 |
echo: Boolean = false, |
| 80236 | 244 |
watchdog_time: Time = Time.zero, |
| 75393 | 245 |
strict: Boolean = true |
246 |
): Process_Result = {
|
|
| 72599 | 247 |
val result = |
| 80230 | 248 |
Isabelle_System.bash(script, ssh = ssh, cwd = cwd, env = env, redirect = redirect, |
| 72599 | 249 |
progress_stdout = echo_if(echo, _), |
250 |
progress_stderr = echo_if(echo, _), |
|
| 80236 | 251 |
watchdog = Bash.Watchdog(watchdog_time, _ => stopped), |
| 72599 | 252 |
strict = strict) |
253 |
if (strict && stopped) throw Exn.Interrupt() else result |
|
| 64201 | 254 |
} |
| 61276 | 255 |
} |
256 |
||
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
257 |
class Console_Progress( |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
258 |
override val verbose: Boolean = false, |
| 83507 | 259 |
threshold: Time = Time.zero, |
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
260 |
detailed: Boolean = false, |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
261 |
stderr: Boolean = false) |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
262 |
extends Progress with Progress.Status {
|
| 83507 | 263 |
override def status_threshold: Time = threshold |
| 83280 | 264 |
override def status_detailed: Boolean = detailed |
| 83507 | 265 |
|
| 83271 | 266 |
override def status_hide(status: Progress.Output): Unit = synchronized {
|
267 |
val txt = output_text(status, terminate = true) |
|
268 |
Output.delete_lines(Library.count_newlines(txt), stdout = !stderr) |
|
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
269 |
} |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83229
diff
changeset
|
270 |
|
|
83286
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
271 |
override def status_output(msgs: Progress.Output): Unit = synchronized {
|
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
272 |
for (msg <- msgs if do_output(msg)) {
|
| 83290 | 273 |
val txt0 = msg.message.output_text |
|
83306
2616fa68b9c6
more robust reset of console text styles, notably for Windows/Cygwin;
wenzelm
parents:
83304
diff
changeset
|
274 |
val txt1 = if (msg.status) "\u001b[7m" + txt0 + "\u001b[0m" else txt0 |
| 83290 | 275 |
Output.output(txt1, stdout = !stderr, include_empty = true) |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77507
diff
changeset
|
276 |
} |
| 78874 | 277 |
} |
| 77503 | 278 |
|
279 |
override def toString: String = super.toString + ": console" |
|
| 61276 | 280 |
} |
| 65888 | 281 |
|
| 77507 | 282 |
class File_Progress(path: Path, override val verbose: Boolean = false) |
| 83282 | 283 |
extends Progress with Progress.Status {
|
|
83286
f772c9234f7f
proper status_output for output via Progress.Status mixin;
wenzelm
parents:
83285
diff
changeset
|
284 |
override def status_output(msgs: Progress.Output): Unit = synchronized {
|
|
83269
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
285 |
val txt = output_text(msgs, terminate = true) |
|
f6de20fbf55f
clarified Progress.output and related operations: prefer bulk messages of general type Progress.Msg;
wenzelm
parents:
83266
diff
changeset
|
286 |
if (txt.nonEmpty) File.append(path, txt) |
| 78874 | 287 |
} |
| 65888 | 288 |
|
| 77503 | 289 |
override def toString: String = super.toString + ": " + path.toString |
| 65888 | 290 |
} |