8000 Update instructions / automation for using JITWatch for benchmark analysis by retronym · Pull Request #8000 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Update instructions / automation for using JITWatch for benchmark analysis #8000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update instructions an automation for using JITWatch for benchmark an…
…alysis

  - Fix source directories of the benchmarks themselves in the generated
    jitwatch.properties
  - Tell JITWatch where hotspot.log is located
    (see AdoptOpenJDK/jitwatch#302)
  - Advise use of `mvn:exec java` rather than `launchUI.sh`. This should be cross-platform
    and handles compilation and execution in one command.
  - Move some instructions out of README.md and into the output of the jitwatchConfig task.
  - git ignore temp file generated in the working directory when following these instructions.
  • Loading branch information
retronym committed Apr 26, 2019
commit 8e4ddcc3f9c292be01e2498a8e4193f9eb799b33
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
/test/target/
/build-sbt/
local.sbt
jitwatch.out
16 changes: 10 additions & 6 deletions project/JitWatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object JitWatchFilePlugin extends AutoPlugin {
val sourceClassiferArtifacts = classiferArtifacts.filter(tuple => tuple._2.classifier == Some("sources") && dependencyModuleIds.contains(tuple._1))

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

jitwatchConfigFile := {
val f = target.value / ("jitwatch-" + configuration.value.name + ".properties")
val contents = jitwatchConfigFileContents.value
val jitwatchProps = target.value / ("jitwatch-" + configuration.value.name + ".properties")
val hotSpotLog = target.value / "hotspot.log"
val log = streams.value.log
val fw = new FileWriter(f)
val fw = new FileWriter(jitwatchProps)
try {
jitwatchConfigFileContents.value.store(fw, null)
log.info(s"./launchUI.sh -Djitwatch.config.file=" + f.getAbsolutePath)
// 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"
log.info(s"^-- UNRESOLVED DEPENDENCIES warnings above are normal, please ignore")
log.info("After cloning https://github.com/AdoptOpenJDK/jitwatch to $JITWATCH_HOME, compile and launch with:")
log.info(s"mvn -f $$JITWATCH_HOME clean compile exec:java -Djitwatch.config.file=${jitwatchProps.getAbsolutePath} -Djitwatch.logfile=${hotSpotLog.getAbsolutePath}")
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.")
} finally {
fw.close()
}
}
}
)
}
29 changes: 8 additions & 21 deletions test/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ You can generate the `hotspot.log` file for a benchmark run by adding the [requi
to JMH benchmark execution:

```
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
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
...
[info] Loaded disassembler from /Users/jz/.jabba/jdk/1.8.172/Contents/Home/jre/lib/hsdis-amd64.dylib
[info] Decoding compiled method 0x0000000113f60bd0:
Expand All @@ -111,34 +111,21 @@ sbt:root> bench/jmh:run scala.collection.mutable.ArrayOpsBenchmark.insertInteger
[info] ArrayOpsBenchmark.insertInteger 1000 avgt 10 188199.582 ± 5930.520 ns/op
```

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

```
sbt> bench/jmh:jitwatchConfigFile
[info] Resolving jline#jline;2.14.6 ...
jmh
[info] ./launchUI.sh -Djitwatch.config.file=/Users/jz/code/scala/test/benchmarks/target/jitwatch-jmh.properties

...
[info] ^-- UNRESOLVED DEPENDENCIES warnings above are normal, please ignore
[info] After cloning https://github.com/AdoptOpenJDK/jitwatch to $JITWATCH_HOME, compile and launch with:
[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
[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.
sbt> ^C
```

Build jitwatch.

```
$ git clone https://github.com/AdoptOpenJDK/jitwatch
$ cd jitwatch
$ mvn install
```

Launch with the generated config file.
```
$ ./launchUI.sh -Djitwatch.config.file=/Users/jz/code/scala/test/benchmarks/target/jitwatch-jmh.properties
```



Select the generated `hotspot.log`, `start`, and then browse the benchmark to start gleaning insights!
Follow instructions in the output above and start gleaning insights!

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