HDDS-1104. Use picocli with Ozone genesis tool. Contributed by Lokesh Jain.

This commit is contained in:
Márton Elek 2019-02-26 16:11:02 +01:00
parent 9e0f3d1c52
commit 585cebf26b
No known key found for this signature in database
GPG Key ID: D51EA8F00EE79B28
1 changed files with 43 additions and 14 deletions

View File

@ -21,8 +21,10 @@ package org.apache.hadoop.ozone.genesis;
import org.openjdk.jmh.profile.StackProfiler; import org.openjdk.jmh.profile.StackProfiler;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.OptionsBuilder;
import picocli.CommandLine;
import picocli.CommandLine.Option;
import picocli.CommandLine.Command;
/** /**
* Main class that executes a set of HDDS/Ozone benchmarks. * Main class that executes a set of HDDS/Ozone benchmarks.
@ -32,30 +34,57 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
* Hence, these classes do not use the Tool/Runner pattern of standard Hadoop * Hence, these classes do not use the Tool/Runner pattern of standard Hadoop
* CLI. * CLI.
*/ */
@Command(name = "ozone genesis",
description = "Tool for running ozone benchmarks",
mixinStandardHelpOptions = true)
public final class Genesis { public final class Genesis {
// For adding benchmark to Genesis add the benchmark name in the default value
// and description for this option.
@Option(names = "-benchmark", required = true, split = ",",
defaultValue = "BenchMarkContainerStateMap,BenchMarkOMKeyAllocation,"
+ "BenchMarkBlockManager,BenchMarkMetadataStoreReads,"
+ "BenchMarkMetadataStoreWrites,BenchMarkDatanodeDispatcher"
+ "BenchMarkRocksDbStore",
description =
"Option used for specifying benchmarks to run.\n"
+ "Ex. ozone genesis -benchmark BenchMarkContainerStateMap,"
+ "BenchMarkOMKeyAllocation.\n"
+ "Possible benchmarks which can be used are "
+ "{BenchMarkContainerStateMap, BenchMarkOMKeyAllocation, "
+ "BenchMarkBlockManager, BenchMarkMetadataStoreReads, "
+ "BenchMarkMetadataStoreWrites, BenchMarkDatanodeDispatcher, "
+ "BenchMarkRocksDbStore}")
private static String[] benchmarks;
@Option(names = "-t", defaultValue = "4",
description = "Number of threads to use for the benchmark.\n"
+ "This option can be overridden by threads mentioned in benchmark.")
private static int numThreads;
private Genesis() { private Genesis() {
} }
public static void main(String[] args) throws RunnerException { public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder() CommandLine commandLine = new CommandLine(new Genesis());
.include(BenchMarkContainerStateMap.class.getSimpleName()) commandLine.parse(args);
.include(BenchMarkOMKeyAllocation.class.getSimpleName()) if (commandLine.isUsageHelpRequested()) {
.include(BenchMarkBlockManager.class.getSimpleName()) commandLine.usage(System.out);
// .include(BenchMarkMetadataStoreReads.class.getSimpleName()) return;
// .include(BenchMarkMetadataStoreWrites.class.getSimpleName()) }
// .include(BenchMarkDatanodeDispatcher.class.getSimpleName())
// Commenting this test out, till we support either a command line or a config OptionsBuilder optionsBuilder = new OptionsBuilder();
// file based ability to run tests. for (String benchmark : benchmarks) {
// .include(BenchMarkRocksDbStore.class.getSimpleName()) optionsBuilder.include(benchmark);
.warmupIterations(5) }
optionsBuilder.warmupIterations(2)
.measurementIterations(20) .measurementIterations(20)
.addProfiler(StackProfiler.class) .addProfiler(StackProfiler.class)
.shouldDoGC(true) .shouldDoGC(true)
.forks(1) .forks(1)
.build(); .threads(numThreads);
new Runner(opt).run(); new Runner(optionsBuilder.build()).run();
} }
} }