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