| author | wenzelm |
| Fri, 07 Oct 2016 11:10:17 +0200 | |
| changeset 64079 | ff26032b7f2a |
| parent 64062 | a7352cbde7d7 |
| child 64085 | 1c451e5c145f |
| permissions | -rw-r--r-- |
| 63686 | 1 |
/* Title: Pure/Tools/build_stats.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Statistics from session build output. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Build_Stats |
|
11 |
{
|
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
12 |
/* presentation */ |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
13 |
|
| 63700 | 14 |
private val default_history_length = 100 |
15 |
private val default_size = (800, 600) |
|
16 |
private val default_only_sessions = Set.empty[String] |
|
17 |
private val default_elapsed_threshold = Time.zero |
|
| 63706 | 18 |
private val default_ml_timing: Option[Boolean] = None |
| 63700 | 19 |
|
| 63703 | 20 |
def present_job(job: String, dir: Path, |
| 63700 | 21 |
history_length: Int = default_history_length, |
22 |
size: (Int, Int) = default_size, |
|
23 |
only_sessions: Set[String] = default_only_sessions, |
|
| 63706 | 24 |
elapsed_threshold: Time = default_elapsed_threshold, |
25 |
ml_timing: Option[Boolean] = default_ml_timing): List[String] = |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
26 |
{
|
| 64054 | 27 |
val job_infos = CI_API.build_job_builds(job).sortBy(_.timestamp).reverse.take(history_length) |
28 |
if (job_infos.isEmpty) error("No build infos for job " + quote(job))
|
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
29 |
|
| 64054 | 30 |
val all_infos = |
31 |
Par_List.map((job_info: CI_API.Job_Info) => |
|
| 64062 | 32 |
(job_info.timestamp / 1000, job_info.read_output.parse_info), job_infos) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
33 |
val all_sessions = |
| 64054 | 34 |
(Set.empty[String] /: all_infos)( |
35 |
{ case (s, (_, info)) => s ++ info.sessions })
|
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
36 |
|
| 64054 | 37 |
def check_threshold(info: Build_Log.Info, session: String): Boolean = |
38 |
info.finished.get(session) match {
|
|
| 63700 | 39 |
case Some(t) => t.elapsed >= elapsed_threshold |
40 |
case None => false |
|
41 |
} |
|
42 |
||
| 63703 | 43 |
val sessions = |
44 |
for {
|
|
45 |
session <- (if (only_sessions.isEmpty) all_sessions else all_sessions & only_sessions) |
|
| 64054 | 46 |
if all_infos.filter({ case (_, info) => check_threshold(info, session) }).length >= 3
|
| 63703 | 47 |
} yield session |
48 |
||
49 |
Isabelle_System.mkdirs(dir) |
|
50 |
for (session <- sessions) {
|
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
51 |
Isabelle_System.with_tmp_file(session, "png") { data_file =>
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
52 |
Isabelle_System.with_tmp_file(session, "gnuplot") { plot_file =>
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
53 |
val data = |
| 64054 | 54 |
for { (t, info) <- all_infos if info.finished.isDefinedAt(session) }
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
55 |
yield {
|
| 64054 | 56 |
val finished = info.finished.getOrElse(session, Timing.zero) |
57 |
val timing = info.timing.getOrElse(session, Timing.zero) |
|
| 63706 | 58 |
List(t.toString, finished.elapsed.minutes, finished.cpu.minutes, |
59 |
timing.elapsed.minutes, timing.cpu.minutes, timing.gc.minutes).mkString(" ")
|
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
60 |
} |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
61 |
File.write(data_file, cat_lines(data)) |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
62 |
|
| 63706 | 63 |
val plots1 = |
64 |
List( |
|
|
63707
b7aab1a6cf0d
clarified presentation order, according to typical amounts;
wenzelm
parents:
63706
diff
changeset
|
65 |
""" using 1:3 smooth sbezier title "cpu time (smooth)" """, |
|
b7aab1a6cf0d
clarified presentation order, according to typical amounts;
wenzelm
parents:
63706
diff
changeset
|
66 |
""" using 1:3 smooth csplines title "cpu time" """, |
| 63706 | 67 |
""" using 1:2 smooth sbezier title "elapsed time (smooth)" """, |
|
63707
b7aab1a6cf0d
clarified presentation order, according to typical amounts;
wenzelm
parents:
63706
diff
changeset
|
68 |
""" using 1:2 smooth csplines title "elapsed time" """) |
| 63706 | 69 |
val plots2 = |
70 |
List( |
|
|
63707
b7aab1a6cf0d
clarified presentation order, according to typical amounts;
wenzelm
parents:
63706
diff
changeset
|
71 |
""" using 1:5 smooth sbezier title "ML cpu time (smooth)" """, |
|
b7aab1a6cf0d
clarified presentation order, according to typical amounts;
wenzelm
parents:
63706
diff
changeset
|
72 |
""" using 1:5 smooth csplines title "ML cpu time" """, |
| 63706 | 73 |
""" using 1:4 smooth sbezier title "ML elapsed time (smooth)" """, |
74 |
""" using 1:4 smooth csplines title "ML elapsed time" """, |
|
75 |
""" using 1:6 smooth sbezier title "ML gc time (smooth)" """, |
|
76 |
""" using 1:6 smooth csplines title "ML gc time" """) |
|
77 |
val plots = |
|
78 |
ml_timing match {
|
|
79 |
case None => plots1 |
|
80 |
case Some(false) => plots1 ::: plots2 |
|
81 |
case Some(true) => plots2 |
|
82 |
} |
|
83 |
||
84 |
val data_file_name = File.standard_path(data_file.getAbsolutePath) |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
85 |
File.write(plot_file, """ |
| 63700 | 86 |
set terminal png size """ + size._1 + "," + size._2 + """ |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
87 |
set output """ + quote(File.standard_path(dir + Path.basic(session + ".png"))) + """ |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
88 |
set xdata time |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
89 |
set timefmt "%s" |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
90 |
set format x "%d-%b" |
| 63701 | 91 |
set xlabel """ + quote(session) + """ noenhanced |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
92 |
set key left top |
| 63706 | 93 |
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
|
94 |
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
|
95 |
if (result.rc != 0) {
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
96 |
Output.error_message("Session " + session + ": gnuplot error")
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
97 |
result.print |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
98 |
} |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
99 |
} |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
100 |
} |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
101 |
} |
| 63703 | 102 |
|
103 |
sessions.toList.sorted |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
104 |
} |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
105 |
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
106 |
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
107 |
/* Isabelle tool wrapper */ |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
108 |
|
| 63703 | 109 |
private val html_header = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
110 |
<html> |
|
111 |
<head><title>Performance statistics from session build output</title></head> |
|
112 |
<body> |
|
113 |
""" |
|
114 |
private val html_footer = """ |
|
115 |
</body> |
|
116 |
</html> |
|
117 |
""" |
|
118 |
||
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
119 |
val isabelle_tool = |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
120 |
Isabelle_Tool("build_stats", "present statistics from session build output", args =>
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
121 |
{
|
| 63703 | 122 |
var target_dir = Path.explode("stats")
|
| 63706 | 123 |
var ml_timing = default_ml_timing |
| 63700 | 124 |
var only_sessions = default_only_sessions |
125 |
var elapsed_threshold = default_elapsed_threshold |
|
126 |
var history_length = default_history_length |
|
127 |
var size = default_size |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
128 |
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
129 |
val getopts = Getopts("""
|
| 63700 | 130 |
Usage: isabelle build_stats [OPTIONS] [JOBS ...] |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
131 |
|
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
132 |
Options are: |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
133 |
-D DIR target directory (default "stats") |
| 63706 | 134 |
-M only ML timing |
| 63700 | 135 |
-S SESSIONS only given SESSIONS (comma separated) |
136 |
-T THRESHOLD only sessions with elapsed time >= THRESHOLD (minutes) |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
137 |
-l LENGTH length of history (default 100) |
| 63706 | 138 |
-m include ML timing |
| 63700 | 139 |
-s WxH size of PNG image (default 800x600) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
140 |
|
| 63700 | 141 |
Present statistics from session build output of the given JOBS, from Jenkins |
142 |
continuous build service specified as URL via ISABELLE_JENKINS_ROOT. |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
143 |
""", |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
144 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
| 63706 | 145 |
"M" -> (_ => ml_timing = Some(true)), |
| 63700 | 146 |
"S:" -> (arg => only_sessions = space_explode(',', arg).toSet),
|
| 63805 | 147 |
"T:" -> (arg => elapsed_threshold = Time.minutes(Value.Double.parse(arg))), |
148 |
"l:" -> (arg => history_length = Value.Int.parse(arg)), |
|
| 63706 | 149 |
"m" -> (_ => ml_timing = Some(false)), |
| 63700 | 150 |
"s:" -> (arg => |
| 63805 | 151 |
space_explode('x', arg).map(Value.Int.parse(_)) match {
|
| 63700 | 152 |
case List(w, h) if w > 0 && h > 0 => size = (w, h) |
153 |
case _ => error("Error bad PNG image size: " + quote(arg))
|
|
154 |
})) |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
155 |
|
| 63700 | 156 |
val jobs = getopts(args) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
157 |
val all_jobs = CI_API.build_jobs() |
| 63700 | 158 |
val bad_jobs = jobs.filterNot(all_jobs.contains(_)).sorted |
159 |
||
160 |
if (jobs.isEmpty) |
|
| 63984 | 161 |
error("No build jobs given. Available jobs: " + all_jobs.sorted.mkString(" "))
|
| 63700 | 162 |
|
163 |
if (bad_jobs.nonEmpty) |
|
| 63984 | 164 |
error("Unknown build jobs: " + bad_jobs.mkString(" ") +
|
165 |
"\nAvailable jobs: " + all_jobs.sorted.mkString(" "))
|
|
|
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 |
for (job <- jobs) {
|
| 63703 | 168 |
val dir = target_dir + Path.basic(job) |
169 |
Output.writeln(dir.implode) |
|
| 63706 | 170 |
val sessions = |
171 |
present_job(job, dir, history_length, size, only_sessions, elapsed_threshold, ml_timing) |
|
| 63703 | 172 |
File.write(dir + Path.basic("index.html"),
|
173 |
html_header + "\n<h1>" + HTML.output(job) + "</h1>\n" + |
|
174 |
cat_lines( |
|
175 |
sessions.map(session => |
|
176 |
"""<br/><img src=""" + quote(HTML.output(session + ".png")) + """><br/>""")) + |
|
177 |
"\n" + html_footer) |
|
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
178 |
} |
| 63703 | 179 |
|
180 |
File.write(target_dir + Path.basic("index.html"),
|
|
181 |
html_header + "\n<ul>\n" + |
|
182 |
cat_lines( |
|
183 |
jobs.map(job => """<li> <a href=""" + quote(HTML.output(job + "/index.html")) + """>""" + |
|
184 |
HTML.output(job) + """</a> </li>""")) + |
|
185 |
"\n</ul>\n" + html_footer) |
|
186 |
}) |
|
| 63686 | 187 |
} |