diff options
author | Wenchao Tong <tongwenchao@google.com> | 2015-03-27 20:43:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-27 20:43:34 +0000 |
commit | 041ca26d028ae314d416cb107721ea7267af6aca (patch) | |
tree | 530ccfa8ca7fc1ac12791ea6e099ec8ba4173c33 /core/tests | |
parent | a2e94c854396b2dc922bd625bfe3f6fbceddf199 (diff) | |
parent | 7ae35a0242abf2091fb226aae19160a46135a5d8 (diff) | |
download | frameworks_base-041ca26d028ae314d416cb107721ea7267af6aca.zip frameworks_base-041ca26d028ae314d416cb107721ea7267af6aca.tar.gz frameworks_base-041ca26d028ae314d416cb107721ea7267af6aca.tar.bz2 |
Merge "Create a Benchmark test for NetworkStats."
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/benchmarks/src/android/net/NetworkStatsBenchmark.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/core/tests/benchmarks/src/android/net/NetworkStatsBenchmark.java b/core/tests/benchmarks/src/android/net/NetworkStatsBenchmark.java new file mode 100644 index 0000000..1a50432 --- /dev/null +++ b/core/tests/benchmarks/src/android/net/NetworkStatsBenchmark.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 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 android.net; + +import com.google.caliper.Param; +import com.google.caliper.SimpleBenchmark; + +public class NetworkStatsBenchmark extends SimpleBenchmark { + private static final String UNDERLYING_IFACE = "wlan0"; + private static final String TUN_IFACE = "tun0"; + private static final int TUN_UID = 999999999; + + @Param({"100", "1000"}) + private int mSize; + private NetworkStats mNetworkStats; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mNetworkStats = new NetworkStats(0, mSize + 2); + int uid = 0; + NetworkStats.Entry recycle = new NetworkStats.Entry(); + for (int i = 0; i < mSize; i++) { + recycle.iface = (i < mSize / 2) ? TUN_IFACE : UNDERLYING_IFACE; + recycle.uid = uid; + recycle.set = i % 2; + recycle.tag = NetworkStats.TAG_NONE; + recycle.rxBytes = 60000; + recycle.rxPackets = 60; + recycle.txBytes = 150000; + recycle.txPackets = 1500; + recycle.operations = 0; + mNetworkStats.addValues(recycle); + if (recycle.set == 1) { + uid++; + } + } + recycle.iface = UNDERLYING_IFACE; + recycle.uid = TUN_UID; + recycle.set = NetworkStats.SET_FOREGROUND; + recycle.tag = NetworkStats.TAG_NONE; + recycle.rxBytes = 90000 * mSize; + recycle.rxPackets = 40 * mSize; + recycle.txBytes = 180000 * mSize; + recycle.txPackets = 1200 * mSize; + recycle.operations = 0; + mNetworkStats.addValues(recycle); + } + + public void timeMigrateTun(int reps) { + for (int i = 0; i < reps; i++) { + NetworkStats stats = mNetworkStats.clone(); + stats.migrateTun(TUN_UID, TUN_IFACE, UNDERLYING_IFACE); + } + } + + /** + * Since timeMigrateTun() includes a clone() call on the NetworkStats object, + * we need to measure the cost of the clone() call itself in order to get more + * accurate measurement on the migrateTun() method. + */ + public void timeClone(int reps) { + for (int i = 0; i < reps; i++) { + NetworkStats stats = mNetworkStats.clone(); + } + } +} |