author | wenzelm |
Sat, 06 May 2017 20:51:33 +0200 | |
changeset 65747 | 5a3052b2095f |
parent 65745 | a124fbf8b2b9 |
child 65750 | 7f5556f4b584 |
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 |
14 |
private val default_image_size = (800, 600) |
|
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 |
sealed case class Entry(date: Date, timing: Timing, ml_timing: Timing) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
42 |
{ |
65736 | 43 |
def check(elapsed_threshold: Time): Boolean = |
44 |
!timing.is_zero && timing.elapsed >= elapsed_threshold |
|
45 |
} |
|
46 |
||
47 |
type Data = Map[String, Map[String, List[Entry]]] |
|
48 |
||
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
49 |
|
65736 | 50 |
/* read data */ |
51 |
||
52 |
def read_data(options: Options, |
|
53 |
profiles: List[Profile] = standard_profiles, |
|
54 |
progress: Progress = No_Progress, |
|
55 |
history_length: Int = default_history_length, |
|
56 |
only_sessions: Set[String] = Set.empty, |
|
57 |
elapsed_threshold: Time = Time.zero): Data = |
|
58 |
{ |
|
59 |
var data: Data = Map.empty |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
60 |
|
65736 | 61 |
val store = Build_Log.store(options) |
62 |
using(store.open_database())(db => |
|
64089 | 63 |
{ |
65736 | 64 |
for (profile <- profiles) { |
65742 | 65 |
progress.echo("input " + quote(profile.name)) |
65736 | 66 |
val columns = |
67 |
List( |
|
68 |
Build_Log.Data.pull_date, |
|
69 |
Build_Log.Settings.ML_PLATFORM, |
|
70 |
Build_Log.Data.session_name, |
|
71 |
Build_Log.Data.threads, |
|
72 |
Build_Log.Data.timing_elapsed, |
|
73 |
Build_Log.Data.timing_cpu, |
|
74 |
Build_Log.Data.timing_gc, |
|
75 |
Build_Log.Data.ml_timing_elapsed, |
|
76 |
Build_Log.Data.ml_timing_cpu, |
|
77 |
Build_Log.Data.ml_timing_gc) |
|
63700 | 78 |
|
65736 | 79 |
db.using_statement(profile.select(columns, history_length, only_sessions))(stmt => |
80 |
{ |
|
65740 | 81 |
val res = stmt.execute_query() |
82 |
while (res.next()) { |
|
83 |
val ml_platform = res.string(Build_Log.Settings.ML_PLATFORM) |
|
84 |
val threads = res.get_int(Build_Log.Data.threads) |
|
65736 | 85 |
val name = |
86 |
profile.name + |
|
87 |
"_m" + (if (ml_platform.startsWith("x86_64")) "64" else "32") + |
|
88 |
"_M" + threads.getOrElse(1) |
|
63703 | 89 |
|
65740 | 90 |
val session = res.string(Build_Log.Data.session_name) |
65736 | 91 |
val entry = |
65740 | 92 |
Entry(res.date(Build_Log.Data.pull_date), |
65741 | 93 |
res.timing( |
94 |
Build_Log.Data.timing_elapsed, |
|
95 |
Build_Log.Data.timing_cpu, |
|
96 |
Build_Log.Data.timing_gc), |
|
97 |
res.timing( |
|
98 |
Build_Log.Data.ml_timing_elapsed, |
|
99 |
Build_Log.Data.ml_timing_cpu, |
|
100 |
Build_Log.Data.ml_timing_gc)) |
|
65736 | 101 |
|
102 |
val session_entries = data.getOrElse(name, Map.empty) |
|
103 |
val entries = session_entries.getOrElse(session, Nil) |
|
104 |
data += (name -> (session_entries + (session -> (entry :: entries)))) |
|
105 |
} |
|
106 |
}) |
|
107 |
} |
|
108 |
}) |
|
109 |
||
110 |
for { |
|
111 |
(name, session_entries) <- data |
|
112 |
session_entries1 <- |
|
113 |
{ |
|
114 |
val session_entries1 = |
|
115 |
for { |
|
116 |
(session, entries) <- session_entries |
|
117 |
if entries.filter(_.check(elapsed_threshold)).length >= 3 |
|
118 |
} yield (session, entries) |
|
119 |
if (session_entries1.isEmpty) None |
|
120 |
else Some(session_entries1) |
|
121 |
} |
|
122 |
} yield (name, session_entries1) |
|
123 |
} |
|
124 |
||
125 |
||
126 |
/* present data */ |
|
127 |
||
128 |
private val html_header = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
|
129 |
<html> |
|
65743 | 130 |
<head><title>Build status</title></head> |
65736 | 131 |
<body> |
132 |
""" |
|
133 |
private val html_footer = """ |
|
134 |
</body> |
|
135 |
</html> |
|
136 |
""" |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
137 |
|
65736 | 138 |
def present_data(data: Data, |
139 |
progress: Progress = No_Progress, |
|
140 |
target_dir: Path = default_target_dir, |
|
141 |
image_size: (Int, Int) = default_image_size, |
|
142 |
ml_timing: Option[Boolean] = None) |
|
143 |
{ |
|
144 |
val data_entries = data.toList.sortBy(_._1) |
|
145 |
for ((name, session_entries) <- data_entries) { |
|
146 |
val dir = target_dir + Path.explode(name) |
|
65742 | 147 |
progress.echo("output " + dir) |
65736 | 148 |
Isabelle_System.mkdirs(dir) |
149 |
||
150 |
for ((session, entries) <- session_entries) { |
|
151 |
Isabelle_System.with_tmp_file(session, "data") { data_file => |
|
152 |
Isabelle_System.with_tmp_file(session, "gnuplot") { gnuplot_file => |
|
63706 | 153 |
|
65736 | 154 |
File.write(data_file, |
155 |
cat_lines( |
|
156 |
entries.map(entry => |
|
157 |
List(entry.date.unix_epoch.toString, |
|
158 |
entry.timing.elapsed.minutes, |
|
159 |
entry.timing.cpu.minutes, |
|
160 |
entry.ml_timing.elapsed.minutes, |
|
161 |
entry.ml_timing.cpu.minutes, |
|
162 |
entry.ml_timing.gc.minutes).mkString(" ")))) |
|
163 |
||
164 |
val plots1 = |
|
165 |
List( |
|
166 |
""" using 1:3 smooth sbezier title "cpu time (smooth)" """, |
|
167 |
""" using 1:3 smooth csplines title "cpu time" """, |
|
168 |
""" using 1:2 smooth sbezier title "elapsed time (smooth)" """, |
|
169 |
""" using 1:2 smooth csplines title "elapsed time" """) |
|
170 |
val plots2 = |
|
171 |
List( |
|
172 |
""" using 1:5 smooth sbezier title "ML cpu time (smooth)" """, |
|
173 |
""" using 1:5 smooth csplines title "ML cpu time" """, |
|
174 |
""" using 1:4 smooth sbezier title "ML elapsed time (smooth)" """, |
|
175 |
""" using 1:4 smooth csplines title "ML elapsed time" """, |
|
176 |
""" using 1:6 smooth sbezier title "ML gc time (smooth)" """, |
|
177 |
""" using 1:6 smooth csplines title "ML gc time" """) |
|
178 |
val plots = |
|
179 |
ml_timing match { |
|
180 |
case None => plots1 |
|
181 |
case Some(false) => plots1 ::: plots2 |
|
182 |
case Some(true) => plots2 |
|
183 |
} |
|
184 |
||
185 |
File.write(gnuplot_file, """ |
|
186 |
set terminal png size """ + image_size._1 + "," + image_size._2 + """ |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
187 |
set output """ + quote(File.standard_path(dir + Path.basic(session + ".png"))) + """ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
188 |
set xdata time |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
189 |
set timefmt "%s" |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
190 |
set format x "%d-%b" |
63701 | 191 |
set xlabel """ + quote(session) + """ noenhanced |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
192 |
set key left top |
64220 | 193 |
plot [] [0:] """ + plots.map(s => quote(data_file.implode) + " " + s).mkString(", ") + "\n") |
65736 | 194 |
|
195 |
val result = |
|
196 |
Isabelle_System.bash("\"$ISABELLE_GNUPLOT\" " + File.bash_path(gnuplot_file)) |
|
197 |
if (result.rc != 0) |
|
65742 | 198 |
result.error("Gnuplot failed for " + name + "/" + session).check |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
199 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
200 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
201 |
} |
65736 | 202 |
|
203 |
File.write(dir + Path.basic("index.html"), |
|
204 |
html_header + "\n<h1>" + HTML.output(name) + "</h1>\n" + |
|
205 |
cat_lines( |
|
206 |
session_entries.toList.map(_._1).sorted.map(session => |
|
207 |
"""<br/><img src=""" + quote(HTML.output(session + ".png")) + """><br/>""")) + |
|
208 |
"\n" + html_footer) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
209 |
} |
63703 | 210 |
|
65736 | 211 |
File.write(target_dir + Path.basic("index.html"), |
212 |
html_header + "\n<ul>\n" + |
|
213 |
cat_lines( |
|
214 |
data_entries.map(_._1).map(name => |
|
215 |
"""<li> <a href=""" + quote(HTML.output(name + "/index.html")) + """>""" + |
|
216 |
HTML.output(name) + """</a> </li>""")) + |
|
217 |
"\n</ul>\n" + html_footer) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
218 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
219 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
220 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
221 |
/* Isabelle tool wrapper */ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
222 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
223 |
val isabelle_tool = |
65743 | 224 |
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
|
225 |
{ |
65736 | 226 |
var target_dir = default_target_dir |
227 |
var ml_timing: Option[Boolean] = None |
|
228 |
var only_sessions = Set.empty[String] |
|
229 |
var elapsed_threshold = Time.zero |
|
63700 | 230 |
var history_length = default_history_length |
65736 | 231 |
var options = Options.init() |
232 |
var image_size = default_image_size |
|
63688
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 |
val getopts = Getopts(""" |
65743 | 235 |
Usage: isabelle build_status [OPTIONS] |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
236 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
237 |
Options are: |
65737 | 238 |
-D DIR target directory (default """ + default_target_dir + """) |
63706 | 239 |
-M only ML timing |
63700 | 240 |
-S SESSIONS only given SESSIONS (comma separated) |
241 |
-T THRESHOLD only sessions with elapsed time >= THRESHOLD (minutes) |
|
65737 | 242 |
-l LENGTH length of history (default """ + default_history_length + """) |
63706 | 243 |
-m include ML timing |
65736 | 244 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
65737 | 245 |
-s WxH size of PNG image (default """ + image_size._1 + "x" + image_size._2 + """) |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
246 |
|
65736 | 247 |
Present performance statistics from build log database, which is specified |
248 |
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
|
249 |
""", |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
250 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
63706 | 251 |
"M" -> (_ => ml_timing = Some(true)), |
63700 | 252 |
"S:" -> (arg => only_sessions = space_explode(',', arg).toSet), |
63805 | 253 |
"T:" -> (arg => elapsed_threshold = Time.minutes(Value.Double.parse(arg))), |
254 |
"l:" -> (arg => history_length = Value.Int.parse(arg)), |
|
63706 | 255 |
"m" -> (_ => ml_timing = Some(false)), |
65736 | 256 |
"o:" -> (arg => options = options + arg), |
63700 | 257 |
"s:" -> (arg => |
63805 | 258 |
space_explode('x', arg).map(Value.Int.parse(_)) match { |
65736 | 259 |
case List(w, h) if w > 0 && h > 0 => image_size = (w, h) |
63700 | 260 |
case _ => error("Error bad PNG image size: " + quote(arg)) |
261 |
})) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
262 |
|
65736 | 263 |
val more_args = getopts(args) |
264 |
if (more_args.nonEmpty) getopts.usage() |
|
63700 | 265 |
|
65736 | 266 |
val progress = new Console_Progress |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
267 |
|
65736 | 268 |
val data = |
65745 | 269 |
read_data(options, progress = progress, history_length = history_length, |
270 |
only_sessions = only_sessions, elapsed_threshold = elapsed_threshold) |
|
63703 | 271 |
|
65736 | 272 |
present_data(data, progress = progress, target_dir = target_dir, |
273 |
image_size = image_size, ml_timing = ml_timing) |
|
274 |
||
64161 | 275 |
}, admin = true) |
63686 | 276 |
} |