proper isabelle tool in Scala;
authorwenzelm
Wed Oct 19 17:03:44 2016 +0200 (2016-10-19)
changeset 643113d5e7719e878
parent 64310 3584841f2d2c
child 64312 1c7b77286ed0
proper isabelle tool in Scala;
Admin/profiling_report
Admin/profiling_reports
src/Pure/Admin/profiling_report.scala
src/Pure/System/isabelle_tool.scala
src/Pure/build-jars
     1.1 --- a/Admin/profiling_report	Wed Oct 19 16:30:24 2016 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,32 +0,0 @@
     1.4 -#!/usr/bin/env perl
     1.5 -#
     1.6 -# Author: Makarius
     1.7 -#
     1.8 -# DESCRIPTION: Simple report generator for Poly/ML profiling output.
     1.9 -
    1.10 -use strict;
    1.11 -
    1.12 -my %log = ();
    1.13 -my @output = ();
    1.14 -
    1.15 -while (<ARGV>) {
    1.16 -    if (m,^([ 0-9]{10}) (\S+$|GARBAGE COLLECTION.*$),) {
    1.17 -	my $count = $1;
    1.18 -	my $fun = $2;
    1.19 -	$fun =~ s,-?\(\d+\).*$,,g;
    1.20 -	$fun =~ s,/\d+$,,g;
    1.21 -	if ($count =~ m,^\s*(\d)+$,) {
    1.22 -	    if (defined($log{$fun})) {
    1.23 -		$log{$fun} += $count;
    1.24 -	    } else {
    1.25 -		$log{$fun} = $count;
    1.26 -	    }
    1.27 -	}
    1.28 -    }
    1.29 -}
    1.30 -
    1.31 -foreach my $fun (keys %log) {
    1.32 -    push @output, (sprintf "%14u %s\n", $log{$fun}, $fun);
    1.33 -}
    1.34 -
    1.35 -print (sort @output);
     2.1 --- a/Admin/profiling_reports	Wed Oct 19 16:30:24 2016 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,19 +0,0 @@
     2.4 -#!/usr/bin/env bash
     2.5 -#
     2.6 -# Author: Makarius
     2.7 -#
     2.8 -# DESCRIPTION: Cumulative reports for Poly/ML profiling output.
     2.9 -
    2.10 -THIS="$(cd $(dirname "$0"); pwd)"
    2.11 -
    2.12 -SRC="$1"
    2.13 -DST="$2"
    2.14 -
    2.15 -mkdir -p "$DST"
    2.16 -
    2.17 -for FILE in "$SRC"/*.gz
    2.18 -do
    2.19 -  echo "$FILE"
    2.20 -  NAME="$(basename "$FILE" .gz)"
    2.21 -  gzip -dc "$FILE" | "$THIS/profiling_report" > "$DST/$NAME"
    2.22 -done
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/Pure/Admin/profiling_report.scala	Wed Oct 19 17:03:44 2016 +0200
     3.3 @@ -0,0 +1,55 @@
     3.4 +/*  Title:      Pure/Admin/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/System/isabelle_tool.scala	Wed Oct 19 16:30:24 2016 +0200
     4.2 +++ b/src/Pure/System/isabelle_tool.scala	Wed Oct 19 17:03:44 2016 +0200
     4.3 @@ -106,6 +106,7 @@
     4.4        Doc.isabelle_tool,
     4.5        ML_Process.isabelle_tool,
     4.6        Options.isabelle_tool,
     4.7 +      Profiling_Report.isabelle_tool,
     4.8        Remote_DMG.isabelle_tool,
     4.9        Update_Cartouches.isabelle_tool,
    4.10        Update_Header.isabelle_tool,
     5.1 --- a/src/Pure/build-jars	Wed Oct 19 16:30:24 2016 +0200
     5.2 +++ b/src/Pure/build-jars	Wed Oct 19 17:03:44 2016 +0200
     5.3 @@ -19,6 +19,7 @@
     5.4    Admin/ci_profile.scala
     5.5    Admin/isabelle_cronjob.scala
     5.6    Admin/other_isabelle.scala
     5.7 +  Admin/profiling_report.scala
     5.8    Admin/remote_dmg.scala
     5.9    Concurrent/consumer_thread.scala
    5.10    Concurrent/counter.scala