src/Pure/Tools/task_statistics.scala
author wenzelm
Tue, 04 Oct 2016 19:26:19 +0200
changeset 64041 fd454d9e97c4
parent 57612 990ffb84489b
child 64045 c6160d0b0337
permissions -rw-r--r--
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
{
64041
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    20
  def apply(session_name: String, task_statistics: List[Properties.T]): Task_Statistics =
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    21
    new Task_Statistics(session_name, task_statistics)
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    22
64041
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    23
  def apply(info: Build.Session_Log_Info): Task_Statistics =
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    24
    apply(info.session_name, info.task_statistics)
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
64041
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    27
final class Task_Statistics private(
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    28
  val session_name: String, val task_statistics: List[Properties.T])
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    29
{
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    30
  private val Task_Name = new Properties.String("task_name")
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50980
diff changeset
    31
  private val Run = new Properties.Int("run")
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    32
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    33
  def chart(bins: Int = 100): JFreeChart =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    34
  {
64041
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    35
    val values = new Array[Double](task_statistics.length)
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    36
    for ((Run(x), i) <- task_statistics.iterator.zipWithIndex)
51370
716a94cc5aaf avoid -Infinity which confuses JFreeChart histogram;
wenzelm
parents: 51240
diff changeset
    37
      values(i) = java.lang.Math.log10((x max 1).toDouble / 1000000)
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    38
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    39
    val data = new HistogramDataset
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    40
    data.addSeries("tasks", values, bins)
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 c =
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    43
      ChartFactory.createHistogram("Task runtime distribution",
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    44
        "log10(runtime / s)", "number of tasks", data,
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    45
        PlotOrientation.VERTICAL, true, true, true)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    46
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    47
    val renderer = c.getPlot.asInstanceOf[XYPlot].getRenderer.asInstanceOf[XYBarRenderer]
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    48
    renderer.setMargin(0.1)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    49
    renderer.setBarPainter(new StandardXYBarPainter)
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    50
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    51
    c
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    52
  }
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    53
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    54
  def show_frame(bins: Int = 100): Unit =
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 51615
diff changeset
    55
    GUI_Thread.later {
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    56
      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
    57
        iconImage = GUI.isabelle_image()
64041
fd454d9e97c4 tuned signature;
wenzelm
parents: 57612
diff changeset
    58
        title = session_name
50980
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    59
        contents = Component.wrap(new ChartPanel(chart(bins)))
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    60
        visible = true
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
}
bc746aa3e8d5 charts for future task runtime statistics;
wenzelm
parents:
diff changeset
    64