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 |
{
|
|
16 |
private val Session_Finished =
|
|
17 |
new Regex("""^Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time.*$""")
|
|
18 |
private val Session_Timing =
|
|
19 |
new Regex("""^Timing (\S+) \((\d) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time.*$""")
|
|
20 |
|
|
21 |
private object ML_Option
|
|
22 |
{
|
|
23 |
def unapply(s: String): Option[(String, String)] =
|
|
24 |
s.indexOf('=') match {
|
|
25 |
case -1 => None
|
|
26 |
case i =>
|
|
27 |
val a = s.substring(0, i)
|
|
28 |
Library.try_unquote(s.substring(i + 1)) match {
|
|
29 |
case Some(b) if Build.ml_options.contains(a) => Some((a, b))
|
|
30 |
case _ => None
|
|
31 |
}
|
|
32 |
}
|
|
33 |
}
|
|
34 |
|
|
35 |
def parse(text: String): Build_Stats =
|
|
36 |
{
|
|
37 |
import Properties.Value
|
|
38 |
|
|
39 |
val ml_options = new mutable.ListBuffer[(String, String)]
|
|
40 |
var finished = Map.empty[String, Timing]
|
|
41 |
var timing = Map.empty[String, Timing]
|
|
42 |
var threads = Map.empty[String, Int]
|
|
43 |
|
|
44 |
for (line <- split_lines(text)) {
|
|
45 |
line match {
|
|
46 |
case Session_Finished(name,
|
|
47 |
Value.Int(e1), Value.Int(e2), Value.Int(e3),
|
|
48 |
Value.Int(c1), Value.Int(c2), Value.Int(c3)) =>
|
|
49 |
val elapsed = Time.hours_minutes_seconds(e1, e2, e3)
|
|
50 |
val cpu = Time.hours_minutes_seconds(c1, c2, c3)
|
|
51 |
finished += (name -> Timing(elapsed, cpu, Time.zero))
|
|
52 |
case Session_Timing(name,
|
|
53 |
Value.Int(t), Value.Double(e), Value.Double(c), Value.Double(g)) =>
|
|
54 |
val elapsed = Time.seconds(e)
|
|
55 |
val cpu = Time.seconds(c)
|
|
56 |
val gc = Time.seconds(g)
|
|
57 |
timing += (name -> Timing(elapsed, cpu, gc))
|
|
58 |
threads += (name -> t)
|
|
59 |
case ML_Option(option) => ml_options += option
|
|
60 |
case _ =>
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
Build_Stats(ml_options.toList, finished, timing, threads)
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
sealed case class Build_Stats(
|
|
69 |
ml_options: List[(String, String)],
|
|
70 |
finished: Map[String, Timing],
|
|
71 |
timing: Map[String, Timing],
|
|
72 |
threads: Map[String, Int])
|
|
73 |
{
|
|
74 |
val sessions: Set[String] = finished.keySet ++ timing.keySet
|
|
75 |
|
|
76 |
override def toString: String =
|
|
77 |
sessions.toList.sorted.mkString("Build_Stats(", ", ", ")")
|
|
78 |
}
|