Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.openjdk.jmh.runner.BenchmarkListEntry Maven / Gradle / Ivy
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.jmh.runner;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.runner.options.TimeValue;
import org.openjdk.jmh.util.Optional;
import org.openjdk.jmh.util.Utils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
public class BenchmarkListEntry implements Comparable {
private static final String BR_SEPARATOR = "===,===";
private final String userClassQName;
private final String generatedClassQName;
private final String method;
private final Mode mode;
private final int[] threadGroups;
private final Optional threads;
private final Optional warmupIterations;
private final Optional warmupTime;
private final Optional warmupBatchSize;
private final Optional measurementIterations;
private final Optional measurementTime;
private final Optional measurementBatchSize;
private final Optional forks;
private final Optional warmupForks;
private final Optional jvm;
private final Optional> jvmArgs;
private final Optional> jvmArgsPrepend;
private final Optional> jvmArgsAppend;
private final Optional> params;
private final Optional tu;
private final Optional opsPerInvocation;
private final Optional timeout;
private WorkloadParams workloadParams;
public BenchmarkListEntry(String userClassQName, String generatedClassQName, String method, Mode mode, int[] threadGroups, Optional threads,
Optional warmupIterations, Optional warmupTime, Optional warmupBatchSize,
Optional measurementIterations, Optional measurementTime, Optional measurementBatchSize,
Optional forks, Optional warmupForks,
Optional jvm, Optional> jvmArgs, Optional> jvmArgsPrepend, Optional> jvmArgsAppend,
Optional> params, Optional tu, Optional opsPerInv,
Optional timeout) {
this.userClassQName = userClassQName;
this.generatedClassQName = generatedClassQName;
this.method = method;
this.mode = mode;
this.threadGroups = threadGroups;
this.threads = threads;
this.warmupIterations = warmupIterations;
this.warmupTime = warmupTime;
this.warmupBatchSize = warmupBatchSize;
this.measurementIterations = measurementIterations;
this.measurementTime = measurementTime;
this.measurementBatchSize = measurementBatchSize;
this.forks = forks;
this.warmupForks = warmupForks;
this.jvm = jvm;
this.jvmArgs = jvmArgs;
this.jvmArgsPrepend = jvmArgsPrepend;
this.jvmArgsAppend = jvmArgsAppend;
this.params = params;
this.workloadParams = new WorkloadParams();
this.tu = tu;
this.opsPerInvocation = opsPerInv;
this.timeout = timeout;
}
public BenchmarkListEntry(String line) {
String[] args = line.split(BR_SEPARATOR);
if (args.length != 22) {
throw new IllegalStateException("Mismatched format for the line: " + line);
}
this.workloadParams = new WorkloadParams();
int idx = 0;
this.userClassQName = args[idx++].trim();
this.generatedClassQName = args[idx++].trim();
this.method = args[idx++].trim();
this.mode = Mode.deepValueOf(args[idx++].trim());
this.threadGroups = Utils.unmarshalIntArray(args[idx++]);
this.threads = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.warmupIterations = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.warmupTime = Optional.of(args[idx++], TIME_VALUE_UNMARSHALLER);
this.warmupBatchSize = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.measurementIterations = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.measurementTime = Optional.of(args[idx++], TIME_VALUE_UNMARSHALLER);
this.measurementBatchSize = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.forks = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.warmupForks = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.jvm = Optional.of(args[idx++], STRING_UNMARSHALLER);
this.jvmArgs = Optional.of(args[idx++], STRING_COLLECTION_UNMARSHALLER);
this.jvmArgsPrepend = Optional.of(args[idx++], STRING_COLLECTION_UNMARSHALLER);
this.jvmArgsAppend = Optional.of(args[idx++], STRING_COLLECTION_UNMARSHALLER);
this.params = Optional.of(args[idx++], PARAM_COLLECTION_UNMARSHALLER);
this.tu = Optional.of(args[idx++], TIMEUNIT_UNMARSHALLER);
this.opsPerInvocation = Optional.of(args[idx++], INTEGER_UNMARSHALLER);
this.timeout = Optional.of(args[idx++], TIME_VALUE_UNMARSHALLER);
}
public BenchmarkListEntry(String userClassQName, String generatedName, String method, Mode mode) {
this(userClassQName, generatedName, method, mode, new int[]{}, Optional.none(),
Optional.none(), Optional.none(), Optional.none(), Optional.none(), Optional.none(), Optional.none(),
Optional.none(), Optional.none(),
Optional.none(), Optional.>none(), Optional.>none(), Optional.>none(),
Optional.>none(), Optional.none(), Optional.none(),
Optional.none());
}
public String toLine() {
return userClassQName + BR_SEPARATOR + generatedClassQName + BR_SEPARATOR + method + BR_SEPARATOR + mode + BR_SEPARATOR + Utils.marshalIntArray(threadGroups) + BR_SEPARATOR +
threads + BR_SEPARATOR + warmupIterations + BR_SEPARATOR + warmupTime + BR_SEPARATOR + warmupBatchSize + BR_SEPARATOR +
measurementIterations + BR_SEPARATOR + measurementTime + BR_SEPARATOR + measurementBatchSize + BR_SEPARATOR +
forks + BR_SEPARATOR + warmupForks + BR_SEPARATOR +
jvm.toString(STRING_MARSHALLER) + BR_SEPARATOR +
jvmArgs.toString(STRING_COLLECTION_MARSHALLER) + BR_SEPARATOR +
jvmArgsPrepend.toString(STRING_COLLECTION_MARSHALLER) + BR_SEPARATOR +
jvmArgsAppend.toString(STRING_COLLECTION_MARSHALLER) + BR_SEPARATOR +
params.toString(PARAM_COLLECTION_MARSHALLER) + BR_SEPARATOR + tu.toString(TIMEUNIT_MARSHALLER) + BR_SEPARATOR +
opsPerInvocation + BR_SEPARATOR +
timeout;
}
public BenchmarkListEntry cloneWith(Mode mode) {
return new BenchmarkListEntry(userClassQName, generatedClassQName, method, mode, threadGroups, threads,
warmupIterations, warmupTime, warmupBatchSize,
measurementIterations, measurementTime, measurementBatchSize,
forks, warmupForks,
jvm, jvmArgs, jvmArgsPrepend, jvmArgsAppend,
params, tu, opsPerInvocation,
timeout);
}
public BenchmarkListEntry cloneWith(WorkloadParams p) {
BenchmarkListEntry br = new BenchmarkListEntry(userClassQName, generatedClassQName, method, mode, threadGroups, threads,
warmupIterations, warmupTime, warmupBatchSize,
measurementIterations, measurementTime, measurementBatchSize,
forks, warmupForks,
jvm, jvmArgs, jvmArgsPrepend, jvmArgsAppend,
params, tu, opsPerInvocation,
timeout);
br.workloadParams = p;
return br;
}
public WorkloadParams getWorkloadParams() {
return workloadParams;
}
@Override
public int compareTo(BenchmarkListEntry o) {
int v = mode.compareTo(o.mode);
if (v != 0) {
return v;
}
int v1 = getUsername().compareTo(o.getUsername());
if (v1 != 0) {
return v1;
}
if (workloadParams == null || o.workloadParams == null) {
return 0;
}
return workloadParams.compareTo(o.workloadParams);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BenchmarkListEntry record = (BenchmarkListEntry) o;
if (mode != record.mode) return false;
if (workloadParams != null ? !workloadParams.equals(record.workloadParams) : record.workloadParams != null) return false;
if (userClassQName != null ? !userClassQName.equals(record.userClassQName) : record.userClassQName != null) return false;
if (method != null ? !method.equals(record.method) : record.method != null) return false;
return true;
}
@Override
public int hashCode() {
int result = userClassQName != null ? userClassQName.hashCode() : 0;
result = 31 * result + (method != null ? method.hashCode() : 0);
result = 31 * result + (mode != null ? mode.hashCode() : 0);
result = 31 * result + (workloadParams != null ? workloadParams.hashCode() : 0);
return result;
}
public String generatedTarget() {
return generatedClassQName + "." + method + "_" + mode;
}
public String getUsername() {
return userClassQName + "." + method;
}
public String getUserClassQName() {
return userClassQName;
}
public Mode getMode() {
return mode;
}
public int[] getThreadGroups() {
return Arrays.copyOf(threadGroups, threadGroups.length);
}
@Override
public String toString() {
return "{\'" + userClassQName + "." + method + "\', " + mode + ", " + workloadParams + "}";
}
public Optional getWarmupTime() {
return warmupTime;
}
public Optional getWarmupIterations() {
return warmupIterations;
}
public Optional getWarmupBatchSize() {
return warmupBatchSize;
}
public Optional getMeasurementTime() {
return measurementTime;
}
public Optional getMeasurementIterations() {
return measurementIterations;
}
public Optional getMeasurementBatchSize() {
return measurementBatchSize;
}
public Optional getForks() {
return forks;
}
public Optional getWarmupForks() {
return warmupForks;
}
public Optional getJvm() {
return jvm;
}
public Optional> getJvmArgs() {
return jvmArgs;
}
public Optional> getJvmArgsAppend() {
return jvmArgsAppend;
}
public Optional> getJvmArgsPrepend() {
return jvmArgsPrepend;
}
public Optional getThreads() {
return threads;
}
public Optional> getParams() {
return params;
}
public Optional getTimeUnit() {
return tu;
}
public Optional getOperationsPerInvocation() {
return opsPerInvocation;
}
public Optional getTimeout() {
return timeout;
}
static final Optional.Unmarshaller INTEGER_UNMARSHALLER = new Optional.Unmarshaller() {
@Override
public Integer valueOf(String s) {
return Integer.valueOf(s);
}
};
static final Optional.Unmarshaller TIME_VALUE_UNMARSHALLER = new Optional.Unmarshaller() {
@Override
public TimeValue valueOf(String s) {
return TimeValue.fromString(s);
}
};
static final Optional.Unmarshaller TIMEUNIT_UNMARSHALLER = new Optional.Unmarshaller() {
@Override
public TimeUnit valueOf(String s) {
return TimeUnit.valueOf(s);
}
};
static final Optional.Marshaller TIMEUNIT_MARSHALLER = new Optional.Marshaller() {
@Override
public String valueOf(TimeUnit val) {
return val.toString();
}
};
static final Optional.Unmarshaller STRING_UNMARSHALLER = new Optional.Unmarshaller() {
@Override
public String valueOf(String s) {
return s;
}
};
static final Optional.Marshaller STRING_MARSHALLER = new Optional.Marshaller() {
@Override
public String valueOf(String s) {
return s;
}
};
static final Optional.Unmarshaller> STRING_COLLECTION_UNMARSHALLER = new Optional.Unmarshaller>() {
@Override
public Collection valueOf(String s) {
return Arrays.asList(s.split("===SEP==="));
}
};
static final Optional.Marshaller> STRING_COLLECTION_MARSHALLER = new Optional.Marshaller>() {
@Override
public String valueOf(Collection src) {
StringBuilder sb = new StringBuilder();
for (String s : src) {
sb.append(s).append("===SEP===");
}
return sb.toString();
}
};
static final Optional.Unmarshaller> PARAM_COLLECTION_UNMARSHALLER = new Optional.Unmarshaller>() {
@Override
public Map valueOf(String s) {
Map map = new TreeMap();
String[] pairs = s.split("===PAIR-SEP===");
for (String pair : pairs) {
String[] kv = pair.split("===SEP-K===");
if (kv[1].equalsIgnoreCase("===EMPTY===")) {
map.put(kv[0], new String[0]);
} else {
String[] vals = kv[1].split("===SEP-V===");
for (int c = 0; c < vals.length; c++) {
if (vals[c].equals("===EMPTY-VAL===")) {
vals[c] = "";
}
}
map.put(kv[0], vals);
}
}
return map;
}
};
static final Optional.Marshaller> PARAM_COLLECTION_MARSHALLER = new Optional.Marshaller>() {
@Override
public String valueOf(Map src) {
StringBuilder sb = new StringBuilder();
for (Map.Entry e : src.entrySet()) {
sb.append(e.getKey());
sb.append("===SEP-K===");
if (e.getValue().length == 0) {
sb.append("===EMPTY===");
} else {
for (String v : e.getValue()) {
if (v.isEmpty()) {
sb.append("===EMPTY-VAL===");
} else {
sb.append(v);
}
sb.append("===SEP-V===");
}
}
sb.append("===PAIR-SEP===");
}
return sb.toString();
}
};
}