| author | wenzelm |
| Wed, 02 Jan 2013 19:23:18 +0100 | |
| changeset 50688 | f02864682307 |
| parent 50685 | 293e8ec4dfc8 |
| child 50689 | 0607d557d073 |
| permissions | -rw-r--r-- |
| 50685 | 1 |
/* Title: Pure/ML/ml_statistics.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
ML runtime statistics. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
|
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
10 |
import scala.collection.immutable.{SortedSet, SortedMap}
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
11 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
12 |
|
| 50685 | 13 |
object ML_Statistics |
14 |
{
|
|
15 |
/* read properties from build log */ |
|
16 |
||
17 |
private val line_prefix = "\fML_statistics = " |
|
18 |
||
19 |
private val syntax = Outer_Syntax.empty + "," + "(" + ")" + "[" + "]"
|
|
20 |
||
21 |
private object Parser extends Parse.Parser |
|
22 |
{
|
|
23 |
private def stat: Parser[(String, String)] = |
|
24 |
keyword("(") ~ string ~ keyword(",") ~ string ~ keyword(")") ^^
|
|
25 |
{ case _ ~ x ~ _ ~ y ~ _ => (x, y) }
|
|
26 |
private def stats: Parser[Properties.T] = |
|
27 |
keyword("[") ~> repsep(stat, keyword(",")) <~ keyword("]")
|
|
28 |
||
29 |
def parse_stats(s: String): Properties.T = |
|
30 |
{
|
|
31 |
parse_all(stats, Token.reader(syntax.scan(s))) match {
|
|
32 |
case Success(result, _) => result |
|
33 |
case bad => error(bad.toString) |
|
34 |
} |
|
35 |
} |
|
36 |
} |
|
37 |
||
38 |
def read_log(log: Path): List[Properties.T] = |
|
39 |
for {
|
|
40 |
line <- split_lines(File.read_gzip(log)) |
|
41 |
if line.startsWith(line_prefix) |
|
42 |
stats = line.substring(line_prefix.length) |
|
43 |
} yield Parser.parse_stats(stats) |
|
|
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
44 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
45 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
46 |
/* content interpretation */ |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
47 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
48 |
val Now = new Properties.Double("now")
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
49 |
final case class Entry(time: Double, data: Map[String, Double]) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
50 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
51 |
def apply(stats: List[Properties.T]): ML_Statistics = new ML_Statistics(stats) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
52 |
def apply(log: Path): ML_Statistics = apply(read_log(log)) |
| 50685 | 53 |
} |
|
50688
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
54 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
55 |
final class ML_Statistics private(val stats: List[Properties.T]) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
56 |
{
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
57 |
require(!stats.isEmpty && stats.forall(props => ML_Statistics.Now.unapply(props).isDefined)) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
58 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
59 |
val time_start = ML_Statistics.Now.unapply(stats.head).get |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
60 |
val duration = ML_Statistics.Now.unapply(stats.last).get - time_start |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
61 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
62 |
val names: Set[String] = |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
63 |
SortedSet.empty[String] ++ |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
64 |
(for (props <- stats.iterator; (x, _) <- props.iterator if x != ML_Statistics.Now.name) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
65 |
yield x) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
66 |
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
67 |
val content: List[ML_Statistics.Entry] = |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
68 |
stats.map(props => {
|
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
69 |
val time = ML_Statistics.Now.unapply(props).get - time_start |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
70 |
require(time >= 0.0) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
71 |
val data = |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
72 |
SortedMap.empty[String, Double] ++ |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
73 |
(for ((x, y) <- props.iterator if x != ML_Statistics.Now.name) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
74 |
yield (x, java.lang.Double.parseDouble(y))) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
75 |
ML_Statistics.Entry(time, data) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
76 |
}) |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
77 |
} |
|
f02864682307
some support for ML statistics content interpretation;
wenzelm
parents:
50685
diff
changeset
|
78 |