Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.net.Uri; | 9 import android.net.Uri; |
| 10 import android.os.AsyncTask; | 10 import android.os.AsyncTask; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.os.Debug; | 12 import android.os.Debug; |
| 13 | 13 |
| 14 import org.chromium.base.PathUtils; | |
| 15 | |
| 14 import org.json.JSONException; | 16 import org.json.JSONException; |
| 15 import org.json.JSONObject; | 17 import org.json.JSONObject; |
| 16 | 18 |
| 17 import java.io.File; | 19 import java.io.File; |
| 18 import java.io.FileOutputStream; | 20 import java.io.FileOutputStream; |
| 19 import java.io.IOException; | 21 import java.io.IOException; |
| 20 import java.io.InputStream; | 22 import java.io.InputStream; |
| 21 import java.io.OutputStream; | 23 import java.io.OutputStream; |
| 22 import java.net.HttpURLConnection; | 24 import java.net.HttpURLConnection; |
| 23 import java.net.MalformedURLException; | 25 import java.net.MalformedURLException; |
| 24 import java.net.URL; | 26 import java.net.URL; |
| 25 import java.net.URLConnection; | 27 import java.net.URLConnection; |
| 26 import java.nio.ByteBuffer; | 28 import java.nio.ByteBuffer; |
| 27 import java.util.ArrayList; | 29 import java.util.ArrayList; |
| 28 import java.util.List; | 30 import java.util.List; |
| 29 import java.util.concurrent.Callable; | 31 import java.util.concurrent.Callable; |
| 30 import java.util.concurrent.Executor; | 32 import java.util.concurrent.Executor; |
| 31 import java.util.concurrent.ExecutorService; | 33 import java.util.concurrent.ExecutorService; |
| 32 import java.util.concurrent.Executors; | 34 import java.util.concurrent.Executors; |
| 33 import java.util.concurrent.Future; | 35 import java.util.concurrent.Future; |
| 34 import java.util.concurrent.LinkedBlockingQueue; | 36 import java.util.concurrent.LinkedBlockingQueue; |
| 35 import java.util.concurrent.TimeUnit; | 37 import java.util.concurrent.TimeUnit; |
| 36 | 38 |
| 37 /** | 39 /** |
| 38 * Runs networking benchmarks and saves results to a file. | 40 * Runs networking benchmarks and saves results to a file. |
| 39 */ | 41 */ |
| 40 public class CronetPerfTestActivity extends Activity { | 42 public class CronetPerfTestActivity extends Activity { |
| 43 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cronet_perf_tes t"; | |
| 41 // Benchmark configuration passed down from host via Intent data. | 44 // Benchmark configuration passed down from host via Intent data. |
| 42 // Call getConfig*(key) to extract individual configuration values. | 45 // Call getConfig*(key) to extract individual configuration values. |
| 43 private Uri mConfig; | 46 private Uri mConfig; |
| 44 // Functions that retrieve individual benchmark configuration values. | 47 // Functions that retrieve individual benchmark configuration values. |
| 45 private String getConfigString(String key) { | 48 private String getConfigString(String key) { |
| 46 return mConfig.getQueryParameter(key); | 49 return mConfig.getQueryParameter(key); |
| 47 } | 50 } |
| 48 private int getConfigInt(String key) { | 51 private int getConfigInt(String key) { |
| 49 return Integer.parseInt(mConfig.getQueryParameter(key)); | 52 return Integer.parseInt(mConfig.getQueryParameter(key)); |
| 50 } | 53 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 // When measuring a large upload, only download a small amou nt so download time | 156 // When measuring a large upload, only download a small amou nt so download time |
| 154 // isn't significant. | 157 // isn't significant. |
| 155 resource = getConfigString( | 158 resource = getConfigString( |
| 156 direction == Direction.UP ? "SMALL_RESOURCE" : "LARG E_RESOURCE"); | 159 direction == Direction.UP ? "SMALL_RESOURCE" : "LARG E_RESOURCE"); |
| 157 mIterations = getConfigInt("LARGE_ITERATIONS"); | 160 mIterations = getConfigInt("LARGE_ITERATIONS"); |
| 158 mLength = getConfigInt("LARGE_RESOURCE_SIZE"); | 161 mLength = getConfigInt("LARGE_RESOURCE_SIZE"); |
| 159 break; | 162 break; |
| 160 default: | 163 default: |
| 161 throw new IllegalArgumentException("Unknown size: " + size); | 164 throw new IllegalArgumentException("Unknown size: " + size); |
| 162 } | 165 } |
| 166 final String scheme; | |
| 167 final String host; | |
| 163 final int port; | 168 final int port; |
| 164 switch (protocol) { | 169 switch (protocol) { |
| 165 case HTTP: | 170 case HTTP: |
| 171 scheme = "http"; | |
| 172 host = getConfigString("HOST_IP"); | |
| 166 port = getConfigInt("HTTP_PORT"); | 173 port = getConfigInt("HTTP_PORT"); |
| 167 break; | 174 break; |
| 168 case QUIC: | 175 case QUIC: |
| 176 scheme = "https"; | |
| 177 host = getConfigString("HOST"); | |
| 169 port = getConfigInt("QUIC_PORT"); | 178 port = getConfigInt("QUIC_PORT"); |
| 170 break; | 179 break; |
| 171 default: | 180 default: |
| 172 throw new IllegalArgumentException("Unknown protocol: " + pr otocol); | 181 throw new IllegalArgumentException("Unknown protocol: " + pr otocol); |
| 173 } | 182 } |
| 174 try { | 183 try { |
| 175 mUrl = new URL("http", getConfigString("HOST"), port, resource); | 184 mUrl = new URL(scheme, host, port, resource); |
| 176 } catch (MalformedURLException e) { | 185 } catch (MalformedURLException e) { |
| 177 throw new IllegalArgumentException("Bad URL: " + getConfigString ("HOST") + ":" | 186 throw new IllegalArgumentException( |
| 178 + port + "/" + resource); | 187 "Bad URL: " + host + ":" + port + "/" + resource); |
| 179 } | 188 } |
| 180 final CronetEngine.Builder cronetEngineBuilder = | 189 final CronetEngine.Builder cronetEngineBuilder = |
| 181 new CronetEngine.Builder(CronetPerfTestActivity.this); | 190 new CronetEngine.Builder(CronetPerfTestActivity.this); |
| 191 cronetEngineBuilder.setLibraryName("cronet_tests"); | |
| 182 if (mProtocol == Protocol.QUIC) { | 192 if (mProtocol == Protocol.QUIC) { |
| 183 cronetEngineBuilder.enableQUIC(true); | 193 cronetEngineBuilder.enableQUIC(true); |
| 184 cronetEngineBuilder.addQuicHint(getConfigString("HOST"), getConf igInt("QUIC_PORT"), | 194 cronetEngineBuilder.addQuicHint(host, port, port); |
| 185 getConfigInt("QUIC_PORT")); | 195 cronetEngineBuilder.setMockCertVerifierForTesting( |
| 196 MockCertVerifier.createMockCertVerifier( | |
| 197 new String[] {getConfigString("QUIC_CERT_FILE")} )); | |
| 186 } | 198 } |
| 187 mCronetEngine = cronetEngineBuilder.build(); | 199 mCronetEngine = cronetEngineBuilder.build(); |
| 200 long urlRequestContextAdapter = | |
| 201 ((CronetUrlRequestContext) mCronetEngine).getUrlRequestConte xtAdapter(); | |
| 202 NativeTestServer.registerHostResolverProc( | |
|
mef
2015/12/29 17:27:45
registerHostResolverProc doesn't really have anyth
pauljensen
2016/01/21 03:51:50
Done.
| |
| 203 urlRequestContextAdapter, false, getConfigString("HOST_IP")) ; | |
| 188 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations); | 204 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations); |
| 189 mConcurrency = concurrency; | 205 mConcurrency = concurrency; |
| 190 mResults = results; | 206 mResults = results; |
| 191 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE") | 207 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE") |
| 192 ? getConfigInt("MAX_BUFFER_SIZE") | 208 ? getConfigInt("MAX_BUFFER_SIZE") |
| 193 : mLength; | 209 : mLength; |
| 194 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D"); | 210 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D"); |
| 195 } | 211 } |
| 196 | 212 |
| 197 private void startTimer() { | 213 private void startTimer() { |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 } | 591 } |
| 576 } | 592 } |
| 577 finish(); | 593 finish(); |
| 578 return null; | 594 return null; |
| 579 } | 595 } |
| 580 } | 596 } |
| 581 | 597 |
| 582 @Override | 598 @Override |
| 583 public void onCreate(Bundle savedInstanceState) { | 599 public void onCreate(Bundle savedInstanceState) { |
| 584 super.onCreate(savedInstanceState); | 600 super.onCreate(savedInstanceState); |
| 601 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, t his); | |
| 585 mConfig = getIntent().getData(); | 602 mConfig = getIntent().getData(); |
| 586 // Execute benchmarks on another thread to avoid networking on main thre ad. | 603 // Execute benchmarks on another thread to avoid networking on main thre ad. |
| 587 new BenchmarkTask().execute(); | 604 new BenchmarkTask().execute(); |
| 588 } | 605 } |
| 589 } | 606 } |
| OLD | NEW |