author | wenzelm |
Sun, 15 Jun 2025 22:46:45 +0200 | |
changeset 82720 | 956ecf2c07a0 |
parent 82466 | d5ef492dd673 |
child 82761 | 88ffadf17062 |
permissions | -rw-r--r-- |
65477 | 1 |
/* Title: Pure/ML/ml_statistics.scala |
50685 | 2 |
Author: Makarius |
3 |
||
4 |
ML runtime statistics. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
65858 | 10 |
import scala.annotation.tailrec |
51432 | 11 |
import scala.collection.mutable |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
12 |
import scala.collection.immutable.{SortedSet, SortedMap} |
50691 | 13 |
import scala.swing.{Frame, Component} |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
14 |
|
50689 | 15 |
import org.jfree.data.xy.{XYSeries, XYSeriesCollection} |
16 |
import org.jfree.chart.{JFreeChart, ChartPanel, ChartFactory} |
|
17 |
import org.jfree.chart.plot.PlotOrientation |
|
18 |
||
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
19 |
|
75393 | 20 |
object ML_Statistics { |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
21 |
/* properties */ |
50690 | 22 |
|
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
23 |
val Now = new Properties.Double("now") |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
24 |
def now(props: Properties.T): Double = Now.unapply(props).get |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
25 |
|
50690 | 26 |
|
72138 | 27 |
/* memory status */ |
28 |
||
29 |
val Heap_Size = new Properties.Long("size_heap") |
|
30 |
val Heap_Free = new Properties.Long("size_heap_free_last_GC") |
|
31 |
val GC_Percent = new Properties.Int("GC_percent") |
|
32 |
||
77708 | 33 |
sealed case class Memory_Status(heap_size: Space, heap_free: Space, gc_percent: Int) { |
34 |
def heap_used: Space = heap_size.used(heap_free) |
|
35 |
def heap_used_fraction: Double = heap_size.used_fraction(heap_free) |
|
72138 | 36 |
def gc_progress: Option[Double] = |
37 |
if (1 <= gc_percent && gc_percent <= 100) Some((gc_percent - 1) * 0.01) else None |
|
38 |
} |
|
39 |
||
75393 | 40 |
def memory_status(props: Properties.T): Memory_Status = { |
77708 | 41 |
val heap_size = Space.bytes(Heap_Size.get(props)) |
42 |
val heap_free = Space.bytes(Heap_Free.get(props)) |
|
72138 | 43 |
val gc_percent = GC_Percent.get(props) |
44 |
Memory_Status(heap_size, heap_free, gc_percent) |
|
45 |
} |
|
46 |
||
47 |
||
72035 | 48 |
/* monitor process */ |
49 |
||
82720
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
50 |
def monitor(options: Options, pid: Long, |
72119
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
51 |
stats_dir: String = "", |
72035 | 52 |
delay: Time = Time.seconds(0.5), |
75393 | 53 |
consume: Properties.T => Unit = Console.println |
54 |
): Unit = { |
|
55 |
def progress_stdout(line: String): Unit = { |
|
77218 | 56 |
val props = space_explode(',', line).flatMap(Properties.Eq.unapply) |
72035 | 57 |
if (props.nonEmpty) consume(props) |
58 |
} |
|
59 |
||
82466 | 60 |
val env_prefix = if_proper(stats_dir, Bash.exports("POLYSTATSDIR=" + stats_dir)) |
72119
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
61 |
|
82720
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
62 |
val polyml_exe = ML_Settings.system(options).polyml_exe |
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
63 |
|
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
64 |
Bash.process(env_prefix + File.bash_path(polyml_exe) + |
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
65 |
" -q --use src/Pure/ML/ml_statistics.ML --eval " + |
72044
efd169aed4dc
more robust: avoid potential problems with encoding of directory name;
wenzelm
parents:
72037
diff
changeset
|
66 |
Bash.string("ML_Statistics.monitor " + ML_Syntax.print_long(pid) + " " + |
efd169aed4dc
more robust: avoid potential problems with encoding of directory name;
wenzelm
parents:
72037
diff
changeset
|
67 |
ML_Syntax.print_double(delay.seconds)), |
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
77710
diff
changeset
|
68 |
cwd = Path.ISABELLE_HOME) |
72035 | 69 |
.result(progress_stdout = progress_stdout, strict = false).check |
70 |
} |
|
71 |
||
72 |
||
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
73 |
/* protocol handler */ |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
74 |
|
75393 | 75 |
class Handler extends Session.Protocol_Handler { |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
76 |
private var session: Session = null |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
77 |
private var monitoring: Future[Unit] = Future.value(()) |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
78 |
|
75380 | 79 |
override def init(session: Session): Unit = synchronized { |
72213 | 80 |
this.session = session |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
81 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
82 |
|
75380 | 83 |
override def exit(): Unit = synchronized { |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
84 |
session = null |
73367 | 85 |
monitoring.cancel() |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
86 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
87 |
|
75380 | 88 |
private def consume(props: Properties.T): Unit = synchronized { |
72136
98dca728fc9c
removed pointless option "ML_statistics": always enabled;
wenzelm
parents:
72119
diff
changeset
|
89 |
if (session != null) { |
73031
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
wenzelm
parents:
72250
diff
changeset
|
90 |
val props1 = (session.cache.props(props ::: Java_Statistics.jvm_statistics())) |
72149 | 91 |
session.runtime_statistics.post(Session.Runtime_Statistics(props1)) |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
92 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
93 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
94 |
|
75380 | 95 |
private def ml_statistics(msg: Prover.Protocol_Output): Boolean = synchronized { |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
96 |
msg.properties match { |
72119
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
97 |
case Markup.ML_Statistics(pid, stats_dir) => |
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
98 |
monitoring = |
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
99 |
Future.thread("ML_statistics") { |
82720
956ecf2c07a0
more flexible ML_Settings in Isabelle/Scala, depending on system options and some default settings;
wenzelm
parents:
82466
diff
changeset
|
100 |
monitor(session.session_options, pid, stats_dir = stats_dir, consume = consume) |
72119
d115d50a19c0
provide POLYSTATSDIR to keep $HOME/.polyml clean (requires Poly/ML 52881757b127, otherwise ignored);
wenzelm
parents:
72117
diff
changeset
|
101 |
} |
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
102 |
true |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
103 |
case _ => false |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
104 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
105 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
106 |
|
75440 | 107 |
override val functions: Session.Protocol_Functions = |
108 |
List(Markup.ML_Statistics.name -> ml_statistics) |
|
72112
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
109 |
} |
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
110 |
|
3546dd4ade74
ML statistics via external process: allows monitoring RTS while ML program sleeps;
wenzelm
parents:
72044
diff
changeset
|
111 |
|
77121 | 112 |
/* memory fields */ |
50690 | 113 |
|
69832 | 114 |
val CODE_SIZE = "size_code" |
115 |
val STACK_SIZE = "size_stacks" |
|
65858 | 116 |
val HEAP_SIZE = "size_heap" |
117 |
||
65866 | 118 |
|
119 |
/* standard fields */ |
|
120 |
||
77710 | 121 |
sealed case class Fields(title: String, names: List[String], scale_MiB: Boolean = false) { |
122 |
def scale(y: Double): Double = if (scale_MiB) Space.B(y).MiB else y |
|
123 |
} |
|
65051 | 124 |
|
125 |
val tasks_fields: Fields = |
|
77117 | 126 |
Fields("Future tasks", |
68129 | 127 |
List("tasks_ready", "tasks_pending", "tasks_running", "tasks_passive", |
128 |
"tasks_urgent", "tasks_total")) |
|
57869 | 129 |
|
65051 | 130 |
val workers_fields: Fields = |
77117 | 131 |
Fields("Worker threads", List("workers_total", "workers_active", "workers_waiting")) |
57869 | 132 |
|
65051 | 133 |
val GC_fields: Fields = |
77117 | 134 |
Fields("GCs", List("partial_GCs", "full_GCs", "share_passes")) |
50690 | 135 |
|
65051 | 136 |
val heap_fields: Fields = |
77117 | 137 |
Fields("Heap", List(HEAP_SIZE, "size_allocation", "size_allocation_free", |
77710 | 138 |
"size_heap_free_last_full_GC", "size_heap_free_last_GC"), scale_MiB = true) |
50690 | 139 |
|
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
140 |
val program_fields: Fields = |
77710 | 141 |
Fields("Program", List("size_code", "size_stacks"), scale_MiB = true) |
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
142 |
|
65051 | 143 |
val threads_fields: Fields = |
77117 | 144 |
Fields("Threads", List("threads_total", "threads_in_ML", "threads_wait_condvar", |
50690 | 145 |
"threads_wait_IO", "threads_wait_mutex", "threads_wait_signal")) |
146 |
||
65051 | 147 |
val time_fields: Fields = |
77117 | 148 |
Fields("Time", List("time_elapsed", "time_elapsed_GC", "time_CPU", "time_GC")) |
51432 | 149 |
|
65051 | 150 |
val speed_fields: Fields = |
77117 | 151 |
Fields("Speed", List("speed_CPU", "speed_GC")) |
50690 | 152 |
|
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
153 |
private val time_speed = Map("time_CPU" -> "speed_CPU", "time_GC" -> "speed_GC") |
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
154 |
|
72149 | 155 |
val java_heap_fields: Fields = |
77117 | 156 |
Fields("Java heap", List("java_heap_size", "java_heap_used")) |
72149 | 157 |
|
158 |
val java_thread_fields: Fields = |
|
77117 | 159 |
Fields("Java threads", List("java_threads_total", "java_workers_total", "java_workers_active")) |
72149 | 160 |
|
65053 | 161 |
|
72143 | 162 |
val main_fields: List[Fields] = |
163 |
List(heap_fields, tasks_fields, workers_fields) |
|
164 |
||
72149 | 165 |
val other_fields: List[Fields] = |
166 |
List(threads_fields, GC_fields, program_fields, time_fields, speed_fields, |
|
167 |
java_heap_fields, java_thread_fields) |
|
168 |
||
169 |
val all_fields: List[Fields] = main_fields ::: other_fields |
|
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
170 |
|
77118 | 171 |
def field_scale(x: String, y: Double): Double = |
77710 | 172 |
all_fields.collectFirst({ case fields if fields.names.contains(x) => fields.scale(y) }) |
77118 | 173 |
.getOrElse(y) |
174 |
||
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
175 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
176 |
/* content interpretation */ |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
177 |
|
75393 | 178 |
final case class Entry(time: Double, data: Map[String, Double]) { |
65858 | 179 |
def get(field: String): Double = data.getOrElse(field, 0.0) |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
180 |
} |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
181 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
182 |
val empty: ML_Statistics = apply(Nil) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
183 |
|
75393 | 184 |
def apply( |
185 |
ml_statistics0: List[Properties.T], |
|
186 |
heading: String = "", |
|
187 |
domain: String => Boolean = _ => true |
|
188 |
): ML_Statistics = { |
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73031
diff
changeset
|
189 |
require(ml_statistics0.forall(props => Now.unapply(props).isDefined), "missing \"now\" field") |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
190 |
|
72224 | 191 |
val ml_statistics = ml_statistics0.sortBy(now) |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
192 |
val time_start = if (ml_statistics.isEmpty) 0.0 else now(ml_statistics.head) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
193 |
val duration = if (ml_statistics.isEmpty) 0.0 else now(ml_statistics.last) - time_start |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
194 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
195 |
val fields = |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
196 |
SortedSet.empty[String] ++ |
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
197 |
(for { |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
198 |
props <- ml_statistics.iterator |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
199 |
(x, _) <- props.iterator |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
200 |
if x != Now.name && domain(x) } yield x) |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
201 |
|
75393 | 202 |
val content = { |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
203 |
var last_edge = Map.empty[String, (Double, Double, Double)] |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
204 |
val result = new mutable.ListBuffer[ML_Statistics.Entry] |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
205 |
for (props <- ml_statistics) { |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
206 |
val time = now(props) - time_start |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
207 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
208 |
// rising edges -- relative speed |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
209 |
val speeds = |
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
210 |
(for { |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
211 |
(key, value) <- props.iterator |
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
212 |
key1 <- time_speed.get(key) |
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
213 |
if domain(key1) |
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
214 |
} yield { |
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
215 |
val (x0, y0, s0) = last_edge.getOrElse(key, (0.0, 0.0, 0.0)) |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
216 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
217 |
val x1 = time |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
218 |
val y1 = java.lang.Double.parseDouble(value) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
219 |
val s1 = if (x1 == x0) 0.0 else (y1 - y0) / (x1 - x0) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
220 |
|
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
221 |
if (y1 > y0) { |
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
222 |
last_edge += (key -> (x1, y1, s1)) |
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
223 |
(key1, s1.toString) |
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
224 |
} |
69822
8c587dd44f51
updated to polyml-5.8-20190220 (pre-release of Poly/ML 5.8);
wenzelm
parents:
68129
diff
changeset
|
225 |
else (key1, s0.toString) |
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
226 |
}).toList |
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
227 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
228 |
val data = |
67760
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
229 |
SortedMap.empty[String, Double] ++ |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
230 |
(for { |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
231 |
(x, y) <- props.iterator ++ speeds.iterator |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
232 |
if x != Now.name && domain(x) |
553d9ad7d679
more compact ML_Statistics, to make build_status work with less than 2GB heap;
wenzelm
parents:
65866
diff
changeset
|
233 |
z = java.lang.Double.parseDouble(y) if z != 0.0 |
77121 | 234 |
} yield { (x.intern, z) }) |
65866 | 235 |
|
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
236 |
result += ML_Statistics.Entry(time, data) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
237 |
} |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
238 |
result.toList |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
239 |
} |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
240 |
|
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
241 |
new ML_Statistics(heading, fields, content, time_start, duration) |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
242 |
} |
50685 | 243 |
} |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
244 |
|
65855
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
245 |
final class ML_Statistics private( |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
246 |
val heading: String, |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
247 |
val fields: Set[String], |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
248 |
val content: List[ML_Statistics.Entry], |
33b3e76114f8
store processed content instead of somewhat bulky properties;
wenzelm
parents:
65854
diff
changeset
|
249 |
val time_start: Double, |
75393 | 250 |
val duration: Double |
251 |
) { |
|
74853 | 252 |
override def toString: String = |
253 |
if (content.isEmpty) "ML_Statistics.empty" |
|
254 |
else "ML_Statistics(length = " + content.length + ", fields = " + fields.size + ")" |
|
255 |
||
256 |
||
65858 | 257 |
/* content */ |
258 |
||
259 |
def maximum(field: String): Double = |
|
73359 | 260 |
content.foldLeft(0.0) { case (m, e) => m max e.get(field) } |
65858 | 261 |
|
75393 | 262 |
def average(field: String): Double = { |
65858 | 263 |
@tailrec def sum(t0: Double, list: List[ML_Statistics.Entry], acc: Double): Double = |
264 |
list match { |
|
265 |
case Nil => acc |
|
266 |
case e :: es => |
|
267 |
val t = e.time |
|
268 |
sum(t, es, (t - t0) * e.get(field) + acc) |
|
269 |
} |
|
270 |
content match { |
|
271 |
case Nil => 0.0 |
|
272 |
case List(e) => e.get(field) |
|
273 |
case e :: es => sum(e.time, es, 0.0) / duration |
|
274 |
} |
|
275 |
} |
|
276 |
||
50689 | 277 |
|
278 |
/* charts */ |
|
279 |
||
75393 | 280 |
def update_data(data: XYSeriesCollection, selected_fields: List[String]): Unit = { |
74852 | 281 |
data.removeAllSeries() |
69832 | 282 |
for (field <- selected_fields) { |
283 |
val series = new XYSeries(field) |
|
77121 | 284 |
content.foreach(e => series.add(e.time, ML_Statistics.field_scale(field, e.get(field)))) |
50689 | 285 |
data.addSeries(series) |
286 |
} |
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
287 |
} |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
288 |
|
75393 | 289 |
def chart(title: String, selected_fields: List[String]): JFreeChart = { |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
290 |
val data = new XYSeriesCollection |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
291 |
update_data(data, selected_fields) |
50689 | 292 |
|
293 |
ChartFactory.createXYLineChart(title, "time", "value", data, |
|
294 |
PlotOrientation.VERTICAL, true, true, true) |
|
295 |
} |
|
296 |
||
65051 | 297 |
def chart(fields: ML_Statistics.Fields): JFreeChart = |
77117 | 298 |
chart(fields.title, fields.names) |
50691 | 299 |
|
65053 | 300 |
def show_frames(fields: List[ML_Statistics.Fields] = ML_Statistics.main_fields): Unit = |
71601 | 301 |
fields.map(chart).foreach(c => |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
53189
diff
changeset
|
302 |
GUI_Thread.later { |
50854 | 303 |
new Frame { |
51615
072a7249e1ac
separate module "GUI", to keep this out of the way of generic Isabelle_System operations, notably for non-Isabelle/jEdit applications;
wenzelm
parents:
51432
diff
changeset
|
304 |
iconImage = GUI.isabelle_image() |
65851 | 305 |
title = heading |
50854 | 306 |
contents = Component.wrap(new ChartPanel(c)) |
307 |
visible = true |
|
308 |
} |
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
309 |
}) |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
310 |
} |