1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.net;
18
19import android.net.NetworkStats;
20import android.os.SystemClock;
21import com.google.caliper.AfterExperiment;
22import com.google.caliper.BeforeExperiment;
23import java.io.File;
24
25public class NetworkStatsFactoryBenchmark {
26    private File mStats;
27
28    // TODO: consider staging stats file with different number of rows
29
30    @BeforeExperiment
31    protected void setUp() {
32        mStats = new File("/proc/net/xt_qtaguid/stats");
33    }
34
35    @AfterExperiment
36    protected void tearDown() {
37        mStats = null;
38    }
39
40    public void timeReadNetworkStatsDetailJava(int reps) throws Exception {
41        for (int i = 0; i < reps; i++) {
42            NetworkStatsFactory.javaReadNetworkStatsDetail(mStats, NetworkStats.UID_ALL,
43                    // Looks like this was broken by change d0c5b9abed60b7bc056d026bf0f2b2235410fb70
44                    // Fixed compilation problem but needs addressing properly.
45                    new String[0], 999);
46        }
47    }
48
49    public void timeReadNetworkStatsDetailNative(int reps) {
50        for (int i = 0; i < reps; i++) {
51            final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 0);
52            NetworkStatsFactory.nativeReadNetworkStatsDetail(
53                    stats, mStats.getAbsolutePath(), NetworkStats.UID_ALL,
54                    // Looks like this was broken by change d0c5b9abed60b7bc056d026bf0f2b2235410fb70
55                    // Fixed compilation problem but needs addressing properly.
56                    new String[0], 999);
57        }
58    }
59}
60