src/Pure/Tools/task_statistics.scala
author wenzelm
Fri, 18 Jan 2013 22:31:57 +0100
changeset 50980 bc746aa3e8d5
child 50982 a7aa17a1f721
permissions -rw-r--r--
charts for future task runtime statistics;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/ML/task_statistics.ML
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     3
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     4
Future task runtime statistics.
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     5
*/
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     6
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     7
package isabelle
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     8
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
     9
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    10
import scala.swing.{Frame, Component}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    11
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    12
import org.jfree.data.statistics.HistogramDataset
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    13
import org.jfree.chart.{JFreeChart, ChartPanel, ChartFactory}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    14
import org.jfree.chart.plot.{XYPlot, PlotOrientation}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    15
import org.jfree.chart.renderer.xy.{XYBarRenderer, StandardXYBarPainter}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    16
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    17
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    18
object Task_Statistics
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    19
{
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    20
  def apply(stats: List[Properties.T]): Task_Statistics = new Task_Statistics(stats)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    21
}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    22
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    23
final class Task_Statistics private(val stats: List[Properties.T])
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    24
{
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    25
  val Task_Name = new Properties.String("task_name")
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    26
  val Run = new Properties.Int("run")
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    27
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    28
  def chart(bins: Int = 100): JFreeChart =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    29
  {
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    30
    val values = new Array[Double](stats.length)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    31
    for ((Run(x), i) <- stats.iterator.zipWithIndex) values(i) =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    32
      Math.log10(x.toDouble / 1000000)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    33
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    34
    val data = new HistogramDataset
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    35
    data.addSeries("tasks", values, bins)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    36
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    37
    val c =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    38
      ChartFactory.createHistogram("Task runtime distribution",
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    39
        "log10(runtime / s)", "number of tasks", data,
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    40
        PlotOrientation.VERTICAL, true, true, true)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    41
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    42
    val renderer = c.getPlot.asInstanceOf[XYPlot].getRenderer.asInstanceOf[XYBarRenderer]
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    43
    renderer.setMargin(0.1)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    44
    renderer.setBarPainter(new StandardXYBarPainter)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    45
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    46
    c
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    47
  }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    48
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    49
  def show_frame(bins: Int = 100): Unit =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    50
    Swing_Thread.later {
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    51
      new Frame {
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    52
        iconImage = Isabelle_System.get_icon().getImage
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    53
        title = "Statistics"
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    54
        contents = Component.wrap(new ChartPanel(chart(bins)))
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    55
        visible = true
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    56
      }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    57
    }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    58
}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    59