| author | wenzelm | 
| Fri, 18 Oct 2024 15:36:42 +0200 | |
| changeset 81185 | c5b398584f5e | 
| parent 78592 | fdfe9b91d96e | 
| 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 | ||
| 75393 | 10 | object Profiling_Report {
 | 
| 73835 | 11 | def profiling_report( | 
| 12 | options: Options, | |
| 74712 | 13 | session: String, | 
| 73835 | 14 | theories: List[String] = Nil, | 
| 15 | clean_name: Boolean = false, | |
| 75393 | 16 | progress: Progress = new Progress | 
| 17 |   ): Unit = {
 | |
| 78178 | 18 | val store = Store(options) | 
| 64311 | 19 | |
| 75779 
5470c67bd772
clarified signature: prefer Export.Session_Context;
 wenzelm parents: 
75778diff
changeset | 20 |     using(Export.open_session_context0(store, session)) { session_context =>
 | 
| 75780 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 21 |       session_context.session_db().map(db => store.read_theories(db, session)) match {
 | 
| 75791 | 22 | case None => store.error_database(session) | 
| 73835 | 23 | case Some(used_theories) => | 
| 24 |           theories.filterNot(used_theories.toSet) match {
 | |
| 25 | case Nil => | |
| 26 |             case bad => error("Unknown theories " + commas_quote(bad))
 | |
| 27 | } | |
| 28 | val reports = | |
| 29 |             (for {
 | |
| 30 | thy <- used_theories.iterator | |
| 31 | if theories.isEmpty || theories.contains(thy) | |
| 78280 | 32 | snapshot <- Build.read_theory(session_context.theory(thy)).iterator | 
| 78592 | 33 | case (Protocol.ML_Profiling(report), _) <- snapshot.messages.iterator | 
| 73835 | 34 | } yield if (clean_name) report.clean_name else report).toList | 
| 35 | ||
| 36 | for (report <- ML_Profiling.account(reports)) progress.echo(report.print) | |
| 37 | } | |
| 75394 | 38 | } | 
| 64311 | 39 | } | 
| 40 | ||
| 41 | ||
| 42 | /* Isabelle tool wrapper */ | |
| 43 | ||
| 44 | val isabelle_tool = | |
| 72763 | 45 |     Isabelle_Tool("profiling_report", "report Poly/ML profiling information from log files",
 | 
| 75393 | 46 | Scala_Project.here, | 
| 75394 | 47 |       { args =>
 | 
| 48 | var theories: List[String] = Nil | |
| 49 | var clean_name = false | |
| 50 | var options = Options.init() | |
| 73835 | 51 | |
| 75394 | 52 |         val getopts = Getopts("""
 | 
| 73835 | 53 | Usage: isabelle profiling_report [OPTIONS] SESSION | 
| 54 | ||
| 55 | Options are: | |
| 56 | -T NAME restrict to given theories (multiple options possible) | |
| 57 | -c clean function names | |
| 58 | -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) | |
| 64311 | 59 | |
| 77554 
4465d9dff448
clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
 wenzelm parents: 
76205diff
changeset | 60 | Report Poly/ML profiling from the sebuild database of the given session | 
| 73835 | 61 | (without up-to-date check of sources). | 
| 62 | """, | |
| 63 | "T:" -> (arg => theories = theories ::: List(arg)), | |
| 64 | "c" -> (_ => clean_name = true), | |
| 65 | "o:" -> (arg => options = options + arg)) | |
| 66 | ||
| 75394 | 67 | val more_args = getopts(args) | 
| 68 | val session_name = | |
| 69 |           more_args match {
 | |
| 70 | case List(session_name) => session_name | |
| 71 | case _ => getopts.usage() | |
| 72 | } | |
| 73835 | 73 | |
| 75394 | 74 | val progress = new Console_Progress() | 
| 73835 | 75 | |
| 75394 | 76 | profiling_report(options, session_name, theories = theories, | 
| 77 | clean_name = clean_name, progress = progress) | |
| 78 | }) | |
| 64311 | 79 | } |