author | wenzelm |
Wed, 17 May 2017 13:47:19 +0200 | |
changeset 65851 | c103358a5559 |
parent 65477 | 64e61b0f6972 |
child 65854 | db070951dfee |
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 |
||
51432 | 10 |
import scala.collection.mutable |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
11 |
import scala.collection.immutable.{SortedSet, SortedMap} |
50691 | 12 |
import scala.swing.{Frame, Component} |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
13 |
|
50689 | 14 |
import org.jfree.data.xy.{XYSeries, XYSeriesCollection} |
15 |
import org.jfree.chart.{JFreeChart, ChartPanel, ChartFactory} |
|
16 |
import org.jfree.chart.plot.PlotOrientation |
|
17 |
||
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
18 |
|
50685 | 19 |
object ML_Statistics |
20 |
{ |
|
50690 | 21 |
/* content interpretation */ |
22 |
||
23 |
final case class Entry(time: Double, data: Map[String, Double]) |
|
24 |
||
65851 | 25 |
def apply(ml_statistics: List[Properties.T], heading: String = ""): ML_Statistics = |
26 |
new ML_Statistics(ml_statistics, heading) |
|
50690 | 27 |
|
65851 | 28 |
val empty = apply(Nil) |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
29 |
|
50690 | 30 |
|
31 |
/* standard fields */ |
|
32 |
||
65051 | 33 |
type Fields = (String, Iterable[String]) |
34 |
||
35 |
val tasks_fields: Fields = |
|
60610
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57869
diff
changeset
|
36 |
("Future tasks", |
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57869
diff
changeset
|
37 |
List("tasks_ready", "tasks_pending", "tasks_running", "tasks_passive", "tasks_urgent")) |
57869 | 38 |
|
65051 | 39 |
val workers_fields: Fields = |
57869 | 40 |
("Worker threads", List("workers_total", "workers_active", "workers_waiting")) |
41 |
||
65051 | 42 |
val GC_fields: Fields = |
43 |
("GCs", List("partial_GCs", "full_GCs")) |
|
50690 | 44 |
|
65051 | 45 |
val heap_fields: Fields = |
50690 | 46 |
("Heap", List("size_heap", "size_allocation", "size_allocation_free", |
47 |
"size_heap_free_last_full_GC", "size_heap_free_last_GC")) |
|
48 |
||
65051 | 49 |
val threads_fields: Fields = |
50690 | 50 |
("Threads", List("threads_total", "threads_in_ML", "threads_wait_condvar", |
51 |
"threads_wait_IO", "threads_wait_mutex", "threads_wait_signal")) |
|
52 |
||
65051 | 53 |
val time_fields: Fields = |
54 |
("Time", List("time_CPU", "time_GC")) |
|
51432 | 55 |
|
65051 | 56 |
val speed_fields: Fields = |
57 |
("Speed", List("speed_CPU", "speed_GC")) |
|
50690 | 58 |
|
65053 | 59 |
|
60 |
val all_fields: List[Fields] = |
|
57869 | 61 |
List(tasks_fields, workers_fields, GC_fields, heap_fields, threads_fields, |
62 |
time_fields, speed_fields) |
|
65053 | 63 |
|
64 |
val main_fields: List[Fields] = |
|
65 |
List(tasks_fields, workers_fields, heap_fields) |
|
50685 | 66 |
} |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
67 |
|
65851 | 68 |
final class ML_Statistics private(val ml_statistics: List[Properties.T], val heading: String) |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
69 |
{ |
50690 | 70 |
val Now = new Properties.Double("now") |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
71 |
def now(props: Properties.T): Double = Now.unapply(props).get |
50690 | 72 |
|
64041 | 73 |
require(ml_statistics.forall(props => Now.unapply(props).isDefined)) |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
74 |
|
64041 | 75 |
val time_start = if (ml_statistics.isEmpty) 0.0 else now(ml_statistics.head) |
76 |
val duration = if (ml_statistics.isEmpty) 0.0 else now(ml_statistics.last) - time_start |
|
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
77 |
|
50689 | 78 |
val fields: Set[String] = |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
79 |
SortedSet.empty[String] ++ |
64041 | 80 |
(for (props <- ml_statistics.iterator; (x, _) <- props.iterator if x != Now.name) |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
81 |
yield x) |
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
82 |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
83 |
val content: List[ML_Statistics.Entry] = |
51432 | 84 |
{ |
85 |
var last_edge = Map.empty[String, (Double, Double, Double)] |
|
86 |
val result = new mutable.ListBuffer[ML_Statistics.Entry] |
|
64041 | 87 |
for (props <- ml_statistics) { |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
88 |
val time = now(props) - time_start |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
89 |
require(time >= 0.0) |
51432 | 90 |
|
91 |
// rising edges -- relative speed |
|
92 |
val speeds = |
|
93 |
for ((key, value) <- props; a <- Library.try_unprefix("time", key)) yield { |
|
52888 | 94 |
val (x0, y0, s0) = last_edge.getOrElse(a, (0.0, 0.0, 0.0)) |
51432 | 95 |
|
96 |
val x1 = time |
|
97 |
val y1 = java.lang.Double.parseDouble(value) |
|
98 |
val s1 = if (x1 == x0) 0.0 else (y1 - y0) / (x1 - x0) |
|
99 |
||
100 |
val b = ("speed" + a).intern |
|
101 |
if (y1 > y0) { last_edge += (a -> (x1, y1, s1)); (b, s1) } else (b, s0) |
|
102 |
} |
|
103 |
||
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
104 |
val data = |
51432 | 105 |
SortedMap.empty[String, Double] ++ speeds ++ |
50690 | 106 |
(for ((x, y) <- props.iterator if x != Now.name) |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
107 |
yield (x, java.lang.Double.parseDouble(y))) |
51432 | 108 |
result += ML_Statistics.Entry(time, data) |
109 |
} |
|
110 |
result.toList |
|
111 |
} |
|
50689 | 112 |
|
113 |
||
114 |
/* charts */ |
|
115 |
||
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
116 |
def update_data(data: XYSeriesCollection, selected_fields: Iterable[String]) |
50689 | 117 |
{ |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
118 |
data.removeAllSeries |
50689 | 119 |
for { |
50690 | 120 |
field <- selected_fields.iterator |
50689 | 121 |
series = new XYSeries(field) |
122 |
} { |
|
123 |
content.foreach(entry => series.add(entry.time, entry.data(field))) |
|
124 |
data.addSeries(series) |
|
125 |
} |
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
126 |
} |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
127 |
|
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
128 |
def chart(title: String, selected_fields: Iterable[String]): JFreeChart = |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
129 |
{ |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
130 |
val data = new XYSeriesCollection |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
131 |
update_data(data, selected_fields) |
50689 | 132 |
|
133 |
ChartFactory.createXYLineChart(title, "time", "value", data, |
|
134 |
PlotOrientation.VERTICAL, true, true, true) |
|
135 |
} |
|
136 |
||
65051 | 137 |
def chart(fields: ML_Statistics.Fields): JFreeChart = |
138 |
chart(fields._1, fields._2) |
|
50691 | 139 |
|
65053 | 140 |
def show_frames(fields: List[ML_Statistics.Fields] = ML_Statistics.main_fields): Unit = |
65051 | 141 |
fields.map(chart(_)).foreach(c => |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
53189
diff
changeset
|
142 |
GUI_Thread.later { |
50854 | 143 |
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
|
144 |
iconImage = GUI.isabelle_image() |
65851 | 145 |
title = heading |
50854 | 146 |
contents = Component.wrap(new ChartPanel(c)) |
147 |
visible = true |
|
148 |
} |
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50691
diff
changeset
|
149 |
}) |
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
150 |
} |
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
151 |