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