Search in sources :

Example 1 with RunnerException

use of org.openjdk.jmh.runner.RunnerException in project javaslang by javaslang.

the class JmhRunner method run.

private static Array<RunResult> run(int warmupIterations, int measurementIterations, int millis, ForkJvm forkJvm, VerboseMode verboseMode, Assertions assertions, PrintInlining printInlining, Array<String> classNames, Array<String> includeNames) {
    try {
        final ChainedOptionsBuilder builder = new OptionsBuilder().shouldDoGC(true).verbosity(verboseMode).shouldFailOnError(true).mode(Mode.Throughput).timeUnit(TimeUnit.SECONDS).warmupTime(TimeValue.milliseconds(millis)).warmupIterations(warmupIterations).measurementTime(TimeValue.milliseconds(millis)).measurementIterations(measurementIterations).forks(forkJvm.forkCount).jvmArgsAppend("-XX:+UseG1GC", "-Xss100m", "-Xms4g", "-Xmx4g", "-XX:MaxGCPauseMillis=1000", "-XX:+UnlockExperimentalVMOptions", "-XX:G1NewSizePercent=100", "-XX:G1MaxNewSizePercent=100", assertions.vmArg);
        final String includePattern = includeNames.mkString("\\..*?\\b(", "|", ")_");
        classNames.forEach(name -> builder.include(name + includePattern));
        if (printInlining == PrintInlining.ENABLE) {
            builder.jvmArgsAppend("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining");
        /* might help in deciding when the JVM is properly warmed up - or where to optimize the code */
        }
        return Array.ofAll(new Runner(builder.build()).run());
    } catch (RunnerException e) {
        throw new RuntimeException(e);
    }
}
Also used : Runner(org.openjdk.jmh.runner.Runner) ChainedOptionsBuilder(org.openjdk.jmh.runner.options.ChainedOptionsBuilder) RunnerException(org.openjdk.jmh.runner.RunnerException) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) ChainedOptionsBuilder(org.openjdk.jmh.runner.options.ChainedOptionsBuilder)

Example 2 with RunnerException

use of org.openjdk.jmh.runner.RunnerException in project h2o-3 by h2oai.

the class H2OResultFormat method main.

/**
   * Copy of {@link org.openjdk.jmh.Main#main(java.lang.String[])}
   *
   * @param args command line parameters
   */
public static void main(String[] args) {
    // Try to run benchmark and collect results
    try {
        CommandLineOptions cmdOptions = new CommandLineOptions(args);
        Runner runner = new Runner(cmdOptions);
        Collection<RunResult> results = null;
        try {
            results = runner.run();
            // Bench code passed so report results
            if (H2O_UBENCH_REPORT_FILE != null) {
                // Create an output directory
                File ubenchReportFile = new File(H2O_UBENCH_REPORT_FILE);
                getResultFormater(ubenchReportFile).writeOut(results);
            }
        } catch (NoBenchmarksException e) {
            System.err.println("No matching benchmarks. Miss-spelled regexp?");
            if (cmdOptions.verbosity().orElse(Defaults.VERBOSITY) != VerboseMode.EXTRA) {
                System.err.println("Use " + VerboseMode.EXTRA + " verbose mode to debug the pattern matching.");
            } else {
                runner.list();
            }
            System.exit(1);
        } catch (ProfilersFailedException e) {
            // This is not exactly an error, set non-zero exit code
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (RunnerException e) {
            System.err.print("ERROR: ");
            e.printStackTrace(System.err);
            System.exit(1);
        }
    } catch (CommandLineOptionException e) {
        System.err.println("Error parsing command line:");
        System.err.println(" " + e.getMessage());
        System.exit(1);
    }
}
Also used : Runner(org.openjdk.jmh.runner.Runner) CommandLineOptionException(org.openjdk.jmh.runner.options.CommandLineOptionException) CommandLineOptions(org.openjdk.jmh.runner.options.CommandLineOptions) RunnerException(org.openjdk.jmh.runner.RunnerException) NoBenchmarksException(org.openjdk.jmh.runner.NoBenchmarksException) ProfilersFailedException(org.openjdk.jmh.runner.ProfilersFailedException) RunResult(org.openjdk.jmh.results.RunResult) File(java.io.File)

Example 3 with RunnerException

use of org.openjdk.jmh.runner.RunnerException in project mule by mulesoft.

the class AbstractBenchmarkAssertionTestCase method runAndAssertBenchmark.

/**
 * Run a JMH benchmark and assert that the primary result is less than or equal to an expected value.
 *
 * @param clazz the JMS benchmark class.
 * @param testName the name of the test method.
 * @param threads the number of threads to run benchmark with.
 * @param params parameters along with array of parameters values to be applied to the benchmark.
 * @param timeUnit the time unit of the expected result value.
 * @param assertions assertion consumer.
 */
protected void runAndAssertBenchmark(Class clazz, String testName, int threads, Map<String, String[]> params, TimeUnit timeUnit, boolean profileGC, Consumer<RunResult> assertions) {
    try {
        if (getBoolean(getProperty(ENABLE_PERFORMANCE_TESTS_SYSTEM_PROPERTY))) {
            ChainedOptionsBuilder optionsBuilder = createCommonOptionsBuilder(clazz, testName, params, timeUnit, profileGC);
            optionsBuilder = optionsBuilder.forks(1).threads(threads).warmupIterations(10).measurementIterations(10);
            assertions.accept(new Runner(optionsBuilder.build()).runSingle());
        } else {
            ChainedOptionsBuilder optionsBuilder = createCommonOptionsBuilder(clazz, testName, params, timeUnit, profileGC);
            optionsBuilder = optionsBuilder.forks(0).warmupIterations(0).measurementIterations(1);
            new Runner(optionsBuilder.build()).runSingle();
        }
    } catch (RunnerException e) {
        fail(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Runner(org.openjdk.jmh.runner.Runner) ChainedOptionsBuilder(org.openjdk.jmh.runner.options.ChainedOptionsBuilder) RunnerException(org.openjdk.jmh.runner.RunnerException)

Aggregations

Runner (org.openjdk.jmh.runner.Runner)3 RunnerException (org.openjdk.jmh.runner.RunnerException)3 ChainedOptionsBuilder (org.openjdk.jmh.runner.options.ChainedOptionsBuilder)2 File (java.io.File)1 RunResult (org.openjdk.jmh.results.RunResult)1 NoBenchmarksException (org.openjdk.jmh.runner.NoBenchmarksException)1 ProfilersFailedException (org.openjdk.jmh.runner.ProfilersFailedException)1 CommandLineOptionException (org.openjdk.jmh.runner.options.CommandLineOptionException)1 CommandLineOptions (org.openjdk.jmh.runner.options.CommandLineOptions)1 OptionsBuilder (org.openjdk.jmh.runner.options.OptionsBuilder)1