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