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