|
50685
|
1 |
/* Title: Pure/ML/ml_statistics.ML
|
|
|
2 |
Author: Makarius
|
|
|
3 |
|
|
|
4 |
ML runtime statistics.
|
|
|
5 |
*/
|
|
|
6 |
|
|
|
7 |
package isabelle
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
object ML_Statistics
|
|
|
11 |
{
|
|
|
12 |
/* read properties from build log */
|
|
|
13 |
|
|
|
14 |
private val line_prefix = "\fML_statistics = "
|
|
|
15 |
|
|
|
16 |
private val syntax = Outer_Syntax.empty + "," + "(" + ")" + "[" + "]"
|
|
|
17 |
|
|
|
18 |
private object Parser extends Parse.Parser
|
|
|
19 |
{
|
|
|
20 |
private def stat: Parser[(String, String)] =
|
|
|
21 |
keyword("(") ~ string ~ keyword(",") ~ string ~ keyword(")") ^^
|
|
|
22 |
{ case _ ~ x ~ _ ~ y ~ _ => (x, y) }
|
|
|
23 |
private def stats: Parser[Properties.T] =
|
|
|
24 |
keyword("[") ~> repsep(stat, keyword(",")) <~ keyword("]")
|
|
|
25 |
|
|
|
26 |
def parse_stats(s: String): Properties.T =
|
|
|
27 |
{
|
|
|
28 |
parse_all(stats, Token.reader(syntax.scan(s))) match {
|
|
|
29 |
case Success(result, _) => result
|
|
|
30 |
case bad => error(bad.toString)
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
def read_log(log: Path): List[Properties.T] =
|
|
|
36 |
for {
|
|
|
37 |
line <- split_lines(File.read_gzip(log))
|
|
|
38 |
if line.startsWith(line_prefix)
|
|
|
39 |
stats = line.substring(line_prefix.length)
|
|
|
40 |
} yield Parser.parse_stats(stats)
|
|
|
41 |
}
|