src/Pure/Admin/build_status.scala
author wenzelm
Fri May 26 23:33:42 2017 +0200 (24 months ago)
changeset 65940 9c7241798c3b
parent 65939 9fb044904a4d
child 65941 316c30b60ebc
permissions -rw-r--r--
show errors from build_log database;
wenzelm@65743
     1
/*  Title:      Pure/Admin/build_status.scala
wenzelm@63686
     2
    Author:     Makarius
wenzelm@63686
     3
wenzelm@65743
     4
Present recent build status information from database.
wenzelm@63686
     5
*/
wenzelm@63686
     6
wenzelm@63686
     7
package isabelle
wenzelm@63686
     8
wenzelm@63686
     9
wenzelm@65743
    10
object Build_Status
wenzelm@63686
    11
{
wenzelm@65799
    12
  /* defaults */
wenzelm@65799
    13
wenzelm@65799
    14
  val default_target_dir = Path.explode("build_status")
wenzelm@65799
    15
  val default_image_size = (800, 600)
wenzelm@65799
    16
  val default_history = 30
wenzelm@65799
    17
wenzelm@65799
    18
  def default_profiles: List[Profile] =
wenzelm@65799
    19
    Jenkins.build_status_profiles ::: Isabelle_Cronjob.build_status_profiles
wenzelm@65799
    20
wenzelm@65799
    21
wenzelm@65791
    22
  /* data profiles */
wenzelm@65791
    23
wenzelm@65798
    24
  sealed case class Profile(description: String, history: Int, sql: String)
wenzelm@65791
    25
  {
wenzelm@65799
    26
    def days(options: Options): Int = options.int("build_log_history") max history
wenzelm@65799
    27
wenzelm@65799
    28
    def stretch(options: Options): Double =
wenzelm@65799
    29
      (days(options) max default_history min (default_history * 5)).toDouble / default_history
wenzelm@65799
    30
wenzelm@65799
    31
    def select(options: Options, columns: List[SQL.Column], only_sessions: Set[String]): SQL.Source =
wenzelm@65791
    32
    {
wenzelm@65791
    33
      Build_Log.Data.universal_table.select(columns, distinct = true,
wenzelm@65791
    34
        sql = "WHERE " +
wenzelm@65799
    35
          Build_Log.Data.pull_date + " > " + Build_Log.Data.recent_time(days(options)) + " AND " +
wenzelm@65893
    36
          SQL.member(Build_Log.Data.status.ident,
wenzelm@65893
    37
            List(
wenzelm@65893
    38
              Build_Log.Session_Status.finished.toString,
wenzelm@65893
    39
              Build_Log.Session_Status.failed.toString)) +
wenzelm@65804
    40
          (if (only_sessions.isEmpty) ""
wenzelm@65804
    41
           else " AND " + SQL.member(Build_Log.Data.session_name.ident, only_sessions)) +
wenzelm@65804
    42
          " AND " + SQL.enclose(sql) +
wenzelm@65849
    43
          " ORDER BY " + Build_Log.Data.pull_date)
wenzelm@65791
    44
    }
wenzelm@65791
    45
  }
wenzelm@65791
    46
wenzelm@65791
    47
wenzelm@65785
    48
  /* build status */
wenzelm@65785
    49
wenzelm@65785
    50
  def build_status(options: Options,
wenzelm@65785
    51
    progress: Progress = No_Progress,
wenzelm@65785
    52
    profiles: List[Profile] = default_profiles,
wenzelm@65785
    53
    only_sessions: Set[String] = Set.empty,
wenzelm@65785
    54
    verbose: Boolean = false,
wenzelm@65785
    55
    target_dir: Path = default_target_dir,
wenzelm@65854
    56
    ml_statistics: Boolean = false,
wenzelm@65785
    57
    image_size: (Int, Int) = default_image_size)
wenzelm@65785
    58
  {
wenzelm@65785
    59
    val data =
wenzelm@65785
    60
      read_data(options, progress = progress, profiles = profiles,
wenzelm@65854
    61
        only_sessions = only_sessions, ml_statistics = ml_statistics, verbose = verbose)
wenzelm@65785
    62
wenzelm@65785
    63
    present_data(data, progress = progress, target_dir = target_dir, image_size = image_size)
wenzelm@65785
    64
  }
wenzelm@65736
    65
wenzelm@65736
    66
wenzelm@65791
    67
  /* read data */
wenzelm@65736
    68
wenzelm@65792
    69
  sealed case class Data(date: Date, entries: List[Data_Entry])
wenzelm@65799
    70
  sealed case class Data_Entry(
wenzelm@65799
    71
    name: String, hosts: List[String], stretch: Double, sessions: List[Session])
wenzelm@65893
    72
  {
wenzelm@65893
    73
    def failed_sessions: List[Session] =
wenzelm@65893
    74
      sessions.filter(_.head.failed).sortBy(_.name)
wenzelm@65893
    75
  }
wenzelm@65865
    76
  sealed case class Session(
wenzelm@65865
    77
    name: String, threads: Int, entries: List[Entry], ml_statistics: ML_Statistics)
wenzelm@65754
    78
  {
wenzelm@65795
    79
    require(entries.nonEmpty)
wenzelm@65795
    80
wenzelm@65863
    81
    def head: Entry = entries.head
wenzelm@65863
    82
    def order: Long = - head.timing.elapsed.ms
wenzelm@65860
    83
wenzelm@65893
    84
    def finished_entries: List[Entry] = entries.filter(_.finished)
wenzelm@65893
    85
wenzelm@65893
    86
    def check_timing: Boolean = finished_entries.length >= 3
wenzelm@65854
    87
    def check_heap: Boolean =
wenzelm@65893
    88
      finished_entries.length >= 3 &&
wenzelm@65893
    89
      finished_entries.forall(entry =>
wenzelm@65859
    90
        entry.maximum_heap > 0 ||
wenzelm@65859
    91
        entry.average_heap > 0 ||
wenzelm@65866
    92
        entry.stored_heap > 0)
wenzelm@65754
    93
  }
wenzelm@65854
    94
  sealed case class Entry(
wenzelm@65854
    95
    pull_date: Date,
wenzelm@65854
    96
    isabelle_version: String,
wenzelm@65854
    97
    afp_version: String,
wenzelm@65854
    98
    timing: Timing,
wenzelm@65854
    99
    ml_timing: Timing,
wenzelm@65859
   100
    maximum_heap: Long,
wenzelm@65859
   101
    average_heap: Long,
wenzelm@65893
   102
    stored_heap: Long,
wenzelm@65940
   103
    status: Build_Log.Session_Status.Value,
wenzelm@65940
   104
    errors: List[String])
wenzelm@65893
   105
  {
wenzelm@65893
   106
    def finished: Boolean = status == Build_Log.Session_Status.finished
wenzelm@65893
   107
    def failed: Boolean = status == Build_Log.Session_Status.failed
wenzelm@65940
   108
wenzelm@65940
   109
    def present_errors(name: String): XML.Body =
wenzelm@65940
   110
      if (errors.isEmpty) HTML.text(name + " (" + isabelle_version + ")")
wenzelm@65940
   111
      else {
wenzelm@65940
   112
        val tooltip_errors =
wenzelm@65940
   113
          errors.map(msg => HTML.pre(HTML.text(Symbol.decode(msg))) + HTML.error_message_class)
wenzelm@65940
   114
        val tooltip = List(HTML.div(tooltip_errors) + HTML.tooltip_class)
wenzelm@65940
   115
        HTML.span(HTML.text(name) ::: tooltip) + HTML.error_class ::
wenzelm@65940
   116
        HTML.text(" (" + isabelle_version + ")")
wenzelm@65940
   117
      }
wenzelm@65893
   118
  }
wenzelm@65736
   119
wenzelm@65865
   120
  sealed case class Image(name: String, width: Int, height: Int)
wenzelm@65865
   121
  {
wenzelm@65865
   122
    def path: Path = Path.basic(name)
wenzelm@65865
   123
  }
wenzelm@65865
   124
wenzelm@65736
   125
  def read_data(options: Options,
wenzelm@65736
   126
    progress: Progress = No_Progress,
wenzelm@65785
   127
    profiles: List[Profile] = default_profiles,
wenzelm@65736
   128
    only_sessions: Set[String] = Set.empty,
wenzelm@65854
   129
    ml_statistics: Boolean = false,
wenzelm@65750
   130
    verbose: Boolean = false): Data =
wenzelm@65736
   131
  {
wenzelm@65754
   132
    val date = Date.now()
wenzelm@65792
   133
    var data_hosts = Map.empty[String, Set[String]]
wenzelm@65799
   134
    var data_stretch = Map.empty[String, Double]
wenzelm@65762
   135
    var data_entries = Map.empty[String, Map[String, Session]]
wenzelm@63688
   136
wenzelm@65792
   137
    def get_hosts(data_name: String): Set[String] =
wenzelm@65792
   138
      data_hosts.getOrElse(data_name, Set.empty)
wenzelm@65792
   139
wenzelm@65736
   140
    val store = Build_Log.store(options)
wenzelm@65736
   141
    using(store.open_database())(db =>
wenzelm@64089
   142
    {
wenzelm@65764
   143
      for (profile <- profiles.sortBy(_.description)) {
wenzelm@65764
   144
        progress.echo("input " + quote(profile.description))
wenzelm@65854
   145
wenzelm@65736
   146
        val columns =
wenzelm@65736
   147
          List(
wenzelm@65736
   148
            Build_Log.Data.pull_date,
wenzelm@65792
   149
            Build_Log.Prop.build_host,
wenzelm@65796
   150
            Build_Log.Prop.isabelle_version,
wenzelm@65796
   151
            Build_Log.Prop.afp_version,
wenzelm@65752
   152
            Build_Log.Settings.ISABELLE_BUILD_OPTIONS,
wenzelm@65736
   153
            Build_Log.Settings.ML_PLATFORM,
wenzelm@65736
   154
            Build_Log.Data.session_name,
wenzelm@65736
   155
            Build_Log.Data.threads,
wenzelm@65736
   156
            Build_Log.Data.timing_elapsed,
wenzelm@65736
   157
            Build_Log.Data.timing_cpu,
wenzelm@65736
   158
            Build_Log.Data.timing_gc,
wenzelm@65736
   159
            Build_Log.Data.ml_timing_elapsed,
wenzelm@65736
   160
            Build_Log.Data.ml_timing_cpu,
wenzelm@65769
   161
            Build_Log.Data.ml_timing_gc,
wenzelm@65893
   162
            Build_Log.Data.heap_size,
wenzelm@65940
   163
            Build_Log.Data.status,
wenzelm@65940
   164
            Build_Log.Data.errors) :::
wenzelm@65854
   165
          (if (ml_statistics) List(Build_Log.Data.ml_statistics) else Nil)
wenzelm@63700
   166
wenzelm@65752
   167
        val Threads_Option = """threads\s*=\s*(\d+)""".r
wenzelm@65752
   168
wenzelm@65799
   169
        val sql = profile.select(options, columns, only_sessions)
wenzelm@65750
   170
        if (verbose) progress.echo(sql)
wenzelm@65750
   171
wenzelm@65750
   172
        db.using_statement(sql)(stmt =>
wenzelm@65736
   173
        {
wenzelm@65740
   174
          val res = stmt.execute_query()
wenzelm@65740
   175
          while (res.next()) {
wenzelm@65766
   176
            val session_name = res.string(Build_Log.Data.session_name)
wenzelm@65764
   177
            val threads =
wenzelm@65764
   178
            {
wenzelm@65764
   179
              val threads1 =
wenzelm@65764
   180
                res.string(Build_Log.Settings.ISABELLE_BUILD_OPTIONS) match {
wenzelm@65895
   181
                  case Threads_Option(Value.Int(i)) => i
wenzelm@65764
   182
                  case _ => 1
wenzelm@65764
   183
                }
wenzelm@65764
   184
              val threads2 = res.get_int(Build_Log.Data.threads).getOrElse(1)
wenzelm@65764
   185
              threads1 max threads2
wenzelm@65764
   186
            }
wenzelm@65766
   187
            val ml_platform = res.string(Build_Log.Settings.ML_PLATFORM)
wenzelm@65762
   188
            val data_name =
wenzelm@65764
   189
              profile.description +
wenzelm@65764
   190
                (if (ml_platform.startsWith("x86_64")) ", 64bit" else "") +
wenzelm@65764
   191
                (if (threads == 1) "" else ", " + threads + " threads")
wenzelm@63703
   192
wenzelm@65799
   193
            res.get_string(Build_Log.Prop.build_host).foreach(host =>
wenzelm@65799
   194
              data_hosts += (data_name -> (get_hosts(data_name) + host)))
wenzelm@65799
   195
wenzelm@65799
   196
            data_stretch += (data_name -> profile.stretch(options))
wenzelm@65799
   197
wenzelm@65854
   198
            val isabelle_version = res.string(Build_Log.Prop.isabelle_version)
wenzelm@65854
   199
wenzelm@65854
   200
            val ml_stats =
wenzelm@65854
   201
              ML_Statistics(
wenzelm@65854
   202
                if (ml_statistics)
wenzelm@65857
   203
                  Properties.uncompress(res.bytes(Build_Log.Data.ml_statistics))
wenzelm@65866
   204
                else Nil, heading = session_name + " (Isabelle/" + isabelle_version + ")")
wenzelm@65854
   205
wenzelm@65736
   206
            val entry =
wenzelm@65796
   207
              Entry(
wenzelm@65796
   208
                pull_date = res.date(Build_Log.Data.pull_date),
wenzelm@65854
   209
                isabelle_version = isabelle_version,
wenzelm@65796
   210
                afp_version = res.string(Build_Log.Prop.afp_version),
wenzelm@65796
   211
                timing =
wenzelm@65796
   212
                  res.timing(
wenzelm@65796
   213
                    Build_Log.Data.timing_elapsed,
wenzelm@65796
   214
                    Build_Log.Data.timing_cpu,
wenzelm@65796
   215
                    Build_Log.Data.timing_gc),
wenzelm@65796
   216
                ml_timing =
wenzelm@65796
   217
                  res.timing(
wenzelm@65796
   218
                    Build_Log.Data.ml_timing_elapsed,
wenzelm@65796
   219
                    Build_Log.Data.ml_timing_cpu,
wenzelm@65796
   220
                    Build_Log.Data.ml_timing_gc),
wenzelm@65859
   221
                maximum_heap = ml_stats.maximum_heap_size,
wenzelm@65859
   222
                average_heap = ml_stats.average_heap_size,
wenzelm@65893
   223
                stored_heap = ML_Statistics.heap_scale(res.long(Build_Log.Data.heap_size)),
wenzelm@65940
   224
                status = Build_Log.Session_Status.withName(res.string(Build_Log.Data.status)),
wenzelm@65940
   225
                errors = Build_Log.uncompress_errors(res.bytes(Build_Log.Data.errors)))
wenzelm@65736
   226
wenzelm@65762
   227
            val sessions = data_entries.getOrElse(data_name, Map.empty)
wenzelm@65766
   228
            val entries = sessions.get(session_name).map(_.entries) getOrElse Nil
wenzelm@65865
   229
            val session = Session(session_name, threads, entry :: entries, ml_stats)
wenzelm@65766
   230
            data_entries += (data_name -> (sessions + (session_name -> session)))
wenzelm@65736
   231
          }
wenzelm@65736
   232
        })
wenzelm@65736
   233
      }
wenzelm@65736
   234
    })
wenzelm@65736
   235
wenzelm@65792
   236
    val sorted_entries =
wenzelm@65762
   237
      (for {
wenzelm@65792
   238
        (name, sessions) <- data_entries.toList
wenzelm@65847
   239
        sorted_sessions <- proper_list(sessions.toList.map(_._2).sortBy(_.order))
wenzelm@65799
   240
      }
wenzelm@65799
   241
      yield {
wenzelm@65799
   242
        val hosts = get_hosts(name).toList.sorted
wenzelm@65799
   243
        val stretch = data_stretch(name)
wenzelm@65799
   244
        Data_Entry(name, hosts, stretch, sorted_sessions)
wenzelm@65799
   245
      }).sortBy(_.name)
wenzelm@65792
   246
wenzelm@65792
   247
    Data(date, sorted_entries)
wenzelm@65736
   248
  }
wenzelm@65736
   249
wenzelm@65736
   250
wenzelm@65736
   251
  /* present data */
wenzelm@65736
   252
wenzelm@65736
   253
  def present_data(data: Data,
wenzelm@65736
   254
    progress: Progress = No_Progress,
wenzelm@65736
   255
    target_dir: Path = default_target_dir,
wenzelm@65759
   256
    image_size: (Int, Int) = default_image_size)
wenzelm@65736
   257
  {
wenzelm@65791
   258
    def clean_name(name: String): String =
wenzelm@65791
   259
      name.flatMap(c => if (c == ' ' || c == '/') "_" else if (c == ',') "" else c.toString)
wenzelm@65791
   260
wenzelm@65860
   261
    def print_heap(x: Long): Option[String] =
wenzelm@65866
   262
      if (x == 0L) None else Some(x.toString + " M")
wenzelm@65854
   263
wenzelm@65838
   264
    HTML.write_document(target_dir, "index.html",
wenzelm@65838
   265
      List(HTML.title("Isabelle build status")),
wenzelm@65838
   266
      List(HTML.chapter("Isabelle build status"),
wenzelm@65838
   267
        HTML.par(
wenzelm@65838
   268
          List(HTML.description(
wenzelm@65838
   269
            List(HTML.text("status date:") -> HTML.text(data.date.toString))))),
wenzelm@65838
   270
        HTML.par(
wenzelm@65838
   271
          List(HTML.itemize(data.entries.map({ case data_entry =>
wenzelm@65893
   272
            List(
wenzelm@65893
   273
              HTML.link(clean_name(data_entry.name) + "/index.html",
wenzelm@65893
   274
                HTML.text(data_entry.name))) :::
wenzelm@65893
   275
            (data_entry.failed_sessions match {
wenzelm@65893
   276
              case Nil => Nil
wenzelm@65893
   277
              case sessions =>
wenzelm@65940
   278
                HTML.break :::
wenzelm@65940
   279
                List(HTML.span(HTML.text("Failed sessions:")) + HTML.error_message_class) :::
wenzelm@65940
   280
                List(HTML.itemize(sessions.map(s => s.head.present_errors(s.name))))
wenzelm@65893
   281
            })
wenzelm@65893
   282
          }))))))
wenzelm@65786
   283
wenzelm@65792
   284
    for (data_entry <- data.entries) {
wenzelm@65792
   285
      val data_name = data_entry.name
wenzelm@65792
   286
wenzelm@65865
   287
      val (image_width, image_height) = image_size
wenzelm@65865
   288
      val image_width_stretch = (image_width * data_entry.stretch).toInt
wenzelm@65799
   289
wenzelm@65786
   290
      progress.echo("output " + quote(data_name))
wenzelm@65786
   291
wenzelm@65764
   292
      val dir = target_dir + Path.basic(clean_name(data_name))
wenzelm@65736
   293
      Isabelle_System.mkdirs(dir)
wenzelm@65736
   294
wenzelm@65764
   295
      val session_plots =
wenzelm@65764
   296
        Par_List.map((session: Session) =>
wenzelm@65764
   297
          Isabelle_System.with_tmp_file(session.name, "data") { data_file =>
wenzelm@65764
   298
            Isabelle_System.with_tmp_file(session.name, "gnuplot") { gnuplot_file =>
wenzelm@63706
   299
wenzelm@65865
   300
              def plot_name(kind: String): String = session.name + "_" + kind + ".png"
wenzelm@65865
   301
wenzelm@65764
   302
              File.write(data_file,
wenzelm@65764
   303
                cat_lines(
wenzelm@65893
   304
                  session.finished_entries.map(entry =>
wenzelm@65854
   305
                    List(entry.pull_date.unix_epoch,
wenzelm@65764
   306
                      entry.timing.elapsed.minutes,
wenzelm@65764
   307
                      entry.timing.resources.minutes,
wenzelm@65764
   308
                      entry.ml_timing.elapsed.minutes,
wenzelm@65769
   309
                      entry.ml_timing.resources.minutes,
wenzelm@65866
   310
                      entry.maximum_heap,
wenzelm@65866
   311
                      entry.average_heap,
wenzelm@65866
   312
                      entry.stored_heap).mkString(" "))))
wenzelm@65736
   313
wenzelm@65764
   314
              val max_time =
wenzelm@65893
   315
                ((0.0 /: session.finished_entries){ case (m, entry) =>
wenzelm@65764
   316
                  m.max(entry.timing.elapsed.minutes).
wenzelm@65764
   317
                    max(entry.timing.resources.minutes).
wenzelm@65764
   318
                    max(entry.ml_timing.elapsed.minutes).
wenzelm@65764
   319
                    max(entry.ml_timing.resources.minutes) } max 0.1) * 1.1
wenzelm@65769
   320
              val timing_range = "[0:" + max_time + "]"
wenzelm@65763
   321
wenzelm@65865
   322
              def gnuplot(plot_name: String, plots: List[String], range: String): Image =
wenzelm@65764
   323
              {
wenzelm@65865
   324
                val image = Image(plot_name, image_width_stretch, image_height)
wenzelm@65764
   325
wenzelm@65764
   326
                File.write(gnuplot_file, """
wenzelm@65865
   327
set terminal png size """ + image.width + "," + image.height + """
wenzelm@65865
   328
set output """ + quote(File.standard_path(dir + image.path)) + """
wenzelm@65759
   329
set xdata time
wenzelm@65759
   330
set timefmt "%s"
wenzelm@65759
   331
set format x "%d-%b"
wenzelm@65762
   332
set xlabel """ + quote(session.name) + """ noenhanced
wenzelm@65763
   333
set key left bottom
wenzelm@65769
   334
plot [] """ + range + " " +
wenzelm@65769
   335
                plots.map(s => quote(data_file.implode) + " " + s).mkString(", ") + "\n")
wenzelm@65759
   336
wenzelm@65764
   337
                val result =
wenzelm@65764
   338
                  Isabelle_System.bash("\"$ISABELLE_GNUPLOT\" " + File.bash_path(gnuplot_file))
wenzelm@65764
   339
                if (!result.ok)
wenzelm@65764
   340
                  result.error("Gnuplot failed for " + data_name + "/" + plot_name).check
wenzelm@65764
   341
wenzelm@65865
   342
                image
wenzelm@65764
   343
              }
wenzelm@65759
   344
wenzelm@65765
   345
              val timing_plots =
wenzelm@65769
   346
              {
wenzelm@65769
   347
                val plots1 =
wenzelm@65769
   348
                  List(
wenzelm@65769
   349
                    """ using 1:2 smooth sbezier title "elapsed time (smooth)" """,
wenzelm@65769
   350
                    """ using 1:2 smooth csplines title "elapsed time" """)
wenzelm@65769
   351
                val plots2 =
wenzelm@65769
   352
                  List(
wenzelm@65769
   353
                    """ using 1:3 smooth sbezier title "cpu time (smooth)" """,
wenzelm@65769
   354
                    """ using 1:3 smooth csplines title "cpu time" """)
wenzelm@65769
   355
                if (session.threads == 1) plots1 else plots1 ::: plots2
wenzelm@65769
   356
              }
wenzelm@65765
   357
wenzelm@65764
   358
              val ml_timing_plots =
wenzelm@65764
   359
                List(
wenzelm@65765
   360
                  """ using 1:4 smooth sbezier title "ML elapsed time (smooth)" """,
wenzelm@65765
   361
                  """ using 1:4 smooth csplines title "ML elapsed time" """,
wenzelm@65764
   362
                  """ using 1:5 smooth sbezier title "ML cpu time (smooth)" """,
wenzelm@65765
   363
                  """ using 1:5 smooth csplines title "ML cpu time" """)
wenzelm@65736
   364
wenzelm@65769
   365
              val heap_plots =
wenzelm@65769
   366
                List(
wenzelm@65859
   367
                  """ using 1:6 smooth sbezier title "maximum heap (smooth)" """,
wenzelm@65859
   368
                  """ using 1:6 smooth csplines title "maximum heap" """,
wenzelm@65859
   369
                  """ using 1:7 smooth sbezier title "average heap (smooth)" """,
wenzelm@65859
   370
                  """ using 1:7 smooth csplines title "average heap" """,
wenzelm@65868
   371
                  """ using 1:8 smooth sbezier title "stored heap (smooth)" """,
wenzelm@65868
   372
                  """ using 1:8 smooth csplines title "stored heap" """)
wenzelm@65769
   373
wenzelm@65865
   374
              def jfreechart(plot_name: String, fields: ML_Statistics.Fields): Image =
wenzelm@65865
   375
              {
wenzelm@65865
   376
                val image = Image(plot_name, image_width, image_height)
wenzelm@65865
   377
                val chart =
wenzelm@65865
   378
                  session.ml_statistics.chart(
wenzelm@65865
   379
                    fields._1 + ": " + session.ml_statistics.heading, fields._2)
wenzelm@65865
   380
                Graphics_File.write_chart_png(
wenzelm@65865
   381
                  (dir + image.path).file, chart, image.width, image.height)
wenzelm@65865
   382
                image
wenzelm@65865
   383
              }
wenzelm@65865
   384
wenzelm@65865
   385
              val images =
wenzelm@65847
   386
                (if (session.check_timing)
wenzelm@65847
   387
                  List(
wenzelm@65865
   388
                    gnuplot(plot_name("timing"), timing_plots, timing_range),
wenzelm@65865
   389
                    gnuplot(plot_name("ml_timing"), ml_timing_plots, timing_range))
wenzelm@65865
   390
                 else Nil) :::
wenzelm@65865
   391
                (if (session.check_heap)
wenzelm@65865
   392
                  List(gnuplot(plot_name("heap"), heap_plots, "[0:]"))
wenzelm@65847
   393
                 else Nil) :::
wenzelm@65865
   394
                (if (session.ml_statistics.content.nonEmpty)
wenzelm@65865
   395
                  List(jfreechart(plot_name("heap_chart"), ML_Statistics.heap_fields)) :::
wenzelm@65865
   396
                  (if (session.threads > 1)
wenzelm@65867
   397
                    List(
wenzelm@65867
   398
                      jfreechart(plot_name("tasks_chart"), ML_Statistics.tasks_fields),
wenzelm@65867
   399
                      jfreechart(plot_name("workers_chart"), ML_Statistics.workers_fields))
wenzelm@65865
   400
                   else Nil)
wenzelm@65865
   401
                 else Nil)
wenzelm@65769
   402
wenzelm@65865
   403
              session.name -> images
wenzelm@65764
   404
            }
wenzelm@65792
   405
          }, data_entry.sessions).toMap
wenzelm@65754
   406
wenzelm@65838
   407
      HTML.write_document(dir, "index.html",
wenzelm@65838
   408
        List(HTML.title("Isabelle build status for " + data_name)),
wenzelm@65838
   409
        HTML.chapter("Isabelle build status for " + data_name) ::
wenzelm@65838
   410
        HTML.par(
wenzelm@65838
   411
          List(HTML.description(
wenzelm@65754
   412
            List(
wenzelm@65838
   413
              HTML.text("status date:") -> HTML.text(data.date.toString),
wenzelm@65838
   414
              HTML.text("build host:") -> HTML.text(commas(data_entry.hosts)))))) ::
wenzelm@65838
   415
        HTML.par(
wenzelm@65838
   416
          List(HTML.itemize(
wenzelm@65838
   417
            data_entry.sessions.map(session =>
wenzelm@65838
   418
              HTML.link("#session_" + session.name, HTML.text(session.name)) ::
wenzelm@65863
   419
              HTML.text(" (" + session.head.timing.message_resources + ")"))))) ::
wenzelm@65838
   420
        data_entry.sessions.flatMap(session =>
wenzelm@65838
   421
          List(
wenzelm@65838
   422
            HTML.section(session.name) + HTML.id("session_" + session.name),
wenzelm@65838
   423
            HTML.par(
wenzelm@65838
   424
              HTML.description(
wenzelm@65838
   425
                List(
wenzelm@65863
   426
                  HTML.text("timing:") -> HTML.text(session.head.timing.message_resources),
wenzelm@65863
   427
                  HTML.text("ML timing:") -> HTML.text(session.head.ml_timing.message_resources)) :::
wenzelm@65863
   428
                print_heap(session.head.maximum_heap).map(s =>
wenzelm@65860
   429
                  HTML.text("maximum heap:") -> HTML.text(s)).toList :::
wenzelm@65863
   430
                print_heap(session.head.average_heap).map(s =>
wenzelm@65860
   431
                  HTML.text("average heap:") -> HTML.text(s)).toList :::
wenzelm@65866
   432
                print_heap(session.head.stored_heap).map(s =>
wenzelm@65866
   433
                  HTML.text("stored heap:") -> HTML.text(s)).toList :::
wenzelm@65863
   434
                proper_string(session.head.isabelle_version).map(s =>
wenzelm@65838
   435
                  HTML.text("Isabelle version:") -> HTML.text(s)).toList :::
wenzelm@65863
   436
                proper_string(session.head.afp_version).map(s =>
wenzelm@65838
   437
                  HTML.text("AFP version:") -> HTML.text(s)).toList) ::
wenzelm@65865
   438
              session_plots.getOrElse(session.name, Nil).map(image =>
wenzelm@65865
   439
                HTML.image(image.name) +
wenzelm@65865
   440
                  HTML.width(image.width / 2) +
wenzelm@65865
   441
                  HTML.height(image.height / 2))))))
wenzelm@63688
   442
    }
wenzelm@63688
   443
  }
wenzelm@63688
   444
wenzelm@63688
   445
wenzelm@63688
   446
  /* Isabelle tool wrapper */
wenzelm@63688
   447
wenzelm@63688
   448
  val isabelle_tool =
wenzelm@65743
   449
    Isabelle_Tool("build_status", "present recent build status information from database", args =>
wenzelm@63688
   450
    {
wenzelm@65736
   451
      var target_dir = default_target_dir
wenzelm@65854
   452
      var ml_statistics = false
wenzelm@65736
   453
      var only_sessions = Set.empty[String]
wenzelm@65736
   454
      var options = Options.init()
wenzelm@65736
   455
      var image_size = default_image_size
wenzelm@65750
   456
      var verbose = false
wenzelm@63688
   457
wenzelm@63688
   458
      val getopts = Getopts("""
wenzelm@65743
   459
Usage: isabelle build_status [OPTIONS]
wenzelm@63688
   460
wenzelm@63688
   461
  Options are:
wenzelm@65737
   462
    -D DIR       target directory (default """ + default_target_dir + """)
wenzelm@65854
   463
    -M           include full ML statistics
wenzelm@63700
   464
    -S SESSIONS  only given SESSIONS (comma separated)
wenzelm@65736
   465
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
wenzelm@65737
   466
    -s WxH       size of PNG image (default """ + image_size._1 + "x" + image_size._2 + """)
wenzelm@65750
   467
    -v           verbose
wenzelm@63688
   468
wenzelm@65736
   469
  Present performance statistics from build log database, which is specified
wenzelm@65782
   470
  via system options build_log_database_host, build_log_database_user,
wenzelm@65782
   471
  build_log_history etc.
wenzelm@63688
   472
""",
wenzelm@63688
   473
        "D:" -> (arg => target_dir = Path.explode(arg)),
wenzelm@65854
   474
        "M" -> (_ => ml_statistics = true),
wenzelm@63700
   475
        "S:" -> (arg => only_sessions = space_explode(',', arg).toSet),
wenzelm@65736
   476
        "o:" -> (arg => options = options + arg),
wenzelm@63700
   477
        "s:" -> (arg =>
wenzelm@63805
   478
          space_explode('x', arg).map(Value.Int.parse(_)) match {
wenzelm@65736
   479
            case List(w, h) if w > 0 && h > 0 => image_size = (w, h)
wenzelm@63700
   480
            case _ => error("Error bad PNG image size: " + quote(arg))
wenzelm@65750
   481
          }),
wenzelm@65750
   482
        "v" -> (_ => verbose = true))
wenzelm@63688
   483
wenzelm@65736
   484
      val more_args = getopts(args)
wenzelm@65736
   485
      if (more_args.nonEmpty) getopts.usage()
wenzelm@63700
   486
wenzelm@65736
   487
      val progress = new Console_Progress
wenzelm@63688
   488
wenzelm@65785
   489
      build_status(options, progress = progress, only_sessions = only_sessions, verbose = verbose,
wenzelm@65854
   490
        target_dir = target_dir, ml_statistics = ml_statistics, image_size = image_size)
wenzelm@65736
   491
wenzelm@64161
   492
  }, admin = true)
wenzelm@63686
   493
}