Skip to content

Commit

Permalink
Add optional sampling interval parameter for Async profiler + switch…
Browse files Browse the repository at this point in the history
… to latest sbt version (#148)

* Add optional sampling interval parameter for Async profiler to avoid issues like: async-profiler/async-profiler#97

* Switch to latest sbt version
  • Loading branch information
plokhotnyuk authored and ktoso committed May 9, 2018
1 parent cabe738 commit a2fb1b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<? extends String> flameGraphOpts = Collections.emptyList();
Expand All @@ -50,7 +51,8 @@ public AsyncProfiler(String initLine) throws ProfilerException {
OptionSpec<String> 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<String> event = parser.accepts("event", "Event to sample: cpu, alloc, lock, cache-misses etc.").withRequiredArg().ofType(String.class).defaultsTo("cpu");
OptionSpec<Long> framebuf = parser.accepts("framebuf", "Size of profiler framebuffer").withRequiredArg().ofType(Long.class).defaultsTo(DEFAULT_FRAMEBUF);
OptionSpec<Boolean> threads = parser.accepts("threads", "profile threads separately").withRequiredArg().ofType(Boolean.class).defaultsTo(false,true);
OptionSpec<Long> interval = parser.accepts("interval", "Profiling interval, in nanoseconds").withRequiredArg().ofType(Long.class).defaultsTo(DEFAULT_INTERVAL);
OptionSpec<Boolean> threads = parser.accepts("threads", "Profile threads separately").withRequiredArg().ofType(Boolean.class).defaultsTo(false,true);
OptionSpec<Boolean> verbose = parser.accepts("verbose", "Output the sequence of commands").withRequiredArg().ofType(Boolean.class).defaultsTo(false);
OptionSpec<String> flameGraphOpts = parser.accepts("flameGraphOpts", "Options passed to FlameGraph.pl").withRequiredArg().withValuesSeparatedBy(',').ofType(String.class);
OptionSpec<Directions> flameGraphDirection = parser.accepts("flameGraphDirection", "Directions to generate flamegraphs").withRequiredArg().ofType(Directions.class).defaultsTo(Directions.values());
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/resources/sbt-jmh.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jmh.version=1.21
extras.version=0.3.4-SNAPSHOT
extras.version=0.3.5-SNAPSHOT
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.3.4-SNAPSHOT"
version in ThisBuild := "0.3.5-SNAPSHOT"

0 comments on commit a2fb1b6

Please sign in to comment.