| author | wenzelm | 
| Sun, 15 Jan 2023 20:38:27 +0100 | |
| changeset 76992 | 11c0747a87fc | 
| parent 75393 | 87ebf5a50283 | 
| child 78592 | fdfe9b91d96e | 
| permissions | -rw-r--r-- | 
| 51240 | 1 | /* Title: Pure/Tools/task_statistics.scala | 
| 50980 | 2 | Author: Makarius | 
| 3 | ||
| 4 | Future task runtime statistics. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 10 | import scala.swing.{Frame, Component}
 | |
| 11 | ||
| 12 | import org.jfree.data.statistics.HistogramDataset | |
| 13 | import org.jfree.chart.{JFreeChart, ChartPanel, ChartFactory}
 | |
| 14 | import org.jfree.chart.plot.{XYPlot, PlotOrientation}
 | |
| 15 | import org.jfree.chart.renderer.xy.{XYBarRenderer, StandardXYBarPainter}
 | |
| 16 | ||
| 17 | ||
| 75393 | 18 | object Task_Statistics {
 | 
| 64041 | 19 | def apply(session_name: String, task_statistics: List[Properties.T]): Task_Statistics = | 
| 20 | new Task_Statistics(session_name, task_statistics) | |
| 50980 | 21 | } | 
| 22 | ||
| 64041 | 23 | final class Task_Statistics private( | 
| 75393 | 24 | val session_name: String, | 
| 25 | val task_statistics: List[Properties.T] | |
| 26 | ) {
 | |
| 50982 | 27 |   private val Task_Name = new Properties.String("task_name")
 | 
| 28 |   private val Run = new Properties.Int("run")
 | |
| 50980 | 29 | |
| 75393 | 30 |   def chart(bins: Int = 100): JFreeChart = {
 | 
| 64041 | 31 | val values = new Array[Double](task_statistics.length) | 
| 32 | for ((Run(x), i) <- task_statistics.iterator.zipWithIndex) | |
| 51370 
716a94cc5aaf
avoid -Infinity which confuses JFreeChart histogram;
 wenzelm parents: 
51240diff
changeset | 33 | values(i) = java.lang.Math.log10((x max 1).toDouble / 1000000) | 
| 50980 | 34 | |
| 35 | val data = new HistogramDataset | |
| 36 |     data.addSeries("tasks", values, bins)
 | |
| 37 | ||
| 38 | val c = | |
| 39 |       ChartFactory.createHistogram("Task runtime distribution",
 | |
| 40 | "log10(runtime / s)", "number of tasks", data, | |
| 41 | PlotOrientation.VERTICAL, true, true, true) | |
| 42 | ||
| 43 | val renderer = c.getPlot.asInstanceOf[XYPlot].getRenderer.asInstanceOf[XYBarRenderer] | |
| 44 | renderer.setMargin(0.1) | |
| 45 | renderer.setBarPainter(new StandardXYBarPainter) | |
| 46 | ||
| 47 | c | |
| 48 | } | |
| 49 | ||
| 50 | def show_frame(bins: Int = 100): Unit = | |
| 57612 
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
 wenzelm parents: 
51615diff
changeset | 51 |     GUI_Thread.later {
 | 
| 50980 | 52 |       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: 
51370diff
changeset | 53 | iconImage = GUI.isabelle_image() | 
| 64041 | 54 | title = session_name | 
| 50980 | 55 | contents = Component.wrap(new ChartPanel(chart(bins))) | 
| 56 | visible = true | |
| 57 | } | |
| 58 | } | |
| 59 | } | |
| 60 |