src/Pure/Tools/profiling_report.scala
changeset 64342 53fb4a19fb98
parent 64311 3d5e7719e878
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Tools/profiling_report.scala	Sat Oct 22 12:34:58 2016 +0200
     1.3 @@ -0,0 +1,55 @@
     1.4 +/*  Title:      Pure/Tools/profiling_report.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Report Poly/ML profiling information from log files.
     1.8 +*/
     1.9 +
    1.10 +package isabelle
    1.11 +
    1.12 +
    1.13 +import java.util.Locale
    1.14 +
    1.15 +
    1.16 +object Profiling_Report
    1.17 +{
    1.18 +  def profiling_report(log_file: Build_Log.Log_File): List[(Long, String)] =
    1.19 +  {
    1.20 +    val Line = """^(?:### )?([ 0-9]{10}) (\S+|GARBAGE COLLECTION.*)$""".r
    1.21 +    val Count = """ *(\d+)""".r
    1.22 +    val clean = """-?\(\d+\).*$""".r
    1.23 +
    1.24 +    var results = Map.empty[String, Long]
    1.25 +    for (Line(Count(Value.Long(count)), raw_fun) <- log_file.lines) {
    1.26 +      val fun = clean.replaceAllIn(raw_fun, "")
    1.27 +      results += (fun -> (results.getOrElse(fun, 0L) + count))
    1.28 +    }
    1.29 +    for ((fun, count) <- results.toList.sortBy(_._2)) yield (count, fun)
    1.30 +  }
    1.31 +
    1.32 +
    1.33 +  /* Isabelle tool wrapper */
    1.34 +
    1.35 +  val isabelle_tool =
    1.36 +    Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files", args =>
    1.37 +    {
    1.38 +      Command_Line.tool0 {
    1.39 +        val getopts =
    1.40 +          Getopts("""
    1.41 +Usage: isabelle profiling_report [LOGS ...]
    1.42 +
    1.43 +  Report Poly/ML profiling output from log files (potentially compressed).
    1.44 +""")
    1.45 +        val log_names = getopts(args)
    1.46 +        for (name <- log_names) {
    1.47 +          val log_file = Build_Log.Log_File(Path.explode(name))
    1.48 +          val results =
    1.49 +            for ((count, fun) <- profiling_report(log_file))
    1.50 +              yield
    1.51 +                String.format(Locale.ROOT, "%14d %s",
    1.52 +                  count.asInstanceOf[AnyRef], fun.asInstanceOf[AnyRef])
    1.53 +          if (results.nonEmpty)
    1.54 +            Output.writeln(cat_lines((log_file.name + ":") :: results))
    1.55 +        }
    1.56 +      }
    1.57 +    })
    1.58 +}