| author | wenzelm |
| Sun, 18 Oct 2020 13:10:09 +0200 | |
| changeset 72494 | ef2082c41cd0 |
| parent 71686 | eb44cf7ae926 |
| child 72763 | 3cc73d00553c |
| permissions | -rw-r--r-- |
| 64342 | 1 |
/* Title: Pure/Tools/profiling_report.scala |
| 64311 | 2 |
Author: Makarius |
3 |
||
4 |
Report Poly/ML profiling information from log files. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import java.util.Locale |
|
11 |
||
12 |
||
13 |
object Profiling_Report |
|
14 |
{
|
|
15 |
def profiling_report(log_file: Build_Log.Log_File): List[(Long, String)] = |
|
16 |
{
|
|
17 |
val Line = """^(?:### )?([ 0-9]{10}) (\S+|GARBAGE COLLECTION.*)$""".r
|
|
18 |
val Count = """ *(\d+)""".r |
|
19 |
val clean = """-?\(\d+\).*$""".r |
|
20 |
||
21 |
var results = Map.empty[String, Long] |
|
22 |
for (Line(Count(Value.Long(count)), raw_fun) <- log_file.lines) {
|
|
23 |
val fun = clean.replaceAllIn(raw_fun, "") |
|
24 |
results += (fun -> (results.getOrElse(fun, 0L) + count)) |
|
25 |
} |
|
26 |
for ((fun, count) <- results.toList.sortBy(_._2)) yield (count, fun) |
|
27 |
} |
|
28 |
||
29 |
||
30 |
/* Isabelle tool wrapper */ |
|
31 |
||
32 |
val isabelle_tool = |
|
33 |
Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files", args =>
|
|
34 |
{
|
|
|
71686
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
35 |
val getopts = |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
36 |
Getopts("""
|
| 64311 | 37 |
Usage: isabelle profiling_report [LOGS ...] |
38 |
||
39 |
Report Poly/ML profiling output from log files (potentially compressed). |
|
40 |
""") |
|
|
71686
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
41 |
val log_names = getopts(args) |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
42 |
for (name <- log_names) {
|
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
43 |
val log_file = Build_Log.Log_File(Path.explode(name)) |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
44 |
val results = |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
45 |
for ((count, fun) <- profiling_report(log_file)) |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
46 |
yield |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
47 |
String.format(Locale.ROOT, "%14d %s", |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
48 |
count.asInstanceOf[AnyRef], fun.asInstanceOf[AnyRef]) |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
49 |
if (results.nonEmpty) |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
50 |
Output.writeln(cat_lines((log_file.name + ":") :: results)) |
| 64311 | 51 |
} |
52 |
}) |
|
53 |
} |