-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Caliper benchmarks for running on Android devices (#10). #278
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cddedc7
Implement Caliper benchmarks for running on Android devices (#10).
85e095d
Fix comments and lint errors.
dd9c9f9
Include windows 32-bit build in uber jar. (#275)
9d26fbe
Implement Caliper benchmarks for running on Android devices (#10).
c080c65
Merge branch 'master' into benchmarks
flooey 18d9429
Remove benchmark-caliper again and switch EngineType to an interface.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ bin | |
|
||
# Vim | ||
.*.sw[nop] | ||
|
||
# Vogar benchmarks | ||
vogar-results/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath libraries.android_tools | ||
} | ||
} | ||
|
||
description = 'Conscrypt: Android Benchmarks' | ||
|
||
ext { | ||
androidHome = "$System.env.ANDROID_HOME" | ||
androidSdkInstalled = file("$androidHome").exists() | ||
androidVersionCode = 1 | ||
androidVersionName = "$version" | ||
androidMinSdkVersion = 24 | ||
androidTargetSdkVersion = 25 | ||
androidBuildToolsVersion = "25.0.0" | ||
androidBuildToolsDir = "${androidHome}/build-tools/${androidBuildToolsVersion}" | ||
} | ||
|
||
if (androidSdkInstalled) { | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion androidTargetSdkVersion | ||
buildToolsVersion androidBuildToolsVersion | ||
|
||
compileOptions { | ||
sourceCompatibility androidMinJavaVersion; | ||
targetCompatibility androidMinJavaVersion | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion androidMinSdkVersion | ||
targetSdkVersion androidTargetSdkVersion | ||
versionCode androidVersionCode | ||
versionName androidVersionName | ||
} | ||
lintOptions { | ||
// Some Caliper classes reference packages that don't exist on Android | ||
disable 'InvalidPackage' | ||
} | ||
sourceSets.main { | ||
java { | ||
srcDirs = [ | ||
"${rootDir}/benchmark-base/src/main/java", | ||
"src/main/java" | ||
] | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':conscrypt-android'), | ||
project(':conscrypt-testing') | ||
|
||
compile 'com.google.caliper:caliper:1.0-beta-2' | ||
compile libraries.bouncycastle_provider | ||
|
||
} | ||
|
||
// This task bundles up everything we're going to send to the device into a single jar. | ||
// We need to include all the Conscrypt code plus the Bouncy Castle jar because the platform | ||
// version of Bouncy Castle is jarjared. | ||
task depsJar(type: Jar, dependsOn: 'assembleRelease') { | ||
archiveName = 'bundled-deps.jar' | ||
from { | ||
configurations.compile.filter { | ||
// Find the jars from our project plus BC | ||
it.name.endsWith(".jar") && (it.path.startsWith("${rootDir}") || it.path.contains('org.bouncycastle')) | ||
}.collect { | ||
zipTree(it) | ||
} | ||
} | ||
from { | ||
// Also include the classes.jar from our Android libraries | ||
['.', "${rootDir}/android"].collect { | ||
zipTree(it + '/build/intermediates/bundles/default/classes.jar') | ||
} | ||
} | ||
// Bouncy Castle signs their jar, which causes our combined jar to fail to verify. Just | ||
// strip out the signature files. | ||
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA" | ||
} | ||
|
||
task runBenchmarks(dependsOn: depsJar) { | ||
doLast { | ||
// First, determine which ABI the device uses so that we can send the right native lib | ||
new ByteArrayOutputStream().withStream { stream -> | ||
exec { | ||
commandLine = ['adb', 'shell', 'getprop', 'ro.product.cpu.abi'] | ||
standardOutput = stream | ||
} | ||
ext.androidDeviceAbi = stream.toString().trim() | ||
ext.androidDevice64Bit = ext.androidDeviceAbi.contains('64') | ||
} | ||
def nativeLibPath = "/system/lib${androidDevice64Bit ? '64' : ''}/libconscrypt_jni.so" | ||
// Send the native library to the device | ||
exec { | ||
executable "${androidHome}/platform-tools/adb" | ||
args 'push' | ||
args "${rootDir}/android/build/intermediates/bundles/default/jni/${androidDeviceAbi}/libconscrypt_jni.so" | ||
args nativeLibPath | ||
} | ||
// Execute the benchmarks | ||
exec { | ||
workingDir "${rootDir}" | ||
environment PATH: "${androidBuildToolsDir}:$System.env.PATH" | ||
environment JACK_JAR: "${androidBuildToolsDir}/jack.jar" | ||
|
||
executable 'java' | ||
args '-cp', 'benchmark-android/vogar.jar', 'vogar.Vogar' | ||
args '--classpath', 'benchmark-android/build/libs/bundled-deps.jar' | ||
args '--benchmark' | ||
args '--language=JN' | ||
args '--mode=app_process' | ||
args 'org.conscrypt.CaliperAlpnBenchmark' | ||
args 'org.conscrypt.CaliperEngineHandshakeBenchmark' | ||
args 'org.conscrypt.CaliperEngineWrapBenchmark' | ||
} | ||
// Clean up the native library | ||
exec { | ||
commandLine = ['adb', 'shell', 'rm', '-f', nativeLibPath] | ||
} | ||
} | ||
} | ||
} else { | ||
logger.warn('Android SDK has not been detected. The Android Benchmark module will not be built.') | ||
|
||
// Disable all tasks | ||
tasks.collect { | ||
it.enabled = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.conscrypt.benchmarks.android"> | ||
|
||
<application/> | ||
|
||
</manifest> |
84 changes: 84 additions & 0 deletions
84
benchmark-android/src/main/java/org/conscrypt/AndroidEngineType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2017 The Android Open Source Project | ||
* | ||
* Licensed 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 org.conscrypt; | ||
|
||
import static org.conscrypt.TestUtils.PROTOCOL_TLS_V1_2; | ||
import static org.conscrypt.TestUtils.initClientSslContext; | ||
import static org.conscrypt.TestUtils.initEngine; | ||
import static org.conscrypt.TestUtils.initServerSslContext; | ||
|
||
import java.security.KeyStore.PrivateKeyEntry; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.cert.X509Certificate; | ||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.SSLException; | ||
import libcore.java.security.TestKeyStore; | ||
|
||
/** | ||
* Enumeration of various types of engines for use with engine-based benchmarks. | ||
*/ | ||
@SuppressWarnings({"ImmutableEnumChecker", "unused"}) | ||
public enum AndroidEngineType implements EngineType { | ||
CONSCRYPT_UNPOOLED { | ||
private final SSLContext clientContext = newConscryptClientContext(); | ||
private final SSLContext serverContext = newConscryptServerContext(); | ||
|
||
@Override | ||
public SSLEngine newClientEngine(String cipher, boolean useAlpn) { | ||
SSLEngine engine = initEngine(clientContext.createSSLEngine(), cipher, true); | ||
if (useAlpn) { | ||
Conscrypt.Engines.setAlpnProtocols( | ||
engine, new String[] {"h2"}); | ||
} | ||
return engine; | ||
} | ||
|
||
@Override | ||
public SSLEngine newServerEngine(String cipher, boolean useAlpn) { | ||
SSLEngine engine = initEngine(serverContext.createSSLEngine(), cipher, false); | ||
if (useAlpn) { | ||
Conscrypt.Engines.setAlpnProtocols( | ||
engine, new String[] {"h2"}); | ||
} | ||
return engine; | ||
} | ||
|
||
private SSLContext newContext() { | ||
try { | ||
return SSLContext.getInstance(PROTOCOL_TLS_V1_2, new OpenSSLProvider()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose(SSLEngine engine) { | ||
engine.closeOutbound(); | ||
} | ||
}; | ||
|
||
@Override | ||
public void dispose(SSLEngine engine) {} | ||
|
||
private static SSLContext newConscryptClientContext() { | ||
return TestUtils.newClientSslContext(TestUtils.getConscryptProvider()); | ||
} | ||
|
||
private static SSLContext newConscryptServerContext() { | ||
return TestUtils.newServerSslContext(TestUtils.getConscryptProvider()); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
benchmark-android/src/main/java/org/conscrypt/CaliperAlpnBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2017 The Android Open Source Project | ||
* | ||
* Licensed 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 org.conscrypt; | ||
|
||
import com.google.caliper.BeforeExperiment; | ||
import com.google.caliper.Param; | ||
import org.conscrypt.EngineHandshakeBenchmark.Config; | ||
|
||
/** | ||
* Cipher benchmarks. Only runs on AES currently because of the combinatorial | ||
* explosion of the test as it stands. | ||
*/ | ||
public class CaliperAlpnBenchmark { | ||
private final CaliperConfig config = new CaliperConfig(); | ||
|
||
@Param({TestUtils.TEST_CIPHER}) | ||
public String a_cipher; | ||
|
||
@Param | ||
public BufferType b_buffer; | ||
|
||
@Param | ||
public AndroidEngineType c_engine; | ||
|
||
private EngineHandshakeBenchmark benchmark; | ||
|
||
@BeforeExperiment | ||
public void setUp() throws Exception { | ||
benchmark = new EngineHandshakeBenchmark(config); | ||
} | ||
|
||
public void timeHandshake(int reps) throws Exception { | ||
for (int i = 0; i < reps; ++i) { | ||
benchmark.handshake(); | ||
} | ||
} | ||
|
||
private final class CaliperConfig implements Config { | ||
@Override | ||
public BufferType bufferType() { | ||
return b_buffer; | ||
} | ||
|
||
@Override | ||
public EngineType engineType() { | ||
return c_engine; | ||
} | ||
|
||
@Override | ||
public String cipher() { | ||
return a_cipher; | ||
} | ||
|
||
@Override | ||
public boolean useAlpn() { | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just make base a dependency rather than including the source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the benchmark-base subproject, so benchmark-android and benchmark-openjdk both include its source directly. This is the same pattern used with common/, it doesn't get compiled directly but android/ and openjdk/ include its source. It makes it a bit easier because there are circular dependencies between the platform-specific bits and the platform-agnostic bits, so this just lets them get compiled together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok that's fine. FYI the main reason we were including source in common is because we wanted a single resulting jar.