Apply advanced JVM options to benchmarks / Fix duplicate uploads

- Add common optimization options when launching a new JVM to run a benchmark
- Fix a bug where a benchmark report is uploaded twice
- Simplify pom.xml and move the build instruction messages to DefaultBenchmark
- Print an empty line to prettify the output
This commit is contained in:
Trustin Lee 2012-12-14 00:00:41 +09:00
parent ad10518fca
commit 6339feaa8f
3 changed files with 92 additions and 42 deletions

View File

@ -53,45 +53,6 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>upload-caliper-reports</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<if>
<available file="${user.home}/.caliperrc"/>
<then>
<java
classname="com.google.caliper.Runner"
classpathref="maven.test.classpath">
<arg value="--uploadResults"/>
<arg value="${project.build.directory}/caliper-reports"/>
</java>
</then>
<else>
<echo>
No .caliperrc file found; not uploading the benchmark report.
Please follow the instructions at:
* http://code.google.com/p/caliper/wiki/OnlineResults
to upload and browse the benchmark results.
</echo>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,59 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.google.caliper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
final class StandardVm extends Vm {
@Override public List<String> getVmSpecificOptions(MeasurementType type, Arguments arguments) {
if (!arguments.getCaptureVmLog()) {
return ImmutableList.of();
}
List<String> result = Lists.newArrayList(
"-server", "-dsa", "-da", "-ea:io.netty...",
"-Xms768m", "-Xmx768m", "-XX:MaxDirectMemorySize=768m",
"-XX:+AggressiveOpts", "-XX:+UseBiasedLocking", "-XX:+UseFastAccessorMethods",
"-XX:+UseStringCache", "-XX:+OptimizeStringConcat",
"-XX:+HeapDumpOnOutOfMemoryError");
if (type == MeasurementType.TIME) {
Collections.addAll(
result,
"-XX:+PrintCompilation");
} else {
Collections.addAll(
result,
"-verbose:gc",
"-Xbatch",
"-XX:+UseSerialGC",
"-XX:+TieredCompilation");
}
return result;
}
public static String defaultVmName() {
return "java";
}
}

View File

@ -16,6 +16,7 @@
package io.netty.microbench.util;
import com.google.caliper.CaliperRc;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import org.junit.Test;
@ -26,6 +27,8 @@ import static org.junit.Assert.*;
public abstract class DefaultBenchmark extends SimpleBenchmark {
private static boolean warned;
private final int trials;
private final int warmupMillis;
private final int runMillis;
@ -72,27 +75,54 @@ public abstract class DefaultBenchmark extends SimpleBenchmark {
fail("not a directory: " + reportDir.getAbsolutePath());
}
deleteOldReports(reportDir);
boolean deleted = deleteOldReports(reportDir);
if (!warned) {
CaliperRc caliperrc = CaliperRc.INSTANCE;
if (caliperrc.getApiKey() == null || caliperrc.getPostUrl() == null) {
warned = true;
System.out.println();
System.out.println(" Cannot read the configuration properties from .caliperrc.");
System.out.println(" Please follow the instructions at:");
System.out.println();
System.out.println(" * http://code.google.com/p/caliper/wiki/OnlineResults");
System.out.println();
System.out.println(" to upload and browse the benchmark results.");
}
}
if (deleted || warned) {
// Insert a pretty newline.
System.out.println();
}
new Runner().run(
"--trials", String.valueOf(trials),
"--warmupMillis", String.valueOf(warmupMillis),
"--runMillis", String.valueOf(runMillis),
"--captureVmLog",
"--saveResults", reportDir.getAbsolutePath(),
"--captureVmLog",
getClass().getName());
}
private void deleteOldReports(File reportDir) {
private boolean deleteOldReports(File reportDir) {
final String prefix = getClass().getName() + '.';
final String suffix = ".json";
boolean deleted = false;
for (File f: reportDir.listFiles()) {
String name = f.getName();
if (name.startsWith(prefix) && name.endsWith(suffix)) {
if (f.delete()) {
if (!deleted) {
deleted = true;
System.out.println();
}
System.out.println(" Deleted old report: " + name.substring(prefix.length(), name.length() - suffix.length()));
}
}
}
return deleted;
}
}