Here are the examples of the java api class com.google.caliper.bridge.WorkerSpec taken from open source projects.
1. WorkerMain#main()
Project: caliper
File: WorkerMain.java
File: WorkerMain.java
public static void main(String[] args) throws Exception { // TODO(lukes): instead of parsing the spec from the command line pass the port number on the // command line and then receive the spec from the socket. This way we can start JVMs prior // to starting experiments and thus get better experiment latency. WorkerSpec request = CommandLineSerializer.parse(args[0]); // nonblocking connect so we can interleave the system call with injector creation. SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); channel.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), request.port)); WorkerComponent workerComponent = DaggerWorkerComponent.builder().experimentModule(ExperimentModule.forWorkerSpec(request)).workerModule(new WorkerModule(request)).build(); Worker worker = workerComponent.getWorker(); WorkerEventLog log = new WorkerEventLog(OpenedSocket.fromSocket(channel)); log.notifyWorkerStarted(request.trialId); try { worker.setUpBenchmark(); log.notifyBootstrapPhaseStarting(); worker.bootstrap(); log.notifyMeasurementPhaseStarting(); boolean keepMeasuring = true; boolean isInWarmup = true; while (keepMeasuring) { worker.preMeasure(isInWarmup); log.notifyMeasurementStarting(); try { ShouldContinueMessage message = log.notifyMeasurementEnding(worker.measure()); keepMeasuring = message.shouldContinue(); isInWarmup = !message.isWarmupComplete(); } finally { worker.postMeasure(); } } } catch (Exception e) { log.notifyFailure(e); } finally { // ? System.out.flush(); worker.tearDownBenchmark(); log.close(); } }
2. WorkerProcess#buildProcess()
Project: caliper
File: WorkerProcess.java
File: WorkerProcess.java
@VisibleForTesting static ProcessBuilder buildProcess(UUID trialId, Experiment experiment, BenchmarkSpec benchmarkSpec, int localPort, BenchmarkClass benchmarkClass) { // TODO(lukes): it would be nice to split this method into a few smaller more targeted methods Instrumentation instrumentation = experiment.instrumentation(); Instrument instrument = instrumentation.instrument(); WorkerSpec request = new WorkerSpec(trialId, instrumentation.workerClass(), instrumentation.workerOptions(), benchmarkSpec, ImmutableList.copyOf(instrumentation.benchmarkMethod.getParameterTypes()), localPort); ProcessBuilder processBuilder = new ProcessBuilder().redirectErrorStream(false); List<String> args = processBuilder.command(); VirtualMachine vm = experiment.vm(); VmConfig vmConfig = vm.config; args.addAll(getJvmArgs(vm, benchmarkClass)); Iterable<String> instrumentJvmOptions = instrument.getExtraCommandLineArgs(vmConfig); logger.fine(String.format("Instrument(%s) Java args: %s", instrument.getClass().getName(), instrumentJvmOptions)); Iterables.addAll(args, instrumentJvmOptions); // last to ensure that they're always applied args.addAll(vmConfig.workerProcessArgs()); args.add(WorkerMain.class.getName()); args.add(CommandLineSerializer.render(request)); logger.finest(String.format("Full JVM (%s) args: %s", vm.name, args)); return processBuilder; }