8000 Merge pull request #8000 from retronym/topic/jitwatch-refine · scala/scala@45b69fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 45b69fc

Browse files
authored
Merge pull request #8000 from retronym/topic/jitwatch-refine
Update instructions / automation for using JITWatch for benchmark analysis
2 parents e7d28f4 + 8e4ddcc commit 45b69fc

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@
5454
/test/target/
5555
/build-sbt/
5656
local.sbt
57+
jitwatch.out

project/JitWatch.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object JitWatchFilePlugin extends AutoPlugin {
6161
val sourceClassiferArtifacts = classiferArtifacts.filter(tuple => tuple._2.classifier == Some("sources") && dependencyModuleIds.contains(tuple._1))
6262

6363
val externalSources = sourceClassiferArtifacts.map(_._3)
64-
val internalAndExternalSources = (sourceDirectory.value +: javaHomeSrc +: (transitiveSourceDirectories ++ transitiveSourceDirectories2).distinct) ++ externalSources
64+
val internalAndExternalSources = sourceDirectories.value ++ (javaHomeSrc +: (transitiveSourceDirectories ++ transitiveSourceDirectories2).distinct) ++ externalSources
6565
props.put("Sources", internalAndExternalSources.map(_.getAbsolutePath).mkString(","))
6666
val baseDir = baseDirectory.value
6767
val lastLogDir = Keys.forkOptions.value.workingDirectory match {
@@ -73,16 +73,20 @@ object JitWatchFilePlugin extends AutoPlugin {
7373
},
7474

7575
jitwatchConfigFile := {
76-
val f = target.value / ("jitwatch-" + configuration.value.name + ".properties")
77-
val contents = jitwatchConfigFileContents.value
76+
val jitwatchProps = target.value / ("jitwatch-" + configuration.value.name + ".properties")
77+
val hotSpotLog = target.value / "hotspot.log"
7878
val log = streams.value.log
79-
val fw = new FileWriter(f)
79+
val fw = new FileWriter(jitwatchProps)
8080
try {
8181
jitwatchConfigFileContents.value.store(fw, null)
82-
log.info(s"./launchUI.sh -Djitwatch.config.file=" + f.getAbsolutePath)
82+
// TODO figure out the last benchmark that was run and focus the UI on that member with: -Djitwatch.focus.member="scala/collection/mutable/ArrayOpsBenchmark insertInteger (Lorg/openjdk/jmh/infra/Blackhole;)V"
83+
log.info(s"^-- UNRESOLVED DEPENDENCIES warnings above are normal, please ignore")
84+
log.info("After cloning https://github.com/AdoptOpenJDK/jitwatch to $JITWATCH_HOME, compile and launch with:")
85+
log.info(s"mvn -f $$JITWATCH_HOME clean compile exec:java -Djitwatch.config.file=${jitwatchProps.getAbsolutePath} -Djitwatch.logfile=${hotSpotLog.getAbsolutePath}")
86+
log.info("Note: Add, for example, `-Djitwatch.focus.member=\"scala/collection/mutable/ArrayOpsBenchmark insertInteger (Lorg/openjdk/jmh/infra/Blackhole;)V\"` to focus UI on a method of interest on startup.")
8387
} finally {
8488
fw.close()
8589
}
86-
}
90+
}
8791
)
8892
}

test/benchmarks/README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ You can generate the `hotspot.log` file for a benchmark run by adding the [requi
9393
to JMH benchmark execution:
9494

9595
```
96-
sbt:root> bench/jmh:run scala.collection.mutable.ArrayOpsBenchmark.insertInteger -psize=1000 -f1 -jvmArgs -XX:+UnlockDiagnosticVMOptions -jvmArgs -XX:+TraceClassLoading -jvmArgs -XX:+LogCompilation -jvmArgs -XX:LogFile=hotspot.log -jvmArgs -XX:+PrintAssembly
96+
sbt:root> bench/jmh:run scala.collection.mutable.ArrayOpsBenchmark.insertInteger -psize=1000 -f1 -jvmArgs -XX:+UnlockDiagnosticVMOptions -jvmArgs -XX:+TraceClassLoading -jvmArgs -XX:+LogCompilation -jvmArgs -XX:LogFile=target/hotspot.log -jvmArgs -XX:+PrintAssembly
9797
...
9898
[info] Loaded disassembler from /Users/jz/.jabba/jdk/1.8.172/Contents/Home/jre/lib/hsdis-amd64.dylib
9999
[info] Decoding compiled method 0x0000000113f60bd0:
@@ -111,34 +111,21 @@ sbt:root> bench/jmh:run scala.collection.mutable.ArrayOpsBenchmark.insertInteger
111111
[info] ArrayOpsBenchmark.insertInteger 1000 avgt 10 188199.582 ± 5930.520 ns/op
112112
```
113113

114-
JITWatch requires configuration of the class and source path. We can generate that with a custom
115-
task in our build:
114+
JITWatch requires configuration of the class and source path. We generate that with a custom task in our build:
116115

117116
```
118117
sbt> bench/jmh:jitwatchConfigFile
119118
[info] Resolving jline#jline;2.14.6 ...
120119
jmh
121-
[info] ./launchUI.sh -Djitwatch.config.file=/Users/jz/code/scala/test/benchmarks/target/jitwatch-jmh.properties
122-
120+
...
121+
[info] ^-- UNRESOLVED DEPENDENCIES warnings above are normal, please ignore
122+
[info] After cloning https://github.com/AdoptOpenJDK/jitwatch to $JITWATCH_HOME, compile and launch with:
123+
[info] mvn -f $JITWATCH_HOME clean compile exec:java -Djitwatch.config.file=/Users/jz/code/scala/test/benchmarks/target/jitwatch-compile.properties -Djitwatch.logfile=/Users/jz/code/scala/test/benchmarks/target/hotspot.log
124+
[info] Note: Add, for example, `-Djitwatch.focus.member="scala/collection/mutable/ArrayOpsBenchmark insertInteger (Lorg/openjdk/jmh/infra/Blackhole;)V"` to focus UI on a method of interest.
123125
sbt> ^C
124126
```
125127

126-
Build jitwatch.
127-
128-
```
129-
$ git clone https://github.com/AdoptOpenJDK/jitwatch
130-
$ cd jitwatch
131-
$ mvn install
132-
```
133-
134-
Launch with the generated config file.
135-
```
136-
$ ./launchUI.sh -Djitwatch.config.file=/Users/jz/code/scala/test/benchmarks/target/jitwatch-jmh.properties
137-
```
138-
139-
140-
141-
Select the generated `hotspot.log`, `start`, and then browse the benchmark to start gleaning insights!
128+
Follow instructions in the output above and start gleaning insights!
142129

143130
## Useful reading
144131
* [OpenJDK advice on microbenchmarks](https://wiki.openjdk.java.net/display/HotSpot/MicroBenchmarks)

0 commit comments

Comments
 (0)
0