From af8e7017318762c69538d3410a7b9f3b9d1107d8 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 9 May 2018 15:34:43 +0200 Subject: [PATCH 1/2] Add optional sampling interval parameter for Async profiler to avoid issues like: https://github.com/jvm-profiling-tools/async-profiler/issues/97 --- .../scala/jmh/extras/profiler/AsyncProfiler.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extras/src/main/java/pl/project13/scala/jmh/extras/profiler/AsyncProfiler.java b/extras/src/main/java/pl/project13/scala/jmh/extras/profiler/AsyncProfiler.java index d435aee..224a2c0 100644 --- a/extras/src/main/java/pl/project13/scala/jmh/extras/profiler/AsyncProfiler.java +++ b/extras/src/main/java/pl/project13/scala/jmh/extras/profiler/AsyncProfiler.java @@ -12,7 +12,6 @@ import org.openjdk.jmh.runner.IterationType; import org.openjdk.jmh.util.Utils; -import java.io.BufferedReader; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -27,6 +26,7 @@ public class AsyncProfiler implements InternalProfiler { private static final String DEFAULT_EVENT = "cpu"; private static final long DEFAULT_FRAMEBUF = 8 * 1024 * 1024; + private static final long DEFAULT_INTERVAL = 1000000; private final String event; private final Directions directions; private final Path asyncProfilerDir; @@ -38,6 +38,7 @@ public class AsyncProfiler implements InternalProfiler { private Path profiler; private Path jattach; private Long framebuf; + private Long interval; private int measurementIterationCount; private Path flameGraphDir; private Collection flameGraphOpts = Collections.emptyList(); @@ -50,7 +51,8 @@ public AsyncProfiler(String initLine) throws ProfilerException { OptionSpec asyncProfilerDir = parser.accepts("asyncProfilerDir", "Location of clone of https://github.com/jvm-profiling-tools/async-profiler. Also can be provided as $" + ASYNC_PROFILER_DIR).withRequiredArg().ofType(String.class).describedAs("directory"); OptionSpec event = parser.accepts("event", "Event to sample: cpu, alloc, lock, cache-misses etc.").withRequiredArg().ofType(String.class).defaultsTo("cpu"); OptionSpec framebuf = parser.accepts("framebuf", "Size of profiler framebuffer").withRequiredArg().ofType(Long.class).defaultsTo(DEFAULT_FRAMEBUF); - OptionSpec threads = parser.accepts("threads", "profile threads separately").withRequiredArg().ofType(Boolean.class).defaultsTo(false,true); + OptionSpec interval = parser.accepts("interval", "Profiling interval, in nanoseconds").withRequiredArg().ofType(Long.class).defaultsTo(DEFAULT_INTERVAL); + OptionSpec threads = parser.accepts("threads", "Profile threads separately").withRequiredArg().ofType(Boolean.class).defaultsTo(false,true); OptionSpec verbose = parser.accepts("verbose", "Output the sequence of commands").withRequiredArg().ofType(Boolean.class).defaultsTo(false); OptionSpec flameGraphOpts = parser.accepts("flameGraphOpts", "Options passed to FlameGraph.pl").withRequiredArg().withValuesSeparatedBy(',').ofType(String.class); OptionSpec flameGraphDirection = parser.accepts("flameGraphDirection", "Directions to generate flamegraphs").withRequiredArg().ofType(Directions.class).defaultsTo(Directions.values()); @@ -69,6 +71,11 @@ public AsyncProfiler(String initLine) throws ProfilerException { } else { this.framebuf = DEFAULT_FRAMEBUF; } + if (options.has(interval)) { + this.interval = options.valueOf(interval); + } else { + this.interval = DEFAULT_INTERVAL; + } if (options.has(outputDir)) { this.outputDir = Paths.get(options.valueOf(outputDir)); createOutputDirectories(); @@ -137,7 +144,7 @@ private void createOutputDirectories() { public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) { if (!started && iterationParams.getType() == IterationType.MEASUREMENT) { String threadOpt = this.threads ? ",threads" : ""; - profilerCommand(String.format("start,event=%s%s,framebuf=%d", event, threadOpt, framebuf)); + profilerCommand(String.format("start,event=%s%s,framebuf=%d,interval=%d", event, threadOpt, framebuf, interval)); started = true; } } From 4862616a021d1b9cd85a5fb384e49664fc254c0f Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 9 May 2018 15:35:20 +0200 Subject: [PATCH 2/2] Switch to latest sbt version --- build.sbt | 2 +- plugin/src/main/resources/sbt-jmh.properties | 2 +- version.sbt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 279945b..4199628 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,7 @@ val jmhVersion = { val commonSettings = Seq( organization := "pl.project13.scala", - crossSbtVersions := Vector("0.13.17", "1.1.4"), + crossSbtVersions := Vector("1.1.5", "0.13.17"), scalacOptions ++= List( "-unchecked", diff --git a/plugin/src/main/resources/sbt-jmh.properties b/plugin/src/main/resources/sbt-jmh.properties index 9f5c6d9..531f711 100644 --- a/plugin/src/main/resources/sbt-jmh.properties +++ b/plugin/src/main/resources/sbt-jmh.properties @@ -1,2 +1,2 @@ jmh.version=1.21 -extras.version=0.3.4-SNAPSHOT +extras.version=0.3.5-SNAPSHOT diff --git a/version.sbt b/version.sbt index dfd7e19..fb2797b 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.3.4-SNAPSHOT" +version in ThisBuild := "0.3.5-SNAPSHOT"