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