Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: components/cronet/android/test/javaperftests/src/org/chromium/net/CronetPerfTestActivity.java

Issue 1536433002: [Cronet] Get Cronet performance test running again (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: branch off telemetry change Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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")} ));
198 }
199
200 try {
201 JSONObject quicParams = new JSONObject().put("host_whitelist", h ost);
mef 2016/01/22 16:21:57 nice touch!
pauljensen 2016/01/25 02:47:48 Acknowledged.
202 JSONObject experimentalOptions = new JSONObject().put("QUIC", qu icParams);
203 cronetEngineBuilder.setExperimentalOptions(experimentalOptions.t oString());
204 } catch (JSONException e) {
205 throw new IllegalStateException("JSON failed: " + e);
186 } 206 }
187 mCronetEngine = cronetEngineBuilder.build(); 207 mCronetEngine = cronetEngineBuilder.build();
208 long urlRequestContextAdapter =
209 ((CronetUrlRequestContext) mCronetEngine).getUrlRequestConte xtAdapter();
210 CronetTestUtil.registerHostResolverProc(
mef 2016/01/22 16:21:57 Can we change CronetTestUtil.registerHostResolverP
pauljensen 2016/01/25 02:47:47 Done.
211 urlRequestContextAdapter, false, getConfigString("HOST_IP")) ;
188 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations); 212 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations);
189 mConcurrency = concurrency; 213 mConcurrency = concurrency;
190 mResults = results; 214 mResults = results;
191 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE") 215 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE")
192 ? getConfigInt("MAX_BUFFER_SIZE") 216 ? getConfigInt("MAX_BUFFER_SIZE")
193 : mLength; 217 : mLength;
194 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D"); 218 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D");
195 } 219 }
196 220
197 private void startTimer() { 221 private void startTimer() {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 400 }
377 401
378 public void rewind(UploadDataSink uploadDataSink) { 402 public void rewind(UploadDataSink uploadDataSink) {
379 uploadDataSink.onRewindError(new Exception("no rewinding")); 403 uploadDataSink.onRewindError(new Exception("no rewinding"));
380 } 404 }
381 } 405 }
382 406
383 private class Callback extends UrlRequest.Callback { 407 private class Callback extends UrlRequest.Callback {
384 private final ByteBuffer mBuffer; 408 private final ByteBuffer mBuffer;
385 private final Runnable mCompletionCallback; 409 private final Runnable mCompletionCallback;
410 private int mBytesReceived;
386 411
387 Callback(ByteBuffer buffer, Runnable completionCallback) { 412 Callback(ByteBuffer buffer, Runnable completionCallback) {
388 mBuffer = buffer; 413 mBuffer = buffer;
389 mCompletionCallback = completionCallback; 414 mCompletionCallback = completionCallback;
390 } 415 }
391 416
392 @Override 417 @Override
393 public void onResponseStarted(UrlRequest request, UrlResponseInf o info) { 418 public void onResponseStarted(UrlRequest request, UrlResponseInf o info) {
394 mBuffer.clear(); 419 mBuffer.clear();
395 request.readNew(mBuffer); 420 request.readNew(mBuffer);
396 } 421 }
397 422
398 @Override 423 @Override
399 public void onRedirectReceived( 424 public void onRedirectReceived(
400 UrlRequest request, UrlResponseInfo info, String newLoca tionUrl) { 425 UrlRequest request, UrlResponseInfo info, String newLoca tionUrl) {
401 request.followRedirect(); 426 request.followRedirect();
402 } 427 }
403 428
404 @Override 429 @Override
405 public void onReadCompleted( 430 public void onReadCompleted(
406 UrlRequest request, UrlResponseInfo info, ByteBuffer byt eBuffer) { 431 UrlRequest request, UrlResponseInfo info, ByteBuffer byt eBuffer) {
432 mBytesReceived += byteBuffer.position();
407 mBuffer.clear(); 433 mBuffer.clear();
408 request.readNew(mBuffer); 434 request.readNew(mBuffer);
409 } 435 }
410 436
411 @Override 437 @Override
412 public void onSucceeded(UrlRequest request, UrlResponseInfo info ) { 438 public void onSucceeded(UrlRequest request, UrlResponseInfo info ) {
439 if (info.getHttpStatusCode() != 200 || mBytesReceived != mLe ngth) {
440 System.out.println("Failed: response code: " + info.getH ttpStatusCode()
441 + " bytes: " + mBytesReceived);
442 mFailed = true;
443 }
413 mCompletionCallback.run(); 444 mCompletionCallback.run();
414 } 445 }
415 446
416 @Override 447 @Override
417 public void onFailed( 448 public void onFailed(
418 UrlRequest request, UrlResponseInfo info, UrlRequestExce ption e) { 449 UrlRequest request, UrlResponseInfo info, UrlRequestExce ption e) {
419 System.out.println("Async request failed with " + e); 450 System.out.println("Async request failed with " + e);
420 mFailed = true; 451 mFailed = true;
421 } 452 }
422 } 453 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 606 }
576 } 607 }
577 finish(); 608 finish();
578 return null; 609 return null;
579 } 610 }
580 } 611 }
581 612
582 @Override 613 @Override
583 public void onCreate(Bundle savedInstanceState) { 614 public void onCreate(Bundle savedInstanceState) {
584 super.onCreate(savedInstanceState); 615 super.onCreate(savedInstanceState);
616 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, t his);
585 mConfig = getIntent().getData(); 617 mConfig = getIntent().getData();
586 // Execute benchmarks on another thread to avoid networking on main thre ad. 618 // Execute benchmarks on another thread to avoid networking on main thre ad.
587 new BenchmarkTask().execute(); 619 new BenchmarkTask().execute();
588 } 620 }
589 } 621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698