src/Pure/ML/ml_statistics.scala
changeset 65858 9418a9fad835
parent 65855 33b3e76114f8
child 65864 1945fa8f0c39
equal deleted inserted replaced
65857:5d29d93766ef 65858:9418a9fad835
     5 */
     5 */
     6 
     6 
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
       
    10 import scala.annotation.tailrec
    10 import scala.collection.mutable
    11 import scala.collection.mutable
    11 import scala.collection.immutable.{SortedSet, SortedMap}
    12 import scala.collection.immutable.{SortedSet, SortedMap}
    12 import scala.swing.{Frame, Component}
    13 import scala.swing.{Frame, Component}
    13 
    14 
    14 import org.jfree.data.xy.{XYSeries, XYSeriesCollection}
    15 import org.jfree.data.xy.{XYSeries, XYSeriesCollection}
    24   def now(props: Properties.T): Double = Now.unapply(props).get
    25   def now(props: Properties.T): Double = Now.unapply(props).get
    25 
    26 
    26 
    27 
    27   /* standard fields */
    28   /* standard fields */
    28 
    29 
       
    30   val HEAP_SIZE = "size_heap"
       
    31 
    29   type Fields = (String, Iterable[String])
    32   type Fields = (String, Iterable[String])
    30 
    33 
    31   val tasks_fields: Fields =
    34   val tasks_fields: Fields =
    32     ("Future tasks",
    35     ("Future tasks",
    33       List("tasks_ready", "tasks_pending", "tasks_running", "tasks_passive", "tasks_urgent"))
    36       List("tasks_ready", "tasks_pending", "tasks_running", "tasks_passive", "tasks_urgent"))
    37 
    40 
    38   val GC_fields: Fields =
    41   val GC_fields: Fields =
    39     ("GCs", List("partial_GCs", "full_GCs"))
    42     ("GCs", List("partial_GCs", "full_GCs"))
    40 
    43 
    41   val heap_fields: Fields =
    44   val heap_fields: Fields =
    42     ("Heap", List("size_heap", "size_allocation", "size_allocation_free",
    45     ("Heap", List(HEAP_SIZE, "size_allocation", "size_allocation_free",
    43       "size_heap_free_last_full_GC", "size_heap_free_last_GC"))
    46       "size_heap_free_last_full_GC", "size_heap_free_last_GC"))
    44 
    47 
    45   val threads_fields: Fields =
    48   val threads_fields: Fields =
    46     ("Threads", List("threads_total", "threads_in_ML", "threads_wait_condvar",
    49     ("Threads", List("threads_total", "threads_in_ML", "threads_wait_condvar",
    47       "threads_wait_IO", "threads_wait_mutex", "threads_wait_signal"))
    50       "threads_wait_IO", "threads_wait_mutex", "threads_wait_signal"))
    63 
    66 
    64   /* content interpretation */
    67   /* content interpretation */
    65 
    68 
    66   final case class Entry(time: Double, data: Map[String, Double])
    69   final case class Entry(time: Double, data: Map[String, Double])
    67   {
    70   {
    68     def heap_size: Long = data.getOrElse("size_heap", 0.0).toLong
    71     def get(field: String): Double = data.getOrElse(field, 0.0)
    69   }
    72   }
    70 
    73 
    71   val empty: ML_Statistics = apply(Nil)
    74   val empty: ML_Statistics = apply(Nil)
    72 
    75 
    73   def apply(ml_statistics: List[Properties.T], heading: String = ""): ML_Statistics =
    76   def apply(ml_statistics: List[Properties.T], heading: String = ""): ML_Statistics =
   121   val fields: Set[String],
   124   val fields: Set[String],
   122   val content: List[ML_Statistics.Entry],
   125   val content: List[ML_Statistics.Entry],
   123   val time_start: Double,
   126   val time_start: Double,
   124   val duration: Double)
   127   val duration: Double)
   125 {
   128 {
   126   def heap_size_max: Long =
   129   /* content */
   127     (0L /: content)({ case (m, entry) => m max entry.heap_size })
   130 
       
   131   def maximum(field: String): Double =
       
   132     (0.0 /: content)({ case (m, e) => m max e.get(field) })
       
   133 
       
   134   def average(field: String): Double =
       
   135   {
       
   136     @tailrec def sum(t0: Double, list: List[ML_Statistics.Entry], acc: Double): Double =
       
   137       list match {
       
   138         case Nil => acc
       
   139         case e :: es =>
       
   140           val t = e.time
       
   141           sum(t, es, (t - t0) * e.get(field) + acc)
       
   142       }
       
   143     content match {
       
   144       case Nil => 0.0
       
   145       case List(e) => e.get(field)
       
   146       case e :: es => sum(e.time, es, 0.0) / duration
       
   147     }
       
   148   }
       
   149 
       
   150   def maximum_heap_size: Long = maximum(ML_Statistics.HEAP_SIZE).toLong
       
   151   def average_heap_size: Long = average(ML_Statistics.HEAP_SIZE).toLong
   128 
   152 
   129 
   153 
   130   /* charts */
   154   /* charts */
   131 
   155 
   132   def update_data(data: XYSeriesCollection, selected_fields: Iterable[String])
   156   def update_data(data: XYSeriesCollection, selected_fields: Iterable[String])