regular user tool;
authorwenzelm
Sat Oct 22 12:34:58 2016 +0200 (2016-10-22)
changeset 6434253fb4a19fb98
parent 64341 45b6faeee56d
child 64343 7cccf8704b78
regular user tool;
NEWS
src/Pure/Admin/profiling_report.scala
src/Pure/Tools/profiling_report.scala
src/Pure/build-jars
     1.1 --- a/NEWS	Sat Oct 22 12:34:17 2016 +0200
     1.2 +++ b/NEWS	Sat Oct 22 12:34:58 2016 +0200
     1.3 @@ -1041,7 +1041,9 @@
     1.4  by default).
     1.5  
     1.6  * System option "profiling" specifies the mode for global ML profiling
     1.7 -in "isabelle build". Possible values are "time", "allocations".
     1.8 +in "isabelle build". Possible values are "time", "allocations". The
     1.9 +command-line tool "isabelle profiling_report" helps to digest the
    1.10 +resulting log files.
    1.11  
    1.12  * System option "ML_process_policy" specifies an optional command prefix
    1.13  for the underlying ML process, e.g. to control CPU affinity on
     2.1 --- a/src/Pure/Admin/profiling_report.scala	Sat Oct 22 12:34:17 2016 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,55 +0,0 @@
     2.4 -/*  Title:      Pure/Admin/profiling_report.scala
     2.5 -    Author:     Makarius
     2.6 -
     2.7 -Report Poly/ML profiling information from log files.
     2.8 -*/
     2.9 -
    2.10 -package isabelle
    2.11 -
    2.12 -
    2.13 -import java.util.Locale
    2.14 -
    2.15 -
    2.16 -object Profiling_Report
    2.17 -{
    2.18 -  def profiling_report(log_file: Build_Log.Log_File): List[(Long, String)] =
    2.19 -  {
    2.20 -    val Line = """^(?:### )?([ 0-9]{10}) (\S+|GARBAGE COLLECTION.*)$""".r
    2.21 -    val Count = """ *(\d+)""".r
    2.22 -    val clean = """-?\(\d+\).*$""".r
    2.23 -
    2.24 -    var results = Map.empty[String, Long]
    2.25 -    for (Line(Count(Value.Long(count)), raw_fun) <- log_file.lines) {
    2.26 -      val fun = clean.replaceAllIn(raw_fun, "")
    2.27 -      results += (fun -> (results.getOrElse(fun, 0L) + count))
    2.28 -    }
    2.29 -    for ((fun, count) <- results.toList.sortBy(_._2)) yield (count, fun)
    2.30 -  }
    2.31 -
    2.32 -
    2.33 -  /* Isabelle tool wrapper */
    2.34 -
    2.35 -  val isabelle_tool =
    2.36 -    Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files", args =>
    2.37 -    {
    2.38 -      Command_Line.tool0 {
    2.39 -        val getopts =
    2.40 -          Getopts("""
    2.41 -Usage: isabelle profiling_report [LOGS ...]
    2.42 -
    2.43 -  Report Poly/ML profiling output from log files (potentially compressed).
    2.44 -""")
    2.45 -        val log_names = getopts(args)
    2.46 -        for (name <- log_names) {
    2.47 -          val log_file = Build_Log.Log_File(Path.explode(name))
    2.48 -          val results =
    2.49 -            for ((count, fun) <- profiling_report(log_file))
    2.50 -              yield
    2.51 -                String.format(Locale.ROOT, "%14d %s",
    2.52 -                  count.asInstanceOf[AnyRef], fun.asInstanceOf[AnyRef])
    2.53 -          if (results.nonEmpty)
    2.54 -            Output.writeln(cat_lines((log_file.name + ":") :: results))
    2.55 -        }
    2.56 -      }
    2.57 -    })
    2.58 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/Pure/Tools/profiling_report.scala	Sat Oct 22 12:34:58 2016 +0200
     3.3 @@ -0,0 +1,55 @@
     3.4 +/*  Title:      Pure/Tools/profiling_report.scala
     3.5 +    Author:     Makarius
     3.6 +
     3.7 +Report Poly/ML profiling information from log files.
     3.8 +*/
     3.9 +
    3.10 +package isabelle
    3.11 +
    3.12 +
    3.13 +import java.util.Locale
    3.14 +
    3.15 +
    3.16 +object Profiling_Report
    3.17 +{
    3.18 +  def profiling_report(log_file: Build_Log.Log_File): List[(Long, String)] =
    3.19 +  {
    3.20 +    val Line = """^(?:### )?([ 0-9]{10}) (\S+|GARBAGE COLLECTION.*)$""".r
    3.21 +    val Count = """ *(\d+)""".r
    3.22 +    val clean = """-?\(\d+\).*$""".r
    3.23 +
    3.24 +    var results = Map.empty[String, Long]
    3.25 +    for (Line(Count(Value.Long(count)), raw_fun) <- log_file.lines) {
    3.26 +      val fun = clean.replaceAllIn(raw_fun, "")
    3.27 +      results += (fun -> (results.getOrElse(fun, 0L) + count))
    3.28 +    }
    3.29 +    for ((fun, count) <- results.toList.sortBy(_._2)) yield (count, fun)
    3.30 +  }
    3.31 +
    3.32 +
    3.33 +  /* Isabelle tool wrapper */
    3.34 +
    3.35 +  val isabelle_tool =
    3.36 +    Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files", args =>
    3.37 +    {
    3.38 +      Command_Line.tool0 {
    3.39 +        val getopts =
    3.40 +          Getopts("""
    3.41 +Usage: isabelle profiling_report [LOGS ...]
    3.42 +
    3.43 +  Report Poly/ML profiling output from log files (potentially compressed).
    3.44 +""")
    3.45 +        val log_names = getopts(args)
    3.46 +        for (name <- log_names) {
    3.47 +          val log_file = Build_Log.Log_File(Path.explode(name))
    3.48 +          val results =
    3.49 +            for ((count, fun) <- profiling_report(log_file))
    3.50 +              yield
    3.51 +                String.format(Locale.ROOT, "%14d %s",
    3.52 +                  count.asInstanceOf[AnyRef], fun.asInstanceOf[AnyRef])
    3.53 +          if (results.nonEmpty)
    3.54 +            Output.writeln(cat_lines((log_file.name + ":") :: results))
    3.55 +        }
    3.56 +      }
    3.57 +    })
    3.58 +}
     4.1 --- a/src/Pure/build-jars	Sat Oct 22 12:34:17 2016 +0200
     4.2 +++ b/src/Pure/build-jars	Sat Oct 22 12:34:58 2016 +0200
     4.3 @@ -19,7 +19,6 @@
     4.4    Admin/ci_profile.scala
     4.5    Admin/isabelle_cronjob.scala
     4.6    Admin/other_isabelle.scala
     4.7 -  Admin/profiling_report.scala
     4.8    Admin/remote_dmg.scala
     4.9    Concurrent/consumer_thread.scala
    4.10    Concurrent/counter.scala
    4.11 @@ -130,6 +129,7 @@
    4.12    Tools/ml_statistics.scala
    4.13    Tools/news.scala
    4.14    Tools/print_operation.scala
    4.15 +  Tools/profiling_report.scala
    4.16    Tools/simplifier_trace.scala
    4.17    Tools/task_statistics.scala
    4.18    Tools/update_cartouches.scala