src/Pure/ML/ml_statistics.scala
author wenzelm
Wed, 02 Jan 2013 16:48:22 +0100
changeset 50685 293e8ec4dfc8
child 50688 f02864682307
permissions -rw-r--r--
ML runtime statistics: read properties from build log;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50685
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/ML/ml_statistics.ML
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     3
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     4
ML runtime statistics.
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     5
*/
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     6
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     7
package isabelle
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     8
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
     9
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    10
object ML_Statistics
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    11
{
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    12
  /* read properties from build log */
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    13
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    14
  private val line_prefix = "\fML_statistics = "
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    15
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    16
  private val syntax = Outer_Syntax.empty + "," + "(" + ")" + "[" + "]"
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    17
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    18
  private object Parser extends Parse.Parser
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    19
  {
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    20
    private def stat: Parser[(String, String)] =
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    21
      keyword("(") ~ string ~ keyword(",") ~ string ~ keyword(")") ^^
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    22
      { case _ ~ x ~ _ ~ y ~ _ => (x, y) }
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    23
    private def stats: Parser[Properties.T] =
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    24
      keyword("[") ~> repsep(stat, keyword(",")) <~ keyword("]")
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    25
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    26
    def parse_stats(s: String): Properties.T =
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    27
    {
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    28
      parse_all(stats, Token.reader(syntax.scan(s))) match {
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    29
        case Success(result, _) => result
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    30
        case bad => error(bad.toString)
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    31
      }
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    32
    }
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    33
  }
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    34
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    35
  def read_log(log: Path): List[Properties.T] =
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    36
    for {
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    37
      line <- split_lines(File.read_gzip(log))
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    38
      if line.startsWith(line_prefix)
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    39
      stats = line.substring(line_prefix.length)
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    40
    } yield Parser.parse_stats(stats)
293e8ec4dfc8 ML runtime statistics: read properties from build log;
wenzelm
parents:
diff changeset
    41
}