1 /* Title: Pure/ML/ml_statistics.ML
10 import scala.collection.immutable.{SortedSet, SortedMap}
11 import scala.swing.{Frame, Component}
13 import org.jfree.data.xy.{XYSeries, XYSeriesCollection}
14 import org.jfree.chart.{JFreeChart, ChartPanel, ChartFactory}
15 import org.jfree.chart.plot.PlotOrientation
20 /* content interpretation */
22 final case class Entry(time: Double, data: Map[String, Double])
24 def apply(stats: List[Properties.T]): ML_Statistics = new ML_Statistics(stats)
25 def apply(path: Path): ML_Statistics = apply(Build.parse_log(File.read_gzip(path)).stats)
27 val empty = apply(Nil)
32 val GC_fields = ("GCs", List("partial_GCs", "full_GCs"))
35 ("Heap", List("size_heap", "size_allocation", "size_allocation_free",
36 "size_heap_free_last_full_GC", "size_heap_free_last_GC"))
39 ("Threads", List("threads_total", "threads_in_ML", "threads_wait_condvar",
40 "threads_wait_IO", "threads_wait_mutex", "threads_wait_signal"))
43 ("Time", List("time_GC_system", "time_GC_user", "time_non_GC_system", "time_non_GC_user"))
47 List("tasks_proof", "tasks_ready", "tasks_pending", "tasks_running", "tasks_passive"))
50 ("Worker threads", List("workers_total", "workers_active", "workers_waiting"))
53 List(GC_fields, heap_fields, threads_fields, time_fields, tasks_fields, workers_fields)
56 final class ML_Statistics private(val stats: List[Properties.T])
58 val Now = new Properties.Double("now")
59 def now(props: Properties.T): Double = Now.unapply(props).get
61 require(stats.forall(props => Now.unapply(props).isDefined))
63 val time_start = if (stats.isEmpty) 0.0 else now(stats.head)
64 val duration = if (stats.isEmpty) 0.0 else now(stats.last) - time_start
66 val fields: Set[String] =
67 SortedSet.empty[String] ++
68 (for (props <- stats.iterator; (x, _) <- props.iterator if x != Now.name)
71 val content: List[ML_Statistics.Entry] =
73 val time = now(props) - time_start
76 SortedMap.empty[String, Double] ++
77 (for ((x, y) <- props.iterator if x != Now.name)
78 yield (x, java.lang.Double.parseDouble(y)))
79 ML_Statistics.Entry(time, data)
85 def update_data(data: XYSeriesCollection, selected_fields: Iterable[String])
89 field <- selected_fields.iterator
90 series = new XYSeries(field)
92 content.foreach(entry => series.add(entry.time, entry.data(field)))
93 data.addSeries(series)
97 def chart(title: String, selected_fields: Iterable[String]): JFreeChart =
99 val data = new XYSeriesCollection
100 update_data(data, selected_fields)
102 ChartFactory.createXYLineChart(title, "time", "value", data,
103 PlotOrientation.VERTICAL, true, true, true)
106 def chart(arg: (String, Iterable[String])): JFreeChart = chart(arg._1, arg._2)
108 def show_standard_frames(): Unit =
109 ML_Statistics.standard_fields.map(chart(_)).foreach(c =>
112 iconImage = Isabelle_System.get_icon().getImage
114 contents = Component.wrap(new ChartPanel(c))