src/Pure/Tools/task_statistics.scala
author wenzelm
Thu, 04 Apr 2013 17:47:28 +0200
changeset 51615 072a7249e1ac
parent 51370 716a94cc5aaf
child 57612 990ffb84489b
permissions -rw-r--r--
separate module "GUI", to keep this out of the way of generic Isabelle_System operations, notably for non-Isabelle/jEdit applications; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51240
a7a04b449e8b updated headers;
wenzelm
parents: 50989
diff changeset
     1
/*  Title:      Pure/Tools/task_statistics.scala
50980
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)
51370
716a94cc5aaf avoid -Infinity which confuses JFreeChart histogram;
wenzelm
parents: 51240
diff changeset
    35
    for ((Run(x), i) <- tasks.iterator.zipWithIndex)
716a94cc5aaf avoid -Infinity which confuses JFreeChart histogram;
wenzelm
parents: 51240
diff changeset
    36
      values(i) = java.lang.Math.log10((x max 1).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 {
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: 51370
diff changeset
    56
        iconImage = GUI.isabelle_image()
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