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; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 return name; | 104 return name; |
105 } | 105 } |
106 | 106 |
107 // Responsible for running one particular benchmark and timing it. | 107 // Responsible for running one particular benchmark and timing it. |
108 private class Benchmark { | 108 private class Benchmark { |
109 private final Mode mMode; | 109 private final Mode mMode; |
110 private final Direction mDirection; | 110 private final Direction mDirection; |
111 private final Protocol mProtocol; | 111 private final Protocol mProtocol; |
112 private final URL mUrl; | 112 private final URL mUrl; |
113 private final String mName; | 113 private final String mName; |
114 private final UrlRequestContext mCronetContext; | 114 private final CronetEngine mCronetEngine; |
115 // Size in bytes of content being uploaded or downloaded. | 115 // Size in bytes of content being uploaded or downloaded. |
116 private final int mLength; | 116 private final int mLength; |
117 // How many requests to execute. | 117 // How many requests to execute. |
118 private final int mIterations; | 118 private final int mIterations; |
119 // How many requests to execute in parallel at any one time. | 119 // How many requests to execute in parallel at any one time. |
120 private final int mConcurrency; | 120 private final int mConcurrency; |
121 // Dictionary of benchmark names mapped to times to complete the benchma rks. | 121 // Dictionary of benchmark names mapped to times to complete the benchma rks. |
122 private final JSONObject mResults; | 122 private final JSONObject mResults; |
123 // How large a buffer to use for passing content, in bytes. | 123 // How large a buffer to use for passing content, in bytes. |
124 private final int mBufferSize; | 124 private final int mBufferSize; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 break; | 171 break; |
172 default: | 172 default: |
173 throw new IllegalArgumentException("Unknown protocol: " + pr otocol); | 173 throw new IllegalArgumentException("Unknown protocol: " + pr otocol); |
174 } | 174 } |
175 try { | 175 try { |
176 mUrl = new URL("http", getConfigString("HOST"), port, resource); | 176 mUrl = new URL("http", getConfigString("HOST"), port, resource); |
177 } catch (MalformedURLException e) { | 177 } catch (MalformedURLException e) { |
178 throw new IllegalArgumentException("Bad URL: " + getConfigString ("HOST") + ":" | 178 throw new IllegalArgumentException("Bad URL: " + getConfigString ("HOST") + ":" |
179 + port + "/" + resource); | 179 + port + "/" + resource); |
180 } | 180 } |
181 final UrlRequestContextConfig cronetConfig = new UrlRequestContextCo nfig(); | 181 final CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Bu ilder(); |
182 if (mProtocol == Protocol.QUIC) { | 182 if (mProtocol == Protocol.QUIC) { |
183 cronetConfig.enableQUIC(true); | 183 cronetEngineBuilder.enableQUIC(true); |
184 cronetConfig.addQuicHint(getConfigString("HOST"), getConfigInt(" QUIC_PORT"), | 184 cronetEngineBuilder.addQuicHint(getConfigString("HOST"), getConf igInt("QUIC_PORT"), |
185 getConfigInt("QUIC_PORT")); | 185 getConfigInt("QUIC_PORT")); |
186 } | 186 } |
187 mCronetContext = new CronetUrlRequestContext(CronetPerfTestActivity. this, cronetConfig); | 187 mCronetEngine = cronetEngineBuilder.build(CronetPerfTestActivity.thi s); |
188 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations); | 188 mName = buildBenchmarkName(mode, direction, protocol, concurrency, m Iterations); |
189 mConcurrency = concurrency; | 189 mConcurrency = concurrency; |
190 mResults = results; | 190 mResults = results; |
191 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE") | 191 mBufferSize = mLength > getConfigInt("MAX_BUFFER_SIZE") |
192 ? getConfigInt("MAX_BUFFER_SIZE") | 192 ? getConfigInt("MAX_BUFFER_SIZE") |
193 : mLength; | 193 : mLength; |
194 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D"); | 194 mUseNetworkThread = getConfigBoolean("CRONET_ASYNC_USE_NETWORK_THREA D"); |
195 } | 195 } |
196 | 196 |
197 private void startTimer() { | 197 private void startTimer() { |
(...skipping 11 matching lines...) Expand all Loading... | |
209 mResults.put(mName, mStopTimeMs - mStartTimeMs); | 209 mResults.put(mName, mStopTimeMs - mStartTimeMs); |
210 } catch (JSONException e) { | 210 } catch (JSONException e) { |
211 System.out.println("Failed to write JSON result for " + mName); | 211 System.out.println("Failed to write JSON result for " + mName); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 // TODO(pauljensen): Remove @SuppressLint once crbug.com/501591 is fixed . | 215 // TODO(pauljensen): Remove @SuppressLint once crbug.com/501591 is fixed . |
216 @SuppressLint("NewApi") | 216 @SuppressLint("NewApi") |
217 private void startLogging() { | 217 private void startLogging() { |
218 if (getConfigBoolean("CAPTURE_NETLOG")) { | 218 if (getConfigBoolean("CAPTURE_NETLOG")) { |
219 mCronetContext.startNetLogToFile(getFilesDir().getPath() + "/" + mName + ".json", | 219 mCronetEngine.startNetLogToFile( |
220 false); | 220 getFilesDir().getPath() + "/" + mName + ".json", false); |
221 } | 221 } |
222 if (getConfigBoolean("CAPTURE_TRACE")) { | 222 if (getConfigBoolean("CAPTURE_TRACE")) { |
223 Debug.startMethodTracing(getFilesDir().getPath() + "/" + mName + ".trace"); | 223 Debug.startMethodTracing(getFilesDir().getPath() + "/" + mName + ".trace"); |
224 } else if (getConfigBoolean("CAPTURE_SAMPLED_TRACE")) { | 224 } else if (getConfigBoolean("CAPTURE_SAMPLED_TRACE")) { |
225 Debug.startMethodTracingSampling( | 225 Debug.startMethodTracingSampling( |
226 getFilesDir().getPath() + "/" + mName + ".trace", 800000 0, 10); | 226 getFilesDir().getPath() + "/" + mName + ".trace", 800000 0, 10); |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 private void stopLogging() { | 230 private void stopLogging() { |
231 if (getConfigBoolean("CAPTURE_NETLOG")) { | 231 if (getConfigBoolean("CAPTURE_NETLOG")) { |
232 mCronetContext.stopNetLog(); | 232 mCronetEngine.stopNetLog(); |
233 } | 233 } |
234 if (getConfigBoolean("CAPTURE_TRACE") || getConfigBoolean("CAPTURE_S AMPLED_TRACE")) { | 234 if (getConfigBoolean("CAPTURE_TRACE") || getConfigBoolean("CAPTURE_S AMPLED_TRACE")) { |
235 Debug.stopMethodTracing(); | 235 Debug.stopMethodTracing(); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 /** | 239 /** |
240 * Transfer {@code mLength} bytes through HttpURLConnection in {@code mD irection} direction. | 240 * Transfer {@code mLength} bytes through HttpURLConnection in {@code mD irection} direction. |
241 * @param connection The HttpURLConnection to use for transfer. | 241 * @param connection The HttpURLConnection to use for transfer. |
242 * @param buffer A buffer of length |mBufferSize| to use for transfer. | 242 * @param buffer A buffer of length |mBufferSize| to use for transfer. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 }); | 336 }); |
337 } | 337 } |
338 return; | 338 return; |
339 } | 339 } |
340 mRemainingRequests--; | 340 mRemainingRequests--; |
341 final Runnable completionCallback = new Runnable() { | 341 final Runnable completionCallback = new Runnable() { |
342 public void run() { | 342 public void run() { |
343 initiateRequest(buffer); | 343 initiateRequest(buffer); |
344 } | 344 } |
345 }; | 345 }; |
346 final UrlRequest request = mCronetContext.createRequest(mUrl.toS tring(), | 346 final UrlRequest.Builder builder = new UrlRequest.Builder(mUrl.t oString(), |
347 new Listener(buffer, completionCallback), mWorkQueueExec utor); | 347 new Listener(buffer, completionCallback), mWorkQueueExec utor); |
348 if (mDirection == Direction.UP) { | 348 if (mDirection == Direction.UP) { |
349 request.setUploadDataProvider(new Uploader(buffer), mWorkQue ueExecutor); | 349 builder.setUploadDataProvider(new Uploader(buffer), mWorkQue ueExecutor); |
350 request.addHeader("Content-Type", "application/octet-stream" ); | 350 builder.addHeader("Content-Type", "application/octet-stream" ); |
351 } | 351 } |
352 request.start(); | 352 mCronetEngine.executeRequest(builder); |
xunjieli
2015/10/01 19:00:09
need to update tests?
pauljensen
2015/10/01 23:42:59
Done.
| |
353 } | 353 } |
354 | 354 |
355 private class Uploader extends UploadDataProvider { | 355 private class Uploader extends UploadDataProvider { |
356 private final ByteBuffer mBuffer; | 356 private final ByteBuffer mBuffer; |
357 private int mRemainingBytes; | 357 private int mRemainingBytes; |
358 | 358 |
359 Uploader(ByteBuffer buffer) { | 359 Uploader(ByteBuffer buffer) { |
360 mBuffer = buffer; | 360 mBuffer = buffer; |
361 mRemainingBytes = mLength; | 361 mRemainingBytes = mLength; |
362 } | 362 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 startLogging(); | 472 startLogging(); |
473 // Prepare list of tasks to run. | 473 // Prepare list of tasks to run. |
474 switch (mMode) { | 474 switch (mMode) { |
475 case SYSTEM_HUC: | 475 case SYSTEM_HUC: |
476 for (int i = 0; i < mIterations; i++) { | 476 for (int i = 0; i < mIterations; i++) { |
477 tasks.add(new SystemHttpURLConnectionFetchTask()); | 477 tasks.add(new SystemHttpURLConnectionFetchTask()); |
478 } | 478 } |
479 break; | 479 break; |
480 case CRONET_HUC: { | 480 case CRONET_HUC: { |
481 final CronetHttpURLStreamHandler cronetStreamHandler = | 481 final CronetHttpURLStreamHandler cronetStreamHandler = |
482 new CronetHttpURLStreamHandler(mCronetContext); | 482 new CronetHttpURLStreamHandler(mCronetEngine); |
483 for (int i = 0; i < mIterations; i++) { | 483 for (int i = 0; i < mIterations; i++) { |
484 tasks.add(new CronetHttpURLConnectionFetchTask(cronetStr eamHandler)); | 484 tasks.add(new CronetHttpURLConnectionFetchTask(cronetStr eamHandler)); |
485 } | 485 } |
486 break; | 486 break; |
487 } | 487 } |
488 case CRONET_ASYNC: | 488 case CRONET_ASYNC: |
489 tasks.add(new CronetAsyncFetchTask()); | 489 tasks.add(new CronetAsyncFetchTask()); |
490 break; | 490 break; |
491 default: | 491 default: |
492 throw new IllegalArgumentException("Unknown mode: " + mMode) ; | 492 throw new IllegalArgumentException("Unknown mode: " + mMode) ; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 586 } |
587 | 587 |
588 @Override | 588 @Override |
589 public void onCreate(Bundle savedInstanceState) { | 589 public void onCreate(Bundle savedInstanceState) { |
590 super.onCreate(savedInstanceState); | 590 super.onCreate(savedInstanceState); |
591 mConfig = getIntent().getData(); | 591 mConfig = getIntent().getData(); |
592 // Execute benchmarks on another thread to avoid networking on main thre ad. | 592 // Execute benchmarks on another thread to avoid networking on main thre ad. |
593 new BenchmarkTask().execute(); | 593 new BenchmarkTask().execute(); |
594 } | 594 } |
595 } | 595 } |
OLD | NEW |