author | wenzelm |
Sun, 14 Aug 2016 22:48:23 +0200 | |
changeset 63702 | fed1d4dab990 |
parent 63701 | 3744d2cf4d2f |
child 63703 | ec095a532a2b |
permissions | -rw-r--r-- |
63686 | 1 |
/* Title: Pure/Tools/build_stats.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Statistics from session build output. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import scala.collection.mutable |
|
11 |
import scala.util.matching.Regex |
|
12 |
||
13 |
||
14 |
object Build_Stats |
|
15 |
{ |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
16 |
/* parse build output */ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
17 |
|
63702
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
18 |
private val Session_Finished1 = |
63686 | 19 |
new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""") |
63702
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
20 |
private val Session_Finished2 = |
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
21 |
new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time.*$""") |
63686 | 22 |
private val Session_Timing = |
23 |
new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""") |
|
24 |
||
25 |
private object ML_Option |
|
26 |
{ |
|
27 |
def unapply(s: String): Option[(String, String)] = |
|
28 |
s.indexOf('=') match { |
|
29 |
case -1 => None |
|
30 |
case i => |
|
31 |
val a = s.substring(0, i) |
|
32 |
Library.try_unquote(s.substring(i + 1)) match { |
|
33 |
case Some(b) if Build.ml_options.contains(a) => Some((a, b)) |
|
34 |
case _ => None |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
||
39 |
def parse(text: String): Build_Stats = |
|
40 |
{ |
|
41 |
import Properties.Value |
|
42 |
||
43 |
val ml_options = new mutable.ListBuffer[(String, String)] |
|
44 |
var finished = Map.empty[String, Timing] |
|
45 |
var timing = Map.empty[String, Timing] |
|
46 |
var threads = Map.empty[String, Int] |
|
47 |
||
48 |
for (line <- split_lines(text)) { |
|
49 |
line match { |
|
63702
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
50 |
case Session_Finished1(name, |
63686 | 51 |
Value.Int(e1), Value.Int(e2), Value.Int(e3), |
52 |
Value.Int(c1), Value.Int(c2), Value.Int(c3)) => |
|
63700 | 53 |
val elapsed = Time.hms(e1, e2, e3) |
54 |
val cpu = Time.hms(c1, c2, c3) |
|
63686 | 55 |
finished += (name -> Timing(elapsed, cpu, Time.zero)) |
63702
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
56 |
case Session_Finished2(name, |
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
57 |
Value.Int(e1), Value.Int(e2), Value.Int(e3)) => |
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
58 |
val elapsed = Time.hms(e1, e2, e3) |
fed1d4dab990
cpu time is optional (see Timing.message_resources);
wenzelm
parents:
63701
diff
changeset
|
59 |
finished += (name -> Timing(elapsed, Time.zero, Time.zero)) |
63686 | 60 |
case Session_Timing(name, |
61 |
Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) => |
|
62 |
val elapsed = Time.seconds(e) |
|
63 |
val cpu = Time.seconds(c) |
|
64 |
val gc = Time.seconds(g) |
|
65 |
timing += (name -> Timing(elapsed, cpu, gc)) |
|
66 |
threads += (name -> t) |
|
67 |
case ML_Option(option) => ml_options += option |
|
68 |
case _ => |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
Build_Stats(ml_options.toList, finished, timing, threads) |
|
73 |
} |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
74 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
75 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
76 |
/* presentation */ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
77 |
|
63700 | 78 |
private val default_target_dir = Path.explode("stats") |
79 |
private val default_history_length = 100 |
|
80 |
private val default_size = (800, 600) |
|
81 |
private val default_only_sessions = Set.empty[String] |
|
82 |
private val default_elapsed_threshold = Time.zero |
|
83 |
||
84 |
def present(job: String, |
|
85 |
target_dir: Path = default_target_dir, |
|
86 |
history_length: Int = default_history_length, |
|
87 |
size: (Int, Int) = default_size, |
|
88 |
only_sessions: Set[String] = default_only_sessions, |
|
89 |
elapsed_threshold: Time = default_elapsed_threshold) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
90 |
{ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
91 |
val build_infos = CI_API.build_job_builds(job).sortBy(_.timestamp).reverse.take(history_length) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
92 |
if (build_infos.isEmpty) error("No build infos for job " + quote(job)) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
93 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
94 |
val dir = target_dir + Path.basic(job) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
95 |
Isabelle_System.mkdirs(dir) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
96 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
97 |
val all_build_stats = |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
98 |
Par_List.map((info: CI_API.Build_Info) => |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
99 |
(info.timestamp / 1000, parse(Url.read(info.output))), build_infos) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
100 |
val all_sessions = |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
101 |
(Set.empty[String] /: all_build_stats)( |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
102 |
{ case (s, (_, stats)) => s ++ stats.sessions }) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
103 |
|
63700 | 104 |
def check_threshold(stats: Build_Stats, session: String): Boolean = |
105 |
stats.finished.get(session) match { |
|
106 |
case Some(t) => t.elapsed >= elapsed_threshold |
|
107 |
case None => false |
|
108 |
} |
|
109 |
||
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
110 |
for { |
63700 | 111 |
session <- (if (only_sessions.isEmpty) all_sessions else all_sessions & only_sessions) |
112 |
if all_build_stats.filter({ case (_, stats) => check_threshold(stats, session) }).length >= 3 |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
113 |
} { |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
114 |
Isabelle_System.with_tmp_file(session, "png") { data_file => |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
115 |
Isabelle_System.with_tmp_file(session, "gnuplot") { plot_file => |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
116 |
val data = |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
117 |
for { (t, stats) <- all_build_stats if stats.finished.isDefinedAt(session) } |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
118 |
yield { |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
119 |
val finished = stats.finished(session) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
120 |
t.toString + " " + finished.cpu.minutes + " " + finished.elapsed.minutes |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
121 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
122 |
File.write(data_file, cat_lines(data)) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
123 |
|
63700 | 124 |
val data_file_name = quote(File.standard_path(data_file.getAbsolutePath)) |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
125 |
File.write(plot_file, """ |
63700 | 126 |
set terminal png size """ + size._1 + "," + size._2 + """ |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
127 |
set output """ + quote(File.standard_path(dir + Path.basic(session + ".png"))) + """ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
128 |
set xdata time |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
129 |
set timefmt "%s" |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
130 |
set format x "%d-%b" |
63701 | 131 |
set xlabel """ + quote(session) + """ noenhanced |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
132 |
set key left top |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
133 |
plot [] [0:] """ + |
63700 | 134 |
data_file_name + """ using 1:2 smooth sbezier title "interpolated cpu time",""" + |
135 |
data_file_name + """ using 1:2 smooth csplines title "cpu time", """ + |
|
136 |
data_file_name + """ using 1:3 smooth sbezier title "interpolated elapsed time",""" + |
|
137 |
data_file_name + """ using 1:3 smooth csplines title "elapsed time" |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
138 |
""") |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
139 |
val result = Isabelle_System.bash("\"$ISABELLE_GNUPLOT\" " + File.bash_path(plot_file)) |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
140 |
if (result.rc != 0) { |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
141 |
Output.error_message("Session " + session + ": gnuplot error") |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
142 |
result.print |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
143 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
144 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
145 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
146 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
147 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
148 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
149 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
150 |
/* Isabelle tool wrapper */ |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
151 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
152 |
val isabelle_tool = |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
153 |
Isabelle_Tool("build_stats", "present statistics from session build output", args => |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
154 |
{ |
63700 | 155 |
var target_dir = default_target_dir |
156 |
var only_sessions = default_only_sessions |
|
157 |
var elapsed_threshold = default_elapsed_threshold |
|
158 |
var history_length = default_history_length |
|
159 |
var size = default_size |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
160 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
161 |
val getopts = Getopts(""" |
63700 | 162 |
Usage: isabelle build_stats [OPTIONS] [JOBS ...] |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
163 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
164 |
Options are: |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
165 |
-D DIR target directory (default "stats") |
63700 | 166 |
-S SESSIONS only given SESSIONS (comma separated) |
167 |
-T THRESHOLD only sessions with elapsed time >= THRESHOLD (minutes) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
168 |
-l LENGTH length of history (default 100) |
63700 | 169 |
-s WxH size of PNG image (default 800x600) |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
170 |
|
63700 | 171 |
Present statistics from session build output of the given JOBS, from Jenkins |
172 |
continuous build service specified as URL via ISABELLE_JENKINS_ROOT. |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
173 |
""", |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
174 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
63700 | 175 |
"S:" -> (arg => only_sessions = space_explode(',', arg).toSet), |
176 |
"T:" -> (arg => elapsed_threshold = Time.minutes(Properties.Value.Double.parse(arg))), |
|
177 |
"l:" -> (arg => history_length = Properties.Value.Int.parse(arg)), |
|
178 |
"s:" -> (arg => |
|
179 |
space_explode('x', arg).map(Properties.Value.Int.parse(_)) match { |
|
180 |
case List(w, h) if w > 0 && h > 0 => size = (w, h) |
|
181 |
case _ => error("Error bad PNG image size: " + quote(arg)) |
|
182 |
})) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
183 |
|
63700 | 184 |
val jobs = getopts(args) |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
185 |
val all_jobs = CI_API.build_jobs() |
63700 | 186 |
val bad_jobs = jobs.filterNot(all_jobs.contains(_)).sorted |
187 |
||
188 |
if (jobs.isEmpty) |
|
189 |
error("No build jobs given. Available jobs: " + commas(all_jobs)) |
|
190 |
||
191 |
if (bad_jobs.nonEmpty) |
|
192 |
error("Unknown build jobs: " + commas(bad_jobs) + |
|
193 |
"\nAvailable jobs: " + commas(all_jobs.sorted)) |
|
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
194 |
|
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
195 |
for (job <- jobs) { |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
196 |
Output.writeln((target_dir + Path.basic(job)).implode) |
63700 | 197 |
present(job, target_dir, history_length, size, only_sessions, elapsed_threshold) |
63688
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
198 |
} |
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
wenzelm
parents:
63686
diff
changeset
|
199 |
}) |
63686 | 200 |
} |
201 |
||
202 |
sealed case class Build_Stats( |
|
203 |
ml_options: List[(String, String)], |
|
204 |
finished: Map[String, Timing], |
|
205 |
timing: Map[String, Timing], |
|
206 |
threads: Map[String, Int]) |
|
207 |
{ |
|
208 |
val sessions: Set[String] = finished.keySet ++ timing.keySet |
|
209 |
||
210 |
override def toString: String = |
|
211 |
sessions.toList.sorted.mkString("Build_Stats(", ", ", ")") |
|
212 |
} |