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