| author | wenzelm |
| Tue, 04 Nov 2025 21:36:33 +0100 | |
| changeset 83505 | ef6863b14ca2 |
| parent 83503 | 7b1b7ac616c0 |
| child 83507 | 989304e45ad7 |
| permissions | -rw-r--r-- |
| 68758 | 1 |
/* Title: Pure/PIDE/document_status.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Document status based on markup information. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
10 |
import scala.collection.immutable.SortedMap |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
11 |
|
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
12 |
|
| 75393 | 13 |
object Document_Status {
|
| 83161 | 14 |
/* theory status: via 'theory' or 'end' commands */ |
15 |
||
16 |
object Theory_Status extends Enumeration {
|
|
17 |
val NONE, INITIALIZED, FINALIZED, CONSOLIDATING, CONSOLIDATED = Value |
|
18 |
||
19 |
def initialized(t: Value): Boolean = t >= INITIALIZED |
|
20 |
def finalized(t: Value): Boolean = t >= FINALIZED |
|
21 |
def consolidating(t: Value): Boolean = t >= CONSOLIDATING |
|
22 |
def consolidated(t: Value): Boolean = t >= CONSOLIDATED |
|
23 |
||
24 |
def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2 |
|
25 |
} |
|
26 |
||
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
27 |
trait Theory_Status {
|
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
28 |
def theory_status: Theory_Status.Value |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
29 |
def initialized: Boolean = Theory_Status.initialized(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
30 |
def finalized: Boolean = Theory_Status.finalized(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
31 |
def consolidating: Boolean = Theory_Status.consolidating(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
32 |
def consolidated: Boolean = Theory_Status.consolidated(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
33 |
} |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
34 |
|
| 83161 | 35 |
|
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
36 |
/* command timings: for pro-forma command with actual commands at offset */ |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
37 |
|
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
38 |
sealed case class Command_Running(name: String, line: Int, start: Date) {
|
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
39 |
def time(now: Date): Time = now - start |
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
40 |
} |
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
41 |
|
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
42 |
object Command_Timings {
|
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
43 |
type Entry_Running = (Symbol.Offset, Command_Running) |
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
44 |
type Entry = (Symbol.Offset, Time) |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
45 |
val empty: Command_Timings = |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
46 |
new Command_Timings(SortedMap.empty, SortedMap.empty, Time.zero) |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
47 |
def merge(args: IterableOnce[Command_Timings]): Command_Timings = |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
48 |
args.iterator.foldLeft(empty)(_ ++ _) |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
49 |
} |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
50 |
|
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
51 |
final class Command_Timings private( |
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
52 |
private val running: SortedMap[Symbol.Offset, Command_Running], // start time (in Scala) |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
53 |
private val finished: SortedMap[Symbol.Offset, Time], // elapsed time (in ML) |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
54 |
private val sum_finished: Time |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
55 |
) {
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
56 |
def is_empty: Boolean = running.isEmpty && finished.isEmpty |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
57 |
|
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
58 |
def has_running: Boolean = running.nonEmpty |
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
59 |
def add_running(entry: Command_Timings.Entry_Running): Command_Timings = |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
60 |
new Command_Timings(running + entry, finished, sum_finished) |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
61 |
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
62 |
def count_finished: Int = finished.size |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
63 |
def get_finished(offset: Symbol.Offset): Time = finished.getOrElse(offset, Time.zero) |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
64 |
def add_finished(entry: Command_Timings.Entry): Command_Timings = {
|
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
65 |
val (offset, t) = entry |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
66 |
val running1 = running - offset |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
67 |
val finished1 = finished + (offset -> (get_finished(offset) + t)) |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
68 |
val sum_finished1 = sum_finished + t |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
69 |
new Command_Timings(running1, finished1, sum_finished1) |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
70 |
} |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
71 |
|
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
72 |
def sum(now: Date): Time = |
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
73 |
running.valuesIterator.foldLeft(sum_finished)({ case (t, run) => t + run.time(now) })
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
74 |
|
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
75 |
def ++ (other: Command_Timings): Command_Timings = |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
76 |
if (is_empty) other |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
77 |
else other.running.foldLeft(other.finished.foldLeft(this)(_ add_finished _))(_ add_running _) |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
78 |
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
79 |
|
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
80 |
override def hashCode: Int = (running, finished).hashCode |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
81 |
override def equals(that: Any): Boolean = |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
82 |
that match {
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
83 |
case other: Command_Timings => running == other.running && finished == other.finished |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
84 |
case _ => false |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
85 |
} |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
86 |
override def toString: String = |
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
87 |
running.mkString("Command_Timings(running = (", ", ", "), ") +
|
|
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
88 |
finished.mkString("finished = (", ", ", "))")
|
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
89 |
} |
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
90 |
|
|
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
91 |
|
| 68758 | 92 |
/* command status */ |
93 |
||
| 75393 | 94 |
object Command_Status {
|
| 68758 | 95 |
val proper_elements: Markup.Elements = |
96 |
Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
97 |
Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
| 68758 | 98 |
|
99 |
val liberal_elements: Markup.Elements = |
|
100 |
proper_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR |
|
101 |
||
| 83247 | 102 |
val empty: Command_Status = |
103 |
new Command_Status( |
|
104 |
theory_status = Theory_Status.NONE, |
|
105 |
touched = false, |
|
106 |
accepted = false, |
|
107 |
warned = false, |
|
108 |
failed = false, |
|
109 |
canceled = false, |
|
110 |
forks = 0, |
|
111 |
runs = 0, |
|
112 |
timings = Command_Timings.empty) |
|
113 |
||
| 83157 | 114 |
def make( |
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
115 |
now: Date, |
| 83185 | 116 |
markups: List[Markup] = Nil, |
| 83157 | 117 |
warned: Boolean = false, |
118 |
failed: Boolean = false |
|
119 |
): Command_Status = {
|
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
120 |
empty.update(now, markups = markups, warned = warned, failed = failed) |
| 68758 | 121 |
} |
122 |
||
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
123 |
def merge(args: IterableOnce[Command_Status]): Command_Status = |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
124 |
args.iterator.foldLeft(empty)(_ + _) |
| 68758 | 125 |
} |
126 |
||
| 83155 | 127 |
final class Command_Status private( |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
128 |
val theory_status: Theory_Status.Value, |
| 68758 | 129 |
private val touched: Boolean, |
130 |
private val accepted: Boolean, |
|
131 |
private val warned: Boolean, |
|
132 |
private val failed: Boolean, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
133 |
private val canceled: Boolean, |
| 83155 | 134 |
val forks: Int, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
135 |
val runs: Int, |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
136 |
val timings: Command_Timings |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
137 |
) extends Theory_Status {
|
| 83155 | 138 |
override def toString: String = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
139 |
if (is_empty) "Command_Status.empty" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
140 |
else if (failed) "Command_Status(failed)" |
| 83155 | 141 |
else if (warned) "Command_Status(warned)" |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
142 |
else "Command_Status(...)" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
143 |
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
144 |
def is_empty: Boolean = |
| 83161 | 145 |
!Theory_Status.initialized(theory_status) && |
|
83160
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
146 |
!touched && !accepted && !warned && !failed && !canceled && |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
147 |
forks == 0 && runs == 0 && timings.is_empty |
| 83155 | 148 |
|
| 68758 | 149 |
def + (that: Command_Status): Command_Status = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
150 |
if (is_empty) that |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
151 |
else if (that.is_empty) this |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
152 |
else {
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
153 |
new Command_Status( |
| 83161 | 154 |
theory_status = Theory_Status.merge(theory_status, that.theory_status), |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
155 |
touched = touched || that.touched, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
156 |
accepted = accepted || that.accepted, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
157 |
warned = warned || that.warned, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
158 |
failed = failed || that.failed, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
159 |
canceled = canceled || that.canceled, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
160 |
forks = forks + that.forks, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
161 |
runs = runs + that.runs, |
|
83210
9cc5d77d505c
more detailed Command_Timings: count actual commands from theory body individually;
wenzelm
parents:
83208
diff
changeset
|
162 |
timings = timings ++ that.timings) |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
163 |
} |
| 68758 | 164 |
|
| 83185 | 165 |
def update( |
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
166 |
now: Date, |
| 83185 | 167 |
markups: List[Markup] = Nil, |
168 |
warned: Boolean = false, |
|
169 |
failed: Boolean = false |
|
170 |
): Command_Status = {
|
|
| 83247 | 171 |
var theory_status1 = theory_status |
172 |
var touched1 = touched |
|
173 |
var accepted1 = accepted |
|
174 |
var warned1 = this.warned || warned |
|
175 |
var failed1 = this.failed || failed |
|
176 |
var canceled1 = canceled |
|
177 |
var forks1 = forks |
|
178 |
var runs1 = runs |
|
179 |
var timings1 = timings |
|
180 |
for (markup <- markups) {
|
|
181 |
markup.name match {
|
|
182 |
case Markup.INITIALIZED => |
|
183 |
theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.INITIALIZED) |
|
184 |
case Markup.FINALIZED => |
|
185 |
theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.FINALIZED) |
|
186 |
case Markup.CONSOLIDATING => |
|
187 |
theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.CONSOLIDATING) |
|
188 |
case Markup.CONSOLIDATED => |
|
189 |
theory_status1 = Theory_Status.merge(theory_status1, Theory_Status.CONSOLIDATED) |
|
190 |
case Markup.ACCEPTED => accepted1 = true |
|
191 |
case Markup.FORKED => touched1 = true; forks1 += 1 |
|
192 |
case Markup.JOINED => forks1 -= 1 |
|
193 |
case Markup.RUNNING => touched1 = true; runs1 += 1 |
|
194 |
case Markup.FINISHED => runs1 -= 1 |
|
195 |
case Markup.WARNING | Markup.LEGACY => warned1 = true |
|
196 |
case Markup.FAILED | Markup.ERROR => failed1 = true |
|
197 |
case Markup.CANCELED => canceled1 = true |
|
| 83294 | 198 |
case Markup.Command_Timing.name => |
| 83247 | 199 |
val props = markup.properties |
200 |
val offset = Position.Offset.get(props) |
|
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
201 |
val is_running = props.contains(Markup.command_running) |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
202 |
timings1 = |
|
83505
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
203 |
if (is_running) {
|
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
204 |
val name = Markup.Name.get(props) |
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
205 |
val line = Position.Line.get(props) |
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
206 |
timings1.add_running(offset -> Command_Running(name, line, now)) |
|
ef6863b14ca2
more informative Document_Status.Command_Running, based on properties from Isabelle/ML;
wenzelm
parents:
83503
diff
changeset
|
207 |
} |
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
208 |
else timings1.add_finished(offset -> Time.seconds(Markup.Elapsed.get(props))) |
| 83247 | 209 |
case _ => |
| 83185 | 210 |
} |
| 83184 | 211 |
} |
| 83247 | 212 |
if (this.theory_status == theory_status1 && |
213 |
this.touched == touched1 && |
|
214 |
this.accepted == accepted1 && |
|
215 |
this.warned == warned1 && |
|
216 |
this.failed == failed1 && |
|
217 |
this.canceled == canceled1 && |
|
218 |
this.forks == forks1 && |
|
219 |
this.runs == runs1 && |
|
220 |
this.timings.eq(timings1)) this |
|
221 |
else {
|
|
222 |
new Command_Status( |
|
223 |
theory_status = theory_status1, |
|
224 |
touched = touched1, |
|
225 |
accepted = accepted1, |
|
226 |
warned = warned1, |
|
227 |
failed = failed1, |
|
228 |
canceled = canceled1, |
|
229 |
forks = forks1, |
|
230 |
runs = runs1, |
|
231 |
timings = timings1) |
|
232 |
} |
|
| 83184 | 233 |
} |
234 |
||
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
235 |
def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0 |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
236 |
|
| 68758 | 237 |
def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
238 |
def is_running: Boolean = runs != 0 |
|
239 |
def is_warned: Boolean = warned |
|
240 |
def is_failed: Boolean = failed |
|
241 |
def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
242 |
def is_canceled: Boolean = canceled |
| 68881 | 243 |
def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0 |
| 68758 | 244 |
} |
245 |
||
246 |
||
247 |
/* node status */ |
|
248 |
||
| 75393 | 249 |
object Node_Status {
|
| 83167 | 250 |
val empty: Node_Status = Node_Status() |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
251 |
|
| 68758 | 252 |
def make( |
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
253 |
now: Date, |
| 68758 | 254 |
state: Document.State, |
255 |
version: Document.Version, |
|
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
256 |
name: Document.Node.Name, |
|
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
257 |
threshold: Time = Time.max |
| 76714 | 258 |
): Node_Status = {
|
| 83229 | 259 |
val node = version.nodes(name) |
260 |
||
| 83220 | 261 |
var theory_status = Document_Status.Theory_Status.NONE |
| 68758 | 262 |
var unprocessed = 0 |
263 |
var running = 0 |
|
264 |
var warned = 0 |
|
265 |
var failed = 0 |
|
266 |
var finished = 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
267 |
var canceled = false |
| 68892 | 268 |
var terminated = true |
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
269 |
var cumulated_time = Time.zero |
| 83189 | 270 |
var max_time = Time.zero |
| 83219 | 271 |
var command_timings = Map.empty[Command, Command_Timings] |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
272 |
|
| 83229 | 273 |
for (command <- node.commands.iterator) {
|
| 83164 | 274 |
val status = state.command_status(version, command) |
| 68758 | 275 |
|
| 83220 | 276 |
theory_status = Theory_Status.merge(theory_status, status.theory_status) |
277 |
||
| 68758 | 278 |
if (status.is_running) running += 1 |
279 |
else if (status.is_failed) failed += 1 |
|
280 |
else if (status.is_warned) warned += 1 |
|
281 |
else if (status.is_finished) finished += 1 |
|
282 |
else unprocessed += 1 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
283 |
|
|
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
284 |
if (status.is_canceled) canceled = true |
| 68892 | 285 |
if (!status.is_terminated) terminated = false |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
286 |
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
287 |
val t = status.timings.sum(now) |
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
288 |
cumulated_time += t |
| 83189 | 289 |
if (t > max_time) max_time = t |
| 83219 | 290 |
if (t.is_notable(threshold)) command_timings += (command -> status.timings) |
| 68758 | 291 |
} |
292 |
||
| 83229 | 293 |
def percent(a: Int, b: Int): Int = |
294 |
if (b == 0) 0 else ((a.toDouble / b) * 100).toInt |
|
| 83228 | 295 |
|
| 83229 | 296 |
val percentage: Int = {
|
297 |
node.get_theory match {
|
|
298 |
case None => |
|
299 |
if (Theory_Status.consolidated(theory_status)) 100 |
|
300 |
else {
|
|
301 |
val total = unprocessed + running + warned + failed + finished |
|
302 |
percent(total - unprocessed, total).min(99) |
|
303 |
} |
|
304 |
case Some(command) => |
|
305 |
val total = command.span.theory_commands |
|
|
83297
00bb83e60336
clarified command_timing protocol: support for still running commands, with timing approximated in Isabelle/Scala;
wenzelm
parents:
83296
diff
changeset
|
306 |
val processed = state.command_status(version, command).timings.count_finished |
| 83229 | 307 |
percent(processed, total) |
308 |
} |
|
309 |
} |
|
| 83228 | 310 |
|
| 68887 | 311 |
Node_Status( |
| 83220 | 312 |
theory_status = theory_status, |
| 83163 | 313 |
suppressed = version.nodes.suppressed(name), |
| 68887 | 314 |
unprocessed = unprocessed, |
315 |
running = running, |
|
316 |
warned = warned, |
|
317 |
failed = failed, |
|
318 |
finished = finished, |
|
319 |
canceled = canceled, |
|
320 |
terminated = terminated, |
|
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
321 |
cumulated_time = cumulated_time, |
| 83189 | 322 |
max_time = max_time, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
323 |
threshold = threshold, |
| 83228 | 324 |
command_timings = command_timings, |
325 |
percentage) |
|
| 68758 | 326 |
} |
327 |
} |
|
328 |
||
329 |
sealed case class Node_Status( |
|
| 83220 | 330 |
theory_status: Theory_Status.Value = Theory_Status.NONE, |
| 83167 | 331 |
suppressed: Boolean = false, |
332 |
unprocessed: Int = 0, |
|
333 |
running: Int = 0, |
|
334 |
warned: Int = 0, |
|
335 |
failed: Int = 0, |
|
336 |
finished: Int = 0, |
|
337 |
canceled: Boolean = false, |
|
338 |
terminated: Boolean = false, |
|
|
83289
2cd87a6da20b
clarified command_timing: expose elapsed time only, other fields were never used;
wenzelm
parents:
83266
diff
changeset
|
339 |
cumulated_time: Time = Time.zero, |
| 83189 | 340 |
max_time: Time = Time.zero, |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
341 |
threshold: Time = Time.zero, |
| 83228 | 342 |
command_timings: Map[Command, Command_Timings] = Map.empty, |
343 |
percentage: Int = 0 |
|
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
344 |
) extends Theory_Status {
|
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
345 |
def is_empty: Boolean = this == Node_Status.empty |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
346 |
|
| 68758 | 347 |
def ok: Boolean = failed == 0 |
348 |
def total: Int = unprocessed + running + warned + failed + finished |
|
349 |
||
| 83163 | 350 |
def quasi_consolidated: Boolean = !suppressed && !finalized && terminated |
| 68897 | 351 |
|
|
83298
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83297
diff
changeset
|
352 |
def progress: Boolean = running > 0 || command_timings.valuesIterator.exists(_.has_running) |
|
d2ffec6f4b89
clarified status_theories: show only running or updated theories;
wenzelm
parents:
83297
diff
changeset
|
353 |
|
|
83266
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83247
diff
changeset
|
354 |
def started: Boolean = percentage == 0 |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83247
diff
changeset
|
355 |
def completed: Boolean = percentage == 100 |
|
2f75f2495e3e
more detailed Console_Progress via Progress.Status;
wenzelm
parents:
83247
diff
changeset
|
356 |
|
| 68758 | 357 |
def json: JSON.Object.T = |
358 |
JSON.Object("ok" -> ok, "total" -> total, "unprocessed" -> unprocessed,
|
|
359 |
"running" -> running, "warned" -> warned, "failed" -> failed, "finished" -> finished, |
|
| 68898 | 360 |
"canceled" -> canceled, "consolidated" -> consolidated, |
361 |
"percentage" -> percentage) |
|
| 68758 | 362 |
} |
363 |
||
364 |
||
| 68759 | 365 |
/* nodes status */ |
366 |
||
| 83169 | 367 |
enum Overall_Status { case ok, failed, pending }
|
| 68759 | 368 |
|
| 75393 | 369 |
object Nodes_Status {
|
|
83205
99ce7933db6d
clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents:
83195
diff
changeset
|
370 |
val empty: Nodes_Status = new Nodes_Status(Map.empty) |
| 68759 | 371 |
} |
372 |
||
|
83205
99ce7933db6d
clarified signature: explicit domain for Nodes_Status operations;
wenzelm
parents:
83195
diff
changeset
|
373 |
final class Nodes_Status private(private val rep: Map[Document.Node.Name, Node_Status]) {
|
|
68770
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68769
diff
changeset
|
374 |
def is_empty: Boolean = rep.isEmpty |
|
83187
2b9457f5ffef
more robust: total "apply", with subtle change of semantics;
wenzelm
parents:
83186
diff
changeset
|
375 |
def apply(name: Document.Node.Name): Node_Status = rep.getOrElse(name, Node_Status.empty) |
| 68759 | 376 |
def get(name: Document.Node.Name): Option[Node_Status] = rep.get(name) |
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
377 |
def iterator: Iterator[(Document.Node.Name, Node_Status)] = rep.iterator |
|
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
378 |
|
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
379 |
def quasi_consolidated(name: Document.Node.Name): Boolean = |
| 83170 | 380 |
get(name) match {
|
| 68897 | 381 |
case Some(st) => st.quasi_consolidated |
|
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
382 |
case None => false |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
383 |
} |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
384 |
|
| 83169 | 385 |
def overall_status(name: Document.Node.Name): Overall_Status = |
| 83170 | 386 |
get(name) match {
|
| 68759 | 387 |
case Some(st) if st.consolidated => |
| 83169 | 388 |
if (st.ok) Overall_Status.ok else Overall_Status.failed |
389 |
case _ => Overall_Status.pending |
|
| 68759 | 390 |
} |
391 |
||
| 83208 | 392 |
def update_node( |
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
393 |
now: Date, |
| 83208 | 394 |
state: Document.State, |
395 |
version: Document.Version, |
|
396 |
name: Document.Node.Name, |
|
397 |
threshold: Time = Time.max |
|
398 |
): Nodes_Status = {
|
|
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
399 |
val node_status = |
|
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
400 |
Document_Status.Node_Status.make(now, state, version, name, threshold = threshold) |
|
83215
0526a640f44f
avoid shortcuts based on potentially expensive equality test;
wenzelm
parents:
83210
diff
changeset
|
401 |
new Nodes_Status(rep + (name -> node_status)) |
| 83208 | 402 |
} |
403 |
||
404 |
def update_nodes( |
|
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
405 |
now: Date, |
|
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68904
diff
changeset
|
406 |
resources: Resources, |
| 68763 | 407 |
state: Document.State, |
408 |
version: Document.Version, |
|
|
83188
481c3e1cb957
incorporate timing into Node_Status, while the default threshold leads to empty command_timings;
wenzelm
parents:
83187
diff
changeset
|
409 |
threshold: Time = Time.max, |
| 68769 | 410 |
domain: Option[Set[Document.Node.Name]] = None, |
| 75393 | 411 |
trim: Boolean = false |
| 83206 | 412 |
): Nodes_Status = {
|
| 83208 | 413 |
val domain1 = version.nodes.domain |
414 |
val that = |
|
415 |
domain.getOrElse(domain1).iterator.foldLeft(this)( |
|
416 |
{ case (a, name) =>
|
|
417 |
if (Resources.hidden_node(name) || resources.loaded_theory(name)) a |
|
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83298
diff
changeset
|
418 |
else a.update_node(now, state, version, name, threshold = threshold) }) |
| 83208 | 419 |
if (trim) new Nodes_Status(that.rep -- that.rep.keysIterator.filterNot(domain1)) |
420 |
else that |
|
| 68763 | 421 |
} |
| 68761 | 422 |
|
| 68759 | 423 |
override def hashCode: Int = rep.hashCode |
424 |
override def equals(that: Any): Boolean = |
|
425 |
that match {
|
|
426 |
case other: Nodes_Status => rep == other.rep |
|
427 |
case _ => false |
|
428 |
} |
|
| 68765 | 429 |
|
| 75393 | 430 |
override def toString: String = {
|
| 68765 | 431 |
var ok = 0 |
432 |
var failed = 0 |
|
433 |
var pending = 0 |
|
| 68873 | 434 |
var canceled = 0 |
| 68765 | 435 |
for (name <- rep.keysIterator) {
|
| 83169 | 436 |
overall_status(name) match {
|
437 |
case Overall_Status.ok => ok += 1 |
|
438 |
case Overall_Status.failed => failed += 1 |
|
439 |
case Overall_Status.pending => pending += 1 |
|
| 68765 | 440 |
} |
| 68873 | 441 |
if (apply(name).canceled) canceled += 1 |
| 68765 | 442 |
} |
| 68873 | 443 |
"Nodes_Status(ok = " + ok + ", failed = " + failed + ", pending = " + pending + |
444 |
", canceled = " + canceled + ")" |
|
| 68765 | 445 |
} |
| 68759 | 446 |
} |
| 68758 | 447 |
} |