src/Pure/Tools/build_stats.scala
author wenzelm
Sat, 01 Oct 2016 20:58:59 +0200
changeset 63984 6ba87450894d
parent 63926 70973a1b4ec0
child 64054 1fc9ab31720d
permissions -rw-r--r--
tuned messages -- facilitate copy-paste;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/build_stats.scala
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     3
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
     4
Statistics from session build output.
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
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    10
import scala.collection.mutable
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    11
import scala.util.matching.Regex
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    12
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    13
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    14
object Build_Stats
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    15
{
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    16
  /* parse build output */
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    17
63702
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    18
  private val Session_Finished1 =
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    19
    new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
63702
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    20
  private val Session_Finished2 =
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    21
    new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""")
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    22
  private val Session_Timing =
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    23
    new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    24
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    25
  private object ML_Option
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    26
  {
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    27
    def unapply(s: String): Option[(String, String)] =
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    28
      s.indexOf('=') match {
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    29
        case -1 => None
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    30
        case i =>
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    31
          val a = s.substring(0, i)
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    32
          Library.try_unquote(s.substring(i + 1)) match {
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    33
            case Some(b) if Build.ml_options.contains(a) => Some((a, b))
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    34
            case _ => None
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    35
          }
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    36
      }
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    37
  }
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    38
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    39
  def parse(text: String): Build_Stats =
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    40
  {
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    41
    val ml_options = new mutable.ListBuffer[(String, String)]
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    42
    var finished = Map.empty[String, Timing]
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    43
    var timing = Map.empty[String, Timing]
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    44
    var threads = Map.empty[String, Int]
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    45
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    46
    for (line <- split_lines(text)) {
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    47
      line match {
63702
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    48
        case Session_Finished1(name,
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    49
            Value.Int(e1), Value.Int(e2), Value.Int(e3),
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    50
            Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    51
          val elapsed = Time.hms(e1, e2, e3)
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    52
          val cpu = Time.hms(c1, c2, c3)
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    53
          finished += (name -> Timing(elapsed, cpu, Time.zero))
63702
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    54
        case Session_Finished2(name,
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    55
            Value.Int(e1), Value.Int(e2), Value.Int(e3)) =>
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    56
          val elapsed = Time.hms(e1, e2, e3)
fed1d4dab990 cpu time is optional (see Timing.message_resources);
wenzelm
parents: 63701
diff changeset
    57
          finished += (name -> Timing(elapsed, Time.zero, Time.zero))
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    58
        case Session_Timing(name,
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    59
            Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    60
          val elapsed = Time.seconds(e)
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    61
          val cpu = Time.seconds(c)
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    62
          val gc = Time.seconds(g)
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    63
          timing += (name -> Timing(elapsed, cpu, gc))
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    64
          threads += (name -> t)
63926
70973a1b4ec0 tuned -- fewer warnings;
wenzelm
parents: 63805
diff changeset
    65
        case ML_Option(a, b) => ml_options += (a -> b)
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    66
        case _ =>
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    67
      }
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    68
    }
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    69
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    70
    Build_Stats(ml_options.toList, finished, timing, threads)
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
    71
  }
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    72
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    73
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    74
  /* presentation */
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    75
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    76
  private val default_history_length = 100
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    77
  private val default_size = (800, 600)
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    78
  private val default_only_sessions = Set.empty[String]
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    79
  private val default_elapsed_threshold = Time.zero
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
    80
  private val default_ml_timing: Option[Boolean] = None
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    81
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
    82
  def present_job(job: String, dir: Path,
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    83
    history_length: Int = default_history_length,
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    84
    size: (Int, Int) = default_size,
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    85
    only_sessions: Set[String] = default_only_sessions,
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
    86
    elapsed_threshold: Time = default_elapsed_threshold,
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
    87
    ml_timing: Option[Boolean] = default_ml_timing): List[String] =
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    88
  {
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    89
    val build_infos = CI_API.build_job_builds(job).sortBy(_.timestamp).reverse.take(history_length)
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    90
    if (build_infos.isEmpty) error("No build infos for job " + quote(job))
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    91
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    92
    val all_build_stats =
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    93
      Par_List.map((info: CI_API.Build_Info) =>
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    94
        (info.timestamp / 1000, parse(Url.read(info.output))), build_infos)
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    95
    val all_sessions =
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    96
      (Set.empty[String] /: all_build_stats)(
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    97
        { case (s, (_, stats)) => s ++ stats.sessions })
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
    98
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
    99
    def check_threshold(stats: Build_Stats, session: String): Boolean =
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   100
      stats.finished.get(session) match {
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   101
        case Some(t) => t.elapsed >= elapsed_threshold
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   102
        case None => false
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   103
      }
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   104
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   105
    val sessions =
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   106
      for {
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   107
        session <- (if (only_sessions.isEmpty) all_sessions else all_sessions & only_sessions)
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   108
        if all_build_stats.filter({ case (_, stats) => check_threshold(stats, session) }).length >= 3
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   109
      } yield session
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   110
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   111
    Isabelle_System.mkdirs(dir)
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   112
    for (session <- sessions) {
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   113
      Isabelle_System.with_tmp_file(session, "png") { data_file =>
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   114
        Isabelle_System.with_tmp_file(session, "gnuplot") { plot_file =>
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   115
          val data =
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   116
            for { (t, stats) <- all_build_stats if stats.finished.isDefinedAt(session) }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   117
            yield {
63708
77323d963ca4 more robust;
wenzelm
parents: 63707
diff changeset
   118
              val finished = stats.finished.getOrElse(session, Timing.zero)
77323d963ca4 more robust;
wenzelm
parents: 63707
diff changeset
   119
              val timing = stats.timing.getOrElse(session, Timing.zero)
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   120
              List(t.toString, finished.elapsed.minutes, finished.cpu.minutes,
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   121
                timing.elapsed.minutes, timing.cpu.minutes, timing.gc.minutes).mkString(" ")
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   122
            }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   123
          File.write(data_file, cat_lines(data))
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   124
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   125
          val plots1 =
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   126
            List(
63707
b7aab1a6cf0d clarified presentation order, according to typical amounts;
wenzelm
parents: 63706
diff changeset
   127
              """ using 1:3 smooth sbezier title "cpu time (smooth)" """,
b7aab1a6cf0d clarified presentation order, according to typical amounts;
wenzelm
parents: 63706
diff changeset
   128
              """ using 1:3 smooth csplines title "cpu time" """,
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   129
              """ using 1:2 smooth sbezier title "elapsed time (smooth)" """,
63707
b7aab1a6cf0d clarified presentation order, according to typical amounts;
wenzelm
parents: 63706
diff changeset
   130
              """ using 1:2 smooth csplines title "elapsed time" """)
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   131
          val plots2 =
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   132
            List(
63707
b7aab1a6cf0d clarified presentation order, according to typical amounts;
wenzelm
parents: 63706
diff changeset
   133
              """ using 1:5 smooth sbezier title "ML cpu time (smooth)" """,
b7aab1a6cf0d clarified presentation order, according to typical amounts;
wenzelm
parents: 63706
diff changeset
   134
              """ using 1:5 smooth csplines title "ML cpu time" """,
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   135
              """ using 1:4 smooth sbezier title "ML elapsed time (smooth)" """,
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   136
              """ using 1:4 smooth csplines title "ML elapsed time" """,
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   137
              """ using 1:6 smooth sbezier title "ML gc time (smooth)" """,
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   138
              """ using 1:6 smooth csplines title "ML gc time" """)
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   139
          val plots =
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   140
            ml_timing match {
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   141
              case None => plots1
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   142
              case Some(false) => plots1 ::: plots2
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   143
              case Some(true) => plots2
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   144
            }
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   145
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   146
          val data_file_name = File.standard_path(data_file.getAbsolutePath)
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   147
          File.write(plot_file, """
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   148
set terminal png size """ + size._1 + "," + size._2 + """
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   149
set output """ + quote(File.standard_path(dir + Path.basic(session + ".png"))) + """
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   150
set xdata time
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   151
set timefmt "%s"
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   152
set format x "%d-%b"
63701
3744d2cf4d2f proper display of "_";
wenzelm
parents: 63700
diff changeset
   153
set xlabel """ + quote(session) + """ noenhanced
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   154
set key left top
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   155
plot [] [0:] """ + plots.map(s => quote(data_file_name) + " " + s).mkString(", ") + "\n")
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   156
          val result = Isabelle_System.bash("\"$ISABELLE_GNUPLOT\" " + File.bash_path(plot_file))
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   157
          if (result.rc != 0) {
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   158
            Output.error_message("Session " + session + ": gnuplot error")
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   159
            result.print
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   160
          }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   161
        }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   162
      }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   163
    }
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   164
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   165
    sessions.toList.sorted
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   166
  }
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   167
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   168
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   169
  /* Isabelle tool wrapper */
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   170
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   171
  private val html_header = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   172
<html>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   173
<head><title>Performance statistics from session build output</title></head>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   174
<body>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   175
"""
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   176
  private val html_footer = """
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   177
</body>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   178
</html>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   179
"""
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   180
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   181
  val isabelle_tool =
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   182
    Isabelle_Tool("build_stats", "present statistics from session build output", args =>
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   183
    {
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   184
      var target_dir = Path.explode("stats")
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   185
      var ml_timing = default_ml_timing
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   186
      var only_sessions = default_only_sessions
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   187
      var elapsed_threshold = default_elapsed_threshold
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   188
      var history_length = default_history_length
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   189
      var size = default_size
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   190
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   191
      val getopts = Getopts("""
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   192
Usage: isabelle build_stats [OPTIONS] [JOBS ...]
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   193
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   194
  Options are:
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   195
    -D DIR       target directory (default "stats")
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   196
    -M           only ML timing
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   197
    -S SESSIONS  only given SESSIONS (comma separated)
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   198
    -T THRESHOLD only sessions with elapsed time >= THRESHOLD (minutes)
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   199
    -l LENGTH    length of history (default 100)
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   200
    -m           include ML timing
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   201
    -s WxH       size of PNG image (default 800x600)
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   202
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   203
  Present statistics from session build output of the given JOBS, from Jenkins
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   204
  continuous build service specified as URL via ISABELLE_JENKINS_ROOT.
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   205
""",
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   206
        "D:" -> (arg => target_dir = Path.explode(arg)),
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   207
        "M" -> (_ => ml_timing = Some(true)),
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   208
        "S:" -> (arg => only_sessions = space_explode(',', arg).toSet),
63805
c272680df665 clarified modules;
wenzelm
parents: 63708
diff changeset
   209
        "T:" -> (arg => elapsed_threshold = Time.minutes(Value.Double.parse(arg))),
c272680df665 clarified modules;
wenzelm
parents: 63708
diff changeset
   210
        "l:" -> (arg => history_length = Value.Int.parse(arg)),
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   211
        "m" -> (_ => ml_timing = Some(false)),
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   212
        "s:" -> (arg =>
63805
c272680df665 clarified modules;
wenzelm
parents: 63708
diff changeset
   213
          space_explode('x', arg).map(Value.Int.parse(_)) match {
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   214
            case List(w, h) if w > 0 && h > 0 => size = (w, h)
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   215
            case _ => error("Error bad PNG image size: " + quote(arg))
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   216
          }))
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   217
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   218
      val jobs = getopts(args)
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   219
      val all_jobs = CI_API.build_jobs()
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   220
      val bad_jobs = jobs.filterNot(all_jobs.contains(_)).sorted
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   221
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   222
      if (jobs.isEmpty)
63984
6ba87450894d tuned messages -- facilitate copy-paste;
wenzelm
parents: 63926
diff changeset
   223
        error("No build jobs given. Available jobs: " + all_jobs.sorted.mkString(" "))
63700
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   224
2a95d904672e clarified options and arguments;
wenzelm
parents: 63688
diff changeset
   225
      if (bad_jobs.nonEmpty)
63984
6ba87450894d tuned messages -- facilitate copy-paste;
wenzelm
parents: 63926
diff changeset
   226
        error("Unknown build jobs: " + bad_jobs.mkString(" ") +
6ba87450894d tuned messages -- facilitate copy-paste;
wenzelm
parents: 63926
diff changeset
   227
          "\nAvailable jobs: " + all_jobs.sorted.mkString(" "))
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   228
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   229
      for (job <- jobs) {
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   230
        val dir = target_dir + Path.basic(job)
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   231
        Output.writeln(dir.implode)
63706
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   232
        val sessions =
76c2f833abf4 present ML timing as well;
wenzelm
parents: 63703
diff changeset
   233
          present_job(job, dir, history_length, size, only_sessions, elapsed_threshold, ml_timing)
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   234
        File.write(dir + Path.basic("index.html"),
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   235
          html_header + "\n<h1>" + HTML.output(job) + "</h1>\n" +
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   236
          cat_lines(
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   237
            sessions.map(session =>
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   238
              """<br/><img src=""" + quote(HTML.output(session + ".png")) + """><br/>""")) +
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   239
          "\n" + html_footer)
63688
cc57255bf6ae gnuplot presentation similar to former isatest-statistics;
wenzelm
parents: 63686
diff changeset
   240
      }
63703
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   241
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   242
      File.write(target_dir + Path.basic("index.html"),
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   243
        html_header + "\n<ul>\n" +
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   244
        cat_lines(
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   245
          jobs.map(job => """<li> <a href=""" + quote(HTML.output(job + "/index.html")) + """>""" +
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   246
            HTML.output(job) + """</a> </li>""")) +
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   247
        "\n</ul>\n" + html_footer)
ec095a532a2b provide index.html;
wenzelm
parents: 63702
diff changeset
   248
  })
63686
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   249
}
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   250
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   251
sealed case class Build_Stats(
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   252
  ml_options: List[(String, String)],
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   253
  finished: Map[String, Timing],
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   254
  timing: Map[String, Timing],
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   255
  threads: Map[String, Int])
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   256
{
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   257
  val sessions: Set[String] = finished.keySet ++ timing.keySet
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   258
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   259
  override def toString: String =
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   260
    sessions.toList.sorted.mkString("Build_Stats(", ", ", ")")
66f217416da7 statistics from session build output;
wenzelm
parents:
diff changeset
   261
}