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