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