summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-04-06 19:55:24 -0500
committerJosh Gao2018-05-23 13:26:04 -0500
commitfd3fd937b13dcaaee7275da21084f1ea897fb006 (patch)
treea1f2d94fe4baa42f81a7a7d9aa9efd5d8c22c8ca
parent7c738cdb53061f89605abc8243236a2bd783eeec (diff)
downloadplatform-system-core-fd3fd937b13dcaaee7275da21084f1ea897fb006.tar.gz
platform-system-core-fd3fd937b13dcaaee7275da21084f1ea897fb006.tar.xz
platform-system-core-fd3fd937b13dcaaee7275da21084f1ea897fb006.zip
adb: add benchmark script.
Test: ./benchmark_device.py Change-Id: I9f36cc267b1cbef2d90a30009c87ccc2a8e21795
-rwxr-xr-xadb/benchmark_device.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/adb/benchmark_device.py b/adb/benchmark_device.py
new file mode 100755
index 000000000..00c23153c
--- /dev/null
+++ b/adb/benchmark_device.py
@@ -0,0 +1,120 @@
1#!/usr/bin/env python3
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import os
19import statistics
20import time
21
22import adb
23
24def lock_min(device):
25 device.shell_nocheck(["""
26 for x in /sys/devices/system/cpu/cpu?/cpufreq; do
27 echo userspace > $x/scaling_governor
28 cat $x/scaling_min_freq > $x/scaling_setspeed
29 done
30 """])
31
32def lock_max(device):
33 device.shell_nocheck(["""
34 for x in /sys/devices/system/cpu/cpu?/cpufreq; do
35 echo userspace > $x/scaling_governor
36 cat $x/scaling_max_freq > $x/scaling_setspeed
37 done
38 """])
39
40def unlock(device):
41 device.shell_nocheck(["""
42 for x in /sys/devices/system/cpu/cpu?/cpufreq; do
43 echo ondemand > $x/scaling_governor
44 echo sched > $x/scaling_governor
45 echo schedutil > $x/scaling_governor
46 done
47 """])
48
49def harmonic_mean(xs):
50 return 1.0 / statistics.mean([1.0 / x for x in xs])
51
52def analyze(name, speeds):
53 median = statistics.median(speeds)
54 mean = harmonic_mean(speeds)
55 stddev = statistics.stdev(speeds)
56 msg = "%s: %d runs: median %.2f MiB/s, mean %.2f MiB/s, stddev: %.2f MiB/s"
57 print(msg % (name, len(speeds), median, mean, stddev))
58
59def benchmark_push(device=None, file_size_mb=100):
60 if device == None:
61 device = adb.get_device()
62
63 lock_max(device)
64
65 remote_path = "/dev/null"
66 local_path = "/tmp/adb_benchmark_temp"
67
68 with open(local_path, "wb") as f:
69 f.truncate(file_size_mb * 1024 * 1024)
70
71 speeds = list()
72 for _ in range(0, 5):
73 begin = time.time()
74 device.push(local=local_path, remote=remote_path)
75 end = time.time()
76 speeds.append(file_size_mb / float(end - begin))
77
78 analyze("push %dMiB" % file_size_mb, speeds)
79
80def benchmark_pull(device=None, file_size_mb=100):
81 if device == None:
82 device = adb.get_device()
83
84 lock_max(device)
85
86 remote_path = "/data/local/tmp/adb_benchmark_temp"
87 local_path = "/tmp/adb_benchmark_temp"
88
89 device.shell(["dd", "if=/dev/zero", "of=" + remote_path, "bs=1m",
90 "count=" + str(file_size_mb)])
91 speeds = list()
92 for _ in range(0, 5):
93 begin = time.time()
94 device.pull(remote=remote_path, local=local_path)
95 end = time.time()
96 speeds.append(file_size_mb / float(end - begin))
97
98 analyze("pull %dMiB" % file_size_mb, speeds)
99
100def benchmark_shell(device=None, file_size_mb=100):
101 if device == None:
102 device = adb.get_device()
103
104 lock_max(device)
105
106 speeds = list()
107 for _ in range(0, 5):
108 begin = time.time()
109 device.shell(["dd", "if=/dev/zero", "bs=1m",
110 "count=" + str(file_size_mb)])
111 end = time.time()
112 speeds.append(file_size_mb / float(end - begin))
113
114 analyze("shell %dMiB" % file_size_mb, speeds)
115
116def main():
117 benchmark_pull()
118
119if __name__ == "__main__":
120 main()