src/Pure/Tools/task_statistics.scala
author wenzelm
Sun, 20 Jan 2013 13:55:15 +0100
changeset 50989 a7f6ce0493b7
parent 50982 a7aa17a1f721
child 51240 a7a04b449e8b
permissions -rw-r--r--
accomodate scala-2.9.2;
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
{
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    20
  def apply(name: String, tasks: List[Properties.T]): Task_Statistics =
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    21
    new Task_Statistics(name, tasks)
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    22
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    23
  def apply(info: Build.Log_Info): Task_Statistics =
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    24
    apply(info.name, info.tasks)
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    25
}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    26
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    27
final class Task_Statistics private(val name: String, val tasks: List[Properties.T])
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    28
{
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    29
  private val Task_Name = new Properties.String("task_name")
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    30
  private val Run = new Properties.Int("run")
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    31
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    32
  def chart(bins: Int = 100): JFreeChart =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    33
  {
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    34
    val values = new Array[Double](tasks.length)
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    35
    for ((Run(x), i) <- tasks.iterator.zipWithIndex) values(i) =
50989
a7f6ce0493b7 accomodate scala-2.9.2;
wenzelm
parents: 50982
diff changeset
    36
      java.lang.Math.log10(x.toDouble / 1000000)
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    37
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    38
    val data = new HistogramDataset
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    39
    data.addSeries("tasks", values, bins)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    40
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    41
    val c =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    42
      ChartFactory.createHistogram("Task runtime distribution",
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    43
        "log10(runtime / s)", "number of tasks", data,
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    44
        PlotOrientation.VERTICAL, true, true, true)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    45
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    46
    val renderer = c.getPlot.asInstanceOf[XYPlot].getRenderer.asInstanceOf[XYBarRenderer]
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    47
    renderer.setMargin(0.1)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    48
    renderer.setBarPainter(new StandardXYBarPainter)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    49
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    50
    c
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    51
  }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    52
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    53
  def show_frame(bins: Int = 100): Unit =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    54
    Swing_Thread.later {
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    55
      new Frame {
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    56
        iconImage = Isabelle_System.get_icon().getImage
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    57
        title = name
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    58
        contents = Component.wrap(new ChartPanel(chart(bins)))
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    59
        visible = true
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    60
      }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    61
    }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    62
}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    63