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