src/Pure/Admin/build_status.scala
author wenzelm
Tue, 09 May 2017 20:36:34 +0200
changeset 65792 c58752102b34
parent 65791 cf48ef4f4e63
child 65794 a880f41a8d0f
permissions -rw-r--r--
more output;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65743
4847ca570454 clarified name;
wenzelm
parents: 65742
diff changeset
     1
/*  Title:      Pure/Admin/build_status.scala
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     3
65743
4847ca570454 clarified name;
wenzelm
parents: 65742
diff changeset
     4
Present recent build status information from database.
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     5
*/
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     6
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     7
package isabelle
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     8
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     9
65743
4847ca570454 clarified name;
wenzelm
parents: 65742
diff changeset
    10
object Build_Status
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    11
{
65791
wenzelm
parents: 65786
diff changeset
    12
  /* data profiles */
wenzelm
parents: 65786
diff changeset
    13
wenzelm
parents: 65786
diff changeset
    14
  sealed case class Profile(description: String, sql: String)
wenzelm
parents: 65786
diff changeset
    15
  {
wenzelm
parents: 65786
diff changeset
    16
    def select(columns: List[SQL.Column], days: Int, only_sessions: Set[String]): SQL.Source =
wenzelm
parents: 65786
diff changeset
    17
    {
wenzelm
parents: 65786
diff changeset
    18
      val sql_sessions =
wenzelm
parents: 65786
diff changeset
    19
        if (only_sessions.isEmpty) ""
wenzelm
parents: 65786
diff changeset
    20
        else
wenzelm
parents: 65786
diff changeset
    21
          only_sessions.iterator.map(a => Build_Log.Data.session_name + " = " + SQL.string(a))
wenzelm
parents: 65786
diff changeset
    22
            .mkString("(", " OR ", ") AND ")
wenzelm
parents: 65786
diff changeset
    23
wenzelm
parents: 65786
diff changeset
    24
      Build_Log.Data.universal_table.select(columns, distinct = true,
wenzelm
parents: 65786
diff changeset
    25
        sql = "WHERE " +
wenzelm
parents: 65786
diff changeset
    26
          Build_Log.Data.pull_date + " > " + Build_Log.Data.recent_time(days) + " AND " +
wenzelm
parents: 65786
diff changeset
    27
          Build_Log.Data.status + " = " + SQL.string(Build_Log.Session_Status.finished.toString) +
wenzelm
parents: 65786
diff changeset
    28
          " AND " + sql_sessions + SQL.enclose(sql) +
wenzelm
parents: 65786
diff changeset
    29
          " ORDER BY " + Build_Log.Data.pull_date + " DESC")
wenzelm
parents: 65786
diff changeset
    30
    }
wenzelm
parents: 65786
diff changeset
    31
  }
wenzelm
parents: 65786
diff changeset
    32
wenzelm
parents: 65786
diff changeset
    33
65785
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    34
  /* build status */
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    35
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    36
  val default_target_dir = Path.explode("build_status")
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    37
  val default_image_size = (800, 600)
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    38
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    39
  def default_profiles: List[Profile] =
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    40
    Jenkins.build_status_profiles ::: Isabelle_Cronjob.build_status_profiles
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    41
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    42
  def build_status(options: Options,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    43
    progress: Progress = No_Progress,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    44
    profiles: List[Profile] = default_profiles,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    45
    only_sessions: Set[String] = Set.empty,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    46
    verbose: Boolean = false,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    47
    target_dir: Path = default_target_dir,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    48
    image_size: (Int, Int) = default_image_size)
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    49
  {
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    50
    val data =
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    51
      read_data(options, progress = progress, profiles = profiles,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    52
        only_sessions = only_sessions, verbose = verbose)
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    53
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    54
    present_data(data, progress = progress, target_dir = target_dir, image_size = image_size)
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    55
  }
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    56
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    57
65791
wenzelm
parents: 65786
diff changeset
    58
  /* read data */
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    59
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    60
  sealed case class Data(date: Date, entries: List[Data_Entry])
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    61
  sealed case class Data_Entry(name: String, hosts: List[String], sessions: List[Session])
65765
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
    62
  sealed case class Session(name: String, threads: Int, entries: List[Entry])
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
    63
  {
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
    64
    def timing: Timing = if (entries.isEmpty) Timing.zero else entries.head.timing
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
    65
    def ml_timing: Timing = if (entries.isEmpty) Timing.zero else entries.head.ml_timing
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
    66
    def order: Long = - timing.elapsed.ms
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
    67
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
    68
    def check_timing: Boolean = entries.length >= 3
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
    69
    def check_heap: Boolean = entries.forall(_.heap_size > 0)
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
    70
  }
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
    71
  sealed case class Entry(date: Date, timing: Timing, ml_timing: Timing, heap_size: Long)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    72
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    73
  def read_data(options: Options,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    74
    progress: Progress = No_Progress,
65785
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
    75
    profiles: List[Profile] = default_profiles,
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    76
    only_sessions: Set[String] = Set.empty,
65750
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
    77
    verbose: Boolean = false): Data =
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    78
  {
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
    79
    val date = Date.now()
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    80
    var data_hosts = Map.empty[String, Set[String]]
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
    81
    var data_entries = Map.empty[String, Map[String, Session]]
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    82
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    83
    def get_hosts(data_name: String): Set[String] =
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    84
      data_hosts.getOrElse(data_name, Set.empty)
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    85
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    86
    val store = Build_Log.store(options)
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    87
    using(store.open_database())(db =>
64089
10d719dbb3ee more permissive timing data;
wenzelm
parents: 64085
diff changeset
    88
    {
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
    89
      for (profile <- profiles.sortBy(_.description)) {
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
    90
        progress.echo("input " + quote(profile.description))
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    91
        val columns =
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    92
          List(
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    93
            Build_Log.Data.pull_date,
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
    94
            Build_Log.Prop.build_host,
65752
ed7b5cd3a7f2 more uniform threads value, notably for Pure session;
wenzelm
parents: 65751
diff changeset
    95
            Build_Log.Settings.ISABELLE_BUILD_OPTIONS,
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    96
            Build_Log.Settings.ML_PLATFORM,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    97
            Build_Log.Data.session_name,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    98
            Build_Log.Data.threads,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
    99
            Build_Log.Data.timing_elapsed,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   100
            Build_Log.Data.timing_cpu,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   101
            Build_Log.Data.timing_gc,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   102
            Build_Log.Data.ml_timing_elapsed,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   103
            Build_Log.Data.ml_timing_cpu,
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   104
            Build_Log.Data.ml_timing_gc,
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   105
            Build_Log.Data.heap_size)
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   106
65752
ed7b5cd3a7f2 more uniform threads value, notably for Pure session;
wenzelm
parents: 65751
diff changeset
   107
        val Threads_Option = """threads\s*=\s*(\d+)""".r
ed7b5cd3a7f2 more uniform threads value, notably for Pure session;
wenzelm
parents: 65751
diff changeset
   108
65782
4935bac8a850 simplified default;
wenzelm
parents: 65773
diff changeset
   109
        val sql = profile.select(columns, options.int("build_log_history"), only_sessions)
65750
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   110
        if (verbose) progress.echo(sql)
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   111
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   112
        db.using_statement(sql)(stmt =>
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   113
        {
65740
83388f09e9ab clarified signature;
wenzelm
parents: 65737
diff changeset
   114
          val res = stmt.execute_query()
83388f09e9ab clarified signature;
wenzelm
parents: 65737
diff changeset
   115
          while (res.next()) {
65766
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   116
            val session_name = res.string(Build_Log.Data.session_name)
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   117
            val threads =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   118
            {
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   119
              val threads1 =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   120
                res.string(Build_Log.Settings.ISABELLE_BUILD_OPTIONS) match {
65766
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   121
                  case Threads_Option(Value.Int(i)) if session_name == "Pure" => i
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   122
                  case _ => 1
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   123
                }
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   124
              val threads2 = res.get_int(Build_Log.Data.threads).getOrElse(1)
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   125
              threads1 max threads2
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   126
            }
65766
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   127
            val ml_platform = res.string(Build_Log.Settings.ML_PLATFORM)
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
   128
            val data_name =
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   129
              profile.description +
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   130
                (if (ml_platform.startsWith("x86_64")) ", 64bit" else "") +
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   131
                (if (threads == 1) "" else ", " + threads + " threads")
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   132
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   133
            val entry =
65740
83388f09e9ab clarified signature;
wenzelm
parents: 65737
diff changeset
   134
              Entry(res.date(Build_Log.Data.pull_date),
65741
wenzelm
parents: 65740
diff changeset
   135
                res.timing(
wenzelm
parents: 65740
diff changeset
   136
                  Build_Log.Data.timing_elapsed,
wenzelm
parents: 65740
diff changeset
   137
                  Build_Log.Data.timing_cpu,
wenzelm
parents: 65740
diff changeset
   138
                  Build_Log.Data.timing_gc),
wenzelm
parents: 65740
diff changeset
   139
                res.timing(
wenzelm
parents: 65740
diff changeset
   140
                  Build_Log.Data.ml_timing_elapsed,
wenzelm
parents: 65740
diff changeset
   141
                  Build_Log.Data.ml_timing_cpu,
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   142
                  Build_Log.Data.ml_timing_gc),
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   143
                heap_size = res.long(Build_Log.Data.heap_size))
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   144
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   145
            res.get_string(Build_Log.Prop.build_host).foreach(host =>
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   146
              data_hosts += (data_name -> (get_hosts(data_name) + host)))
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   147
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
   148
            val sessions = data_entries.getOrElse(data_name, Map.empty)
65766
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   149
            val entries = sessions.get(session_name).map(_.entries) getOrElse Nil
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   150
            val session = Session(session_name, threads, entry :: entries)
2edb89630a80 more specific workaround (see also ed7b5cd3a7f2);
wenzelm
parents: 65765
diff changeset
   151
            data_entries += (data_name -> (sessions + (session_name -> session)))
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   152
          }
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   153
        })
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   154
      }
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   155
    })
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   156
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   157
    val sorted_entries =
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
   158
      (for {
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   159
        (name, sessions) <- data_entries.toList
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   160
        sorted_sessions <-
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   161
          proper_list(sessions.toList.map(_._2).filter(_.check_timing).sortBy(_.order))
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   162
      } yield Data_Entry(name, get_hosts(name).toList.sorted, sorted_sessions)).sortBy(_.name)
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   163
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   164
    Data(date, sorted_entries)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   165
  }
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   166
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   167
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   168
  /* present data */
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   169
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   170
  def present_data(data: Data,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   171
    progress: Progress = No_Progress,
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   172
    target_dir: Path = default_target_dir,
65759
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   173
    image_size: (Int, Int) = default_image_size)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   174
  {
65791
wenzelm
parents: 65786
diff changeset
   175
    def clean_name(name: String): String =
wenzelm
parents: 65786
diff changeset
   176
      name.flatMap(c => if (c == ' ' || c == '/') "_" else if (c == ',') "" else c.toString)
wenzelm
parents: 65786
diff changeset
   177
65786
wenzelm
parents: 65785
diff changeset
   178
    Isabelle_System.mkdirs(target_dir)
wenzelm
parents: 65785
diff changeset
   179
    File.write(target_dir + Path.basic("index.html"),
wenzelm
parents: 65785
diff changeset
   180
      HTML.output_document(
wenzelm
parents: 65785
diff changeset
   181
        List(HTML.title("Isabelle build status")),
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   182
        List(HTML.chapter("Isabelle build status"),
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   183
          HTML.itemize(data.entries.map({ case data_entry =>
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   184
            List(HTML.link(clean_name(data_entry.name) + "/index.html", HTML.text(data_entry.name)))
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   185
          })))))
65786
wenzelm
parents: 65785
diff changeset
   186
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   187
    for (data_entry <- data.entries) {
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   188
      val data_name = data_entry.name
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   189
65786
wenzelm
parents: 65785
diff changeset
   190
      progress.echo("output " + quote(data_name))
wenzelm
parents: 65785
diff changeset
   191
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   192
      val dir = target_dir + Path.basic(clean_name(data_name))
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   193
      Isabelle_System.mkdirs(dir)
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   194
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   195
      val session_plots =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   196
        Par_List.map((session: Session) =>
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   197
          Isabelle_System.with_tmp_file(session.name, "data") { data_file =>
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   198
            Isabelle_System.with_tmp_file(session.name, "gnuplot") { gnuplot_file =>
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   199
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   200
              File.write(data_file,
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   201
                cat_lines(
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   202
                  session.entries.map(entry =>
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   203
                    List(entry.date.unix_epoch.toString,
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   204
                      entry.timing.elapsed.minutes,
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   205
                      entry.timing.resources.minutes,
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   206
                      entry.ml_timing.elapsed.minutes,
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   207
                      entry.ml_timing.resources.minutes,
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   208
                      (entry.heap_size.toDouble / (1024 * 1024)).toString).mkString(" "))))
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   209
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   210
              val max_time =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   211
                ((0.0 /: session.entries){ case (m, entry) =>
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   212
                  m.max(entry.timing.elapsed.minutes).
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   213
                    max(entry.timing.resources.minutes).
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   214
                    max(entry.ml_timing.elapsed.minutes).
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   215
                    max(entry.ml_timing.resources.minutes) } max 0.1) * 1.1
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   216
              val timing_range = "[0:" + max_time + "]"
65763
dbadcc3fbe33 tuned output;
wenzelm
parents: 65762
diff changeset
   217
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   218
              def gnuplot(plots: List[String], kind: String, range: String): String =
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   219
              {
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   220
                val plot_name = session.name + "_" + kind + ".png"
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   221
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   222
                File.write(gnuplot_file, """
65759
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   223
set terminal png size """ + image_size._1 + "," + image_size._2 + """
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   224
set output """ + quote(File.standard_path(dir + Path.basic(plot_name))) + """
65759
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   225
set xdata time
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   226
set timefmt "%s"
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   227
set format x "%d-%b"
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
   228
set xlabel """ + quote(session.name) + """ noenhanced
65763
dbadcc3fbe33 tuned output;
wenzelm
parents: 65762
diff changeset
   229
set key left bottom
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   230
plot [] """ + range + " " +
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   231
                plots.map(s => quote(data_file.implode) + " " + s).mkString(", ") + "\n")
65759
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   232
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   233
                val result =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   234
                  Isabelle_System.bash("\"$ISABELLE_GNUPLOT\" " + File.bash_path(gnuplot_file))
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   235
                if (!result.ok)
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   236
                  result.error("Gnuplot failed for " + data_name + "/" + plot_name).check
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   237
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   238
                plot_name
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   239
              }
65759
a2b041a36523 always show ml_timing -- in another chart;
wenzelm
parents: 65758
diff changeset
   240
65765
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
   241
              val timing_plots =
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   242
              {
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   243
                val plots1 =
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   244
                  List(
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   245
                    """ using 1:2 smooth sbezier title "elapsed time (smooth)" """,
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   246
                    """ using 1:2 smooth csplines title "elapsed time" """)
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   247
                val plots2 =
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   248
                  List(
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   249
                    """ using 1:3 smooth sbezier title "cpu time (smooth)" """,
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   250
                    """ using 1:3 smooth csplines title "cpu time" """)
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   251
                if (session.threads == 1) plots1 else plots1 ::: plots2
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   252
              }
65765
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
   253
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   254
              val ml_timing_plots =
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   255
                List(
65765
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
   256
                  """ using 1:4 smooth sbezier title "ML elapsed time (smooth)" """,
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
   257
                  """ using 1:4 smooth csplines title "ML elapsed time" """,
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   258
                  """ using 1:5 smooth sbezier title "ML cpu time (smooth)" """,
65765
c67bb109cd7b cpu time is somewhat redundant for threads=1;
wenzelm
parents: 65764
diff changeset
   259
                  """ using 1:5 smooth csplines title "ML cpu time" """)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   260
65769
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   261
              val heap_plots =
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   262
                List(
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   263
                  """ using 1:6 smooth sbezier title "heap (smooth)" """,
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   264
                  """ using 1:6 smooth csplines title "heap" """)
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   265
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   266
              val plot_names =
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   267
                List(
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   268
                  gnuplot(timing_plots, "timing", timing_range),
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   269
                  gnuplot(ml_timing_plots, "ml_timing", timing_range)) :::
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   270
                (if (session.check_heap) List(gnuplot(heap_plots, "heap", "[0:]")) else Nil)
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   271
490b7c517000 plot heap size;
wenzelm
parents: 65766
diff changeset
   272
              session.name -> plot_names
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   273
            }
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   274
          }, data_entry.sessions).toMap
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
   275
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   276
      File.write(dir + Path.basic("index.html"),
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
   277
        HTML.output_document(
65760
a51290fd62d9 more uniform charts;
wenzelm
parents: 65759
diff changeset
   278
          List(HTML.title("Isabelle build status for " + data_name)),
65792
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   279
          HTML.chapter("Isabelle build status for " + data_name) ::
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   280
          HTML.par(
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   281
            List(HTML.itemize(
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   282
              List(
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   283
                HTML.bold(HTML.text("build host: ")) :: HTML.text(commas(data_entry.hosts)),
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   284
                HTML.bold(HTML.text("status date: ")) :: HTML.text(data.date.toString))))) ::
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   285
          HTML.par(
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   286
            List(HTML.itemize(
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   287
              data_entry.sessions.map(session =>
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   288
                HTML.link("#session_" + session.name, HTML.text(session.name)) ::
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   289
                HTML.text(" (" + session.timing.message_resources + ")"))))) ::
c58752102b34 more output;
wenzelm
parents: 65791
diff changeset
   290
          data_entry.sessions.flatMap(session =>
65754
05c6a29c9132 clarified explicit Build_Status.Data operations;
wenzelm
parents: 65752
diff changeset
   291
            List(
65762
295b845243d3 clarified types;
wenzelm
parents: 65760
diff changeset
   292
              HTML.section(session.name) + HTML.id("session_" + session.name),
65755
21b4bfa6d204 more HTML output;
wenzelm
parents: 65754
diff changeset
   293
              HTML.par(
65764
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   294
                HTML.itemize(List(
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   295
                  HTML.bold(HTML.text("timing: ")) :: HTML.text(session.timing.message_resources),
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   296
                  HTML.bold(HTML.text("ML timing: ")) ::
1af6d544c2a3 clarified description vs. file name;
wenzelm
parents: 65763
diff changeset
   297
                    HTML.text(session.ml_timing.message_resources))) ::
65773
120ef768c84c clarified image size;
wenzelm
parents: 65769
diff changeset
   298
                session_plots.getOrElse(session.name, Nil).map(plot_name =>
120ef768c84c clarified image size;
wenzelm
parents: 65769
diff changeset
   299
                  HTML.image(plot_name) +
120ef768c84c clarified image size;
wenzelm
parents: 65769
diff changeset
   300
                    HTML.width(image_size._1 / 2) +
120ef768c84c clarified image size;
wenzelm
parents: 65769
diff changeset
   301
                    HTML.height(image_size._2 / 2)))))))
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   302
    }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   303
  }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   304
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   305
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   306
  /* Isabelle tool wrapper */
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   307
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   308
  val isabelle_tool =
65743
4847ca570454 clarified name;
wenzelm
parents: 65742
diff changeset
   309
    Isabelle_Tool("build_status", "present recent build status information from database", args =>
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   310
    {
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   311
      var target_dir = default_target_dir
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   312
      var only_sessions = Set.empty[String]
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   313
      var options = Options.init()
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   314
      var image_size = default_image_size
65750
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   315
      var verbose = false
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   316
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   317
      val getopts = Getopts("""
65743
4847ca570454 clarified name;
wenzelm
parents: 65742
diff changeset
   318
Usage: isabelle build_status [OPTIONS]
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   319
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   320
  Options are:
65737
0729c09be90c tuned messages;
wenzelm
parents: 65736
diff changeset
   321
    -D DIR       target directory (default """ + default_target_dir + """)
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   322
    -S SESSIONS  only given SESSIONS (comma separated)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   323
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
65737
0729c09be90c tuned messages;
wenzelm
parents: 65736
diff changeset
   324
    -s WxH       size of PNG image (default """ + image_size._1 + "x" + image_size._2 + """)
65750
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   325
    -v           verbose
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   326
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   327
  Present performance statistics from build log database, which is specified
65782
4935bac8a850 simplified default;
wenzelm
parents: 65773
diff changeset
   328
  via system options build_log_database_host, build_log_database_user,
4935bac8a850 simplified default;
wenzelm
parents: 65773
diff changeset
   329
  build_log_history etc.
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   330
""",
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   331
        "D:" -> (arg => target_dir = Path.explode(arg)),
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   332
        "S:" -> (arg => only_sessions = space_explode(',', arg).toSet),
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   333
        "o:" -> (arg => options = options + arg),
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   334
        "s:" -> (arg =>
63805
c272680df665 clarified modules;
wenzelm
parents: 63708
diff changeset
   335
          space_explode('x', arg).map(Value.Int.parse(_)) match {
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   336
            case List(w, h) if w > 0 && h > 0 => image_size = (w, h)
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   337
            case _ => error("Error bad PNG image size: " + quote(arg))
65750
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   338
          }),
7f5556f4b584 added option verbose for SQL source;
wenzelm
parents: 65747
diff changeset
   339
        "v" -> (_ => verbose = true))
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   340
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   341
      val more_args = getopts(args)
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   342
      if (more_args.nonEmpty) getopts.usage()
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   343
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   344
      val progress = new Console_Progress
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   345
65785
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
   346
      build_status(options, progress = progress, only_sessions = only_sessions, verbose = verbose,
6107504371fb tuned signature;
wenzelm
parents: 65784
diff changeset
   347
        target_dir = target_dir, image_size = image_size)
65736
2e7230b66a32 performance statistics from build log database;
wenzelm
parents: 65733
diff changeset
   348
64161
2b1128e95dfb explicit indication of Admin tools;
wenzelm
parents: 64106
diff changeset
   349
  }, admin = true)
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   350
}