src/Pure/Admin/build_status.scala
changeset 65799 ed705d6a6a63
parent 65798 d459db0f6135
child 65804 73ed0ebac3b0
     1.1 --- a/src/Pure/Admin/build_status.scala	Wed May 10 17:24:31 2017 +0200
     1.2 +++ b/src/Pure/Admin/build_status.scala	Wed May 10 19:02:06 2017 +0200
     1.3 @@ -9,11 +9,26 @@
     1.4  
     1.5  object Build_Status
     1.6  {
     1.7 +  /* defaults */
     1.8 +
     1.9 +  val default_target_dir = Path.explode("build_status")
    1.10 +  val default_image_size = (800, 600)
    1.11 +  val default_history = 30
    1.12 +
    1.13 +  def default_profiles: List[Profile] =
    1.14 +    Jenkins.build_status_profiles ::: Isabelle_Cronjob.build_status_profiles
    1.15 +
    1.16 +
    1.17    /* data profiles */
    1.18  
    1.19    sealed case class Profile(description: String, history: Int, sql: String)
    1.20    {
    1.21 -    def select(columns: List[SQL.Column], days: Int, only_sessions: Set[String]): SQL.Source =
    1.22 +    def days(options: Options): Int = options.int("build_log_history") max history
    1.23 +
    1.24 +    def stretch(options: Options): Double =
    1.25 +      (days(options) max default_history min (default_history * 5)).toDouble / default_history
    1.26 +
    1.27 +    def select(options: Options, columns: List[SQL.Column], only_sessions: Set[String]): SQL.Source =
    1.28      {
    1.29        val sql_sessions =
    1.30          if (only_sessions.isEmpty) ""
    1.31 @@ -23,7 +38,7 @@
    1.32  
    1.33        Build_Log.Data.universal_table.select(columns, distinct = true,
    1.34          sql = "WHERE " +
    1.35 -          Build_Log.Data.pull_date + " > " + Build_Log.Data.recent_time(days max history) + " AND " +
    1.36 +          Build_Log.Data.pull_date + " > " + Build_Log.Data.recent_time(days(options)) + " AND " +
    1.37            Build_Log.Data.status + " = " + SQL.string(Build_Log.Session_Status.finished.toString) +
    1.38            " AND " + sql_sessions + SQL.enclose(sql) +
    1.39            " ORDER BY " + Build_Log.Data.pull_date + " DESC")
    1.40 @@ -33,12 +48,6 @@
    1.41  
    1.42    /* build status */
    1.43  
    1.44 -  val default_target_dir = Path.explode("build_status")
    1.45 -  val default_image_size = (800, 600)
    1.46 -
    1.47 -  def default_profiles: List[Profile] =
    1.48 -    Jenkins.build_status_profiles ::: Isabelle_Cronjob.build_status_profiles
    1.49 -
    1.50    def build_status(options: Options,
    1.51      progress: Progress = No_Progress,
    1.52      profiles: List[Profile] = default_profiles,
    1.53 @@ -58,7 +67,8 @@
    1.54    /* read data */
    1.55  
    1.56    sealed case class Data(date: Date, entries: List[Data_Entry])
    1.57 -  sealed case class Data_Entry(name: String, hosts: List[String], sessions: List[Session])
    1.58 +  sealed case class Data_Entry(
    1.59 +    name: String, hosts: List[String], stretch: Double, sessions: List[Session])
    1.60    sealed case class Session(name: String, threads: Int, entries: List[Entry])
    1.61    {
    1.62      require(entries.nonEmpty)
    1.63 @@ -85,6 +95,7 @@
    1.64    {
    1.65      val date = Date.now()
    1.66      var data_hosts = Map.empty[String, Set[String]]
    1.67 +    var data_stretch = Map.empty[String, Double]
    1.68      var data_entries = Map.empty[String, Map[String, Session]]
    1.69  
    1.70      def get_hosts(data_name: String): Set[String] =
    1.71 @@ -115,7 +126,7 @@
    1.72  
    1.73          val Threads_Option = """threads\s*=\s*(\d+)""".r
    1.74  
    1.75 -        val sql = profile.select(columns, options.int("build_log_history"), only_sessions)
    1.76 +        val sql = profile.select(options, columns, only_sessions)
    1.77          if (verbose) progress.echo(sql)
    1.78  
    1.79          db.using_statement(sql)(stmt =>
    1.80 @@ -139,6 +150,11 @@
    1.81                  (if (ml_platform.startsWith("x86_64")) ", 64bit" else "") +
    1.82                  (if (threads == 1) "" else ", " + threads + " threads")
    1.83  
    1.84 +            res.get_string(Build_Log.Prop.build_host).foreach(host =>
    1.85 +              data_hosts += (data_name -> (get_hosts(data_name) + host)))
    1.86 +
    1.87 +            data_stretch += (data_name -> profile.stretch(options))
    1.88 +
    1.89              val entry =
    1.90                Entry(
    1.91                  pull_date = res.date(Build_Log.Data.pull_date),
    1.92 @@ -156,9 +172,6 @@
    1.93                      Build_Log.Data.ml_timing_gc),
    1.94                  heap_size = res.long(Build_Log.Data.heap_size))
    1.95  
    1.96 -            res.get_string(Build_Log.Prop.build_host).foreach(host =>
    1.97 -              data_hosts += (data_name -> (get_hosts(data_name) + host)))
    1.98 -
    1.99              val sessions = data_entries.getOrElse(data_name, Map.empty)
   1.100              val entries = sessions.get(session_name).map(_.entries) getOrElse Nil
   1.101              val session = Session(session_name, threads, entry :: entries)
   1.102 @@ -173,7 +186,12 @@
   1.103          (name, sessions) <- data_entries.toList
   1.104          sorted_sessions <-
   1.105            proper_list(sessions.toList.map(_._2).filter(_.check_timing).sortBy(_.order))
   1.106 -      } yield Data_Entry(name, get_hosts(name).toList.sorted, sorted_sessions)).sortBy(_.name)
   1.107 +      }
   1.108 +      yield {
   1.109 +        val hosts = get_hosts(name).toList.sorted
   1.110 +        val stretch = data_stretch(name)
   1.111 +        Data_Entry(name, hosts, stretch, sorted_sessions)
   1.112 +      }).sortBy(_.name)
   1.113  
   1.114      Data(date, sorted_entries)
   1.115    }
   1.116 @@ -205,6 +223,9 @@
   1.117      for (data_entry <- data.entries) {
   1.118        val data_name = data_entry.name
   1.119  
   1.120 +      val image_width = (image_size._1 * data_entry.stretch).toInt
   1.121 +      val image_height = image_size._2
   1.122 +
   1.123        progress.echo("output " + quote(data_name))
   1.124  
   1.125        val dir = target_dir + Path.basic(clean_name(data_name))
   1.126 @@ -238,7 +259,7 @@
   1.127                  val plot_name = session.name + "_" + kind + ".png"
   1.128  
   1.129                  File.write(gnuplot_file, """
   1.130 -set terminal png size """ + image_size._1 + "," + image_size._2 + """
   1.131 +set terminal png size """ + image_width + "," + image_height + """
   1.132  set output """ + quote(File.standard_path(dir + Path.basic(plot_name))) + """
   1.133  set xdata time
   1.134  set timefmt "%s"
   1.135 @@ -319,8 +340,8 @@
   1.136                      HTML.bold(HTML.text("AFP version: ")) :: HTML.text(s)).toList) ::
   1.137                  session_plots.getOrElse(session.name, Nil).map(plot_name =>
   1.138                    HTML.image(plot_name) +
   1.139 -                    HTML.width(image_size._1 / 2) +
   1.140 -                    HTML.height(image_size._2 / 2)))))))
   1.141 +                    HTML.width(image_width / 2) +
   1.142 +                    HTML.height(image_height / 2)))))))
   1.143      }
   1.144    }
   1.145