| author | paulson <lp15@cam.ac.uk> |
| Wed, 16 Mar 2022 16:14:22 +0000 | |
| changeset 75287 | 7add2d5322a7 |
| parent 74755 | 510296c0d8d1 |
| child 75393 | 87ebf5a50283 |
| permissions | -rw-r--r-- |
| 64342 | 1 |
/* Title: Pure/Tools/profiling_report.scala |
| 64311 | 2 |
Author: Makarius |
3 |
||
| 73835 | 4 |
Report Poly/ML profiling information from session build database. |
| 64311 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Profiling_Report |
|
11 |
{
|
|
| 73835 | 12 |
def profiling_report( |
13 |
options: Options, |
|
| 74712 | 14 |
session: String, |
| 73835 | 15 |
theories: List[String] = Nil, |
16 |
clean_name: Boolean = false, |
|
17 |
progress: Progress = new Progress): Unit = |
|
| 64311 | 18 |
{
|
| 73835 | 19 |
val store = Sessions.store(options) |
| 64311 | 20 |
|
| 73835 | 21 |
using(store.open_database_context())(db_context => |
22 |
{
|
|
23 |
val result = |
|
| 74712 | 24 |
db_context.input_database(session)((db, name) => Some(store.read_theories(db, name))) |
| 73835 | 25 |
result match {
|
| 74712 | 26 |
case None => error("Missing build database for session " + quote(session))
|
| 73835 | 27 |
case Some(used_theories) => |
28 |
theories.filterNot(used_theories.toSet) match {
|
|
29 |
case Nil => |
|
30 |
case bad => error("Unknown theories " + commas_quote(bad))
|
|
31 |
} |
|
32 |
val reports = |
|
33 |
(for {
|
|
34 |
thy <- used_theories.iterator |
|
35 |
if theories.isEmpty || theories.contains(thy) |
|
|
74755
510296c0d8d1
clarified signature: avoid potential misunderstanding of Resources.empty as proper Resources;
wenzelm
parents:
74712
diff
changeset
|
36 |
command <- Build_Job.read_theory(db_context, List(session), thy).iterator |
| 73835 | 37 |
snapshot = Document.State.init.snippet(command) |
| 73838 | 38 |
(Protocol.ML_Profiling(report), _) <- snapshot.messages.iterator |
| 73835 | 39 |
} yield if (clean_name) report.clean_name else report).toList |
40 |
||
41 |
for (report <- ML_Profiling.account(reports)) progress.echo(report.print) |
|
42 |
} |
|
43 |
}) |
|
| 64311 | 44 |
} |
45 |
||
46 |
||
47 |
/* Isabelle tool wrapper */ |
|
48 |
||
49 |
val isabelle_tool = |
|
| 72763 | 50 |
Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files",
|
51 |
Scala_Project.here, args => |
|
| 64311 | 52 |
{
|
| 73835 | 53 |
var theories: List[String] = Nil |
54 |
var clean_name = false |
|
55 |
var options = Options.init() |
|
56 |
||
|
71686
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
57 |
val getopts = |
|
eb44cf7ae926
tuned -- Command_Line.tool is already part of Isabelle_Tool;
wenzelm
parents:
71632
diff
changeset
|
58 |
Getopts("""
|
| 73835 | 59 |
Usage: isabelle profiling_report [OPTIONS] SESSION |
60 |
||
61 |
Options are: |
|
62 |
-T NAME restrict to given theories (multiple options possible) |
|
63 |
-c clean function names |
|
64 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
| 64311 | 65 |
|
| 73835 | 66 |
Report Poly/ML profiling from the build database of the given session |
67 |
(without up-to-date check of sources). |
|
68 |
""", |
|
69 |
"T:" -> (arg => theories = theories ::: List(arg)), |
|
70 |
"c" -> (_ => clean_name = true), |
|
71 |
"o:" -> (arg => options = options + arg)) |
|
72 |
||
73 |
val more_args = getopts(args) |
|
74 |
val session_name = |
|
75 |
more_args match {
|
|
76 |
case List(session_name) => session_name |
|
77 |
case _ => getopts.usage() |
|
78 |
} |
|
79 |
||
80 |
val progress = new Console_Progress() |
|
81 |
||
82 |
profiling_report(options, session_name, theories = theories, |
|
83 |
clean_name = clean_name, progress = progress) |
|
| 64311 | 84 |
}) |
85 |
} |