| author | Fabian Huch <huch@in.tum.de> |
| Wed, 13 Mar 2024 11:54:06 +0100 | |
| changeset 79880 | a3d53f2bc41d |
| parent 79874 | 1e7b5a258bc5 |
| child 79887 | 17220dc05991 |
| permissions | -rw-r--r-- |
| 79874 | 1 |
/* Title: Pure/Build/build_benchmark.scala |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Fabian Huch, TU Muenchen |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
3 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
4 |
Host platform benchmarks for performance estimation. |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
5 |
*/ |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
6 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
7 |
package isabelle |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
8 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
9 |
|
| 79620 | 10 |
object Build_Benchmark {
|
| 79625 | 11 |
/* benchmark */ |
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
12 |
|
| 79625 | 13 |
// ZF-Constructible as representative benchmark session with |
14 |
// short build time and requirements |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
15 |
val benchmark_session = "ZF-Constructible" |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
16 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
17 |
def benchmark_command( |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
18 |
host: Build_Cluster.Host, |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
19 |
ssh: SSH.System = SSH.Local, |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
20 |
isabelle_home: Path = Path.current, |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
21 |
): String = {
|
| 78916 | 22 |
val options = Options.Spec.eq("build_hostname", host.name) :: host.options
|
| 79624 | 23 |
ssh.bash_path(Isabelle_Tool.exe(isabelle_home)) + " build_benchmark" + |
|
78915
90756ad4d8d7
more accurate treatment of surrounding whitespace;
wenzelm
parents:
78908
diff
changeset
|
24 |
Options.Spec.bash_strings(options, bg = true) |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
25 |
} |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
26 |
|
| 79641 | 27 |
def benchmark_requirements(options: Options, progress: Progress = new Progress): Unit = {
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
28 |
val res = |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
29 |
Build.build( |
| 79642 | 30 |
options.string.update("build_engine", Build.Engine.Default.name),
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
31 |
selection = Sessions.Selection(requirements = true, sessions = List(benchmark_session)), |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
32 |
progress = progress, build_heap = true) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
33 |
if (!res.ok) error("Failed building requirements")
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
34 |
} |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
35 |
|
| 79641 | 36 |
def benchmark(options: Options, progress: Progress = new Progress): Unit = {
|
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
37 |
val hostname = options.string("build_hostname")
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
38 |
val store = Store(options) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
39 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
40 |
using(store.open_server()) { server =>
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
41 |
using_optional(store.maybe_open_database_server(server = server)) { database_server =>
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
42 |
val db = store.open_build_database(path = Host.private_data.database, server = server) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
43 |
|
| 79617 | 44 |
progress.echo("Starting benchmark ...")
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
45 |
val selection = Sessions.Selection(sessions = List(benchmark_session)) |
| 79657 | 46 |
val full_sessions = Sessions.load_structure(options + "threads=1") |
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
47 |
|
| 79644 | 48 |
val build_deps = Sessions.deps(full_sessions.selection(selection)).check_errors |
49 |
val build_context = Build.Context(store, build_deps, jobs = 1) |
|
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
50 |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
51 |
val sessions = Build_Process.Sessions.empty.init(build_context, database_server, progress) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
52 |
val session = sessions(benchmark_session) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
53 |
|
|
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79660
diff
changeset
|
54 |
val hierachy = session.ancestors.map(store.output_session(_, store_heap = true)) |
| 79698 | 55 |
for (db <- database_server) ML_Heap.restore(db, hierachy, cache = store.cache.compress) |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
56 |
|
| 79660 | 57 |
val local_options = options + "build_database_server=false" + "build_database=false" |
|
79295
123651f3ec5d
restore benchmark requirement heaps properly;
Fabian Huch <huch@in.tum.de>
parents:
79291
diff
changeset
|
58 |
|
|
123651f3ec5d
restore benchmark requirement heaps properly;
Fabian Huch <huch@in.tum.de>
parents:
79291
diff
changeset
|
59 |
benchmark_requirements(local_options, progress) |
| 79698 | 60 |
for (db <- database_server) ML_Heap.restore(db, hierachy, cache = store.cache.compress) |
|
79295
123651f3ec5d
restore benchmark requirement heaps properly;
Fabian Huch <huch@in.tum.de>
parents:
79291
diff
changeset
|
61 |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
62 |
def get_shasum(session_name: String): SHA1.Shasum = {
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
63 |
val ancestor_shasums = sessions(session_name).ancestors.map(get_shasum) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
64 |
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
65 |
val input_shasum = |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
66 |
if (ancestor_shasums.isEmpty) ML_Process.bootstrap_shasum() |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
67 |
else SHA1.flat_shasum(ancestor_shasums) |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
68 |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
69 |
store.check_output( |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
70 |
database_server, session_name, |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
71 |
session_options = build_context.sessions_structure(session_name).options, |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
72 |
sources_shasum = sessions(session_name).sources_shasum, |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
73 |
input_shasum = input_shasum, |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
74 |
fresh_build = false, |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
75 |
store_heap = false)._2 |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
76 |
} |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
77 |
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
78 |
val deps = Sessions.deps(full_sessions.selection(selection)).check_errors |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
79 |
val background = deps.background(benchmark_session) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
80 |
val input_shasum = get_shasum(benchmark_session) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
81 |
val node_info = Host.Node_Info(hostname, None, Nil) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
82 |
|
|
79295
123651f3ec5d
restore benchmark requirement heaps properly;
Fabian Huch <huch@in.tum.de>
parents:
79291
diff
changeset
|
83 |
val local_build_context = build_context.copy(store = Store(local_options)) |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
84 |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
85 |
val build = |
| 79777 | 86 |
Build_Job.start_session(local_build_context, session, progress, new Logger, server, |
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
87 |
background, session.sources_shasum, input_shasum, node_info, false) |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
88 |
|
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
89 |
val timing = |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
90 |
build.join match {
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
91 |
case Some(result) if result.process_result.ok => result.process_result.timing |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
92 |
case _ => error("Failed to build benchmark session")
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
93 |
} |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
94 |
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
95 |
val score = Time.seconds(1000).ms.toDouble / (1 + timing.elapsed.ms) |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
96 |
progress.echo( |
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
97 |
"Finished benchmark in " + timing.message + ". Score: " + String.format("%.2f", score))
|
|
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
98 |
|
| 79602 | 99 |
Host.write_info(db, Host.Info.init(hostname = hostname, score = Some(score))) |
|
79291
e9a788a75775
use single-threaded session build as benchmark (using ZF-Constructible);
Fabian Huch <huch@in.tum.de>
parents:
78916
diff
changeset
|
100 |
} |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
101 |
} |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
102 |
} |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
103 |
|
| 79625 | 104 |
|
105 |
/* Isabelle tool wrapper */ |
|
106 |
||
| 79620 | 107 |
val isabelle_tool = Isabelle_Tool("build_benchmark", "run benchmark for build process",
|
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
108 |
Scala_Project.here, |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
109 |
{ args =>
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
110 |
var options = Options.init() |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
111 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
112 |
val getopts = Getopts("""
|
| 79620 | 113 |
Usage: isabelle build_benchmark [OPTIONS] |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
114 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
115 |
Options are: |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
116 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
117 |
|
| 79620 | 118 |
Run benchmark for build process. |
|
78840
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
119 |
""", |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
120 |
"o:" -> (arg => options = options + arg)) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
121 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
122 |
val more_args = getopts(args) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
123 |
if (more_args.nonEmpty) getopts.usage() |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
124 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
125 |
val progress = new Console_Progress() |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
126 |
|
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
127 |
benchmark(options, progress = progress) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
128 |
}) |
|
4b528ca25573
added initial version of benchmark module, e.g., to compare performance of different hosts;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
129 |
} |