Skip to content

Commit

Permalink
Fix benchmark am: 1261c8f am: 6b541a1
Browse files Browse the repository at this point in the history
Original change: https://android-review.googlesource.com/c/platform/packages/modules/adb/+/3229487

Change-Id: I96205865cd8fcfa684f5c80e5a988a5350290fb7
Signed-off-by: Automerger Merge Worker <[email protected]>
  • Loading branch information
Fabien Sanglard authored and android-build-merge-worker-robot committed Aug 20, 2024
2 parents 9d6f4bf + 6b541a1 commit 2d45102
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
42 changes: 24 additions & 18 deletions benchmark_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import tempfile
import time

transfer_size_mib = 100
num_runs = 10

# Make sure environment is setup, otherwise "adb" module is not available.
if os.getenv("ANDROID_BUILD_TOP") is None:
print("Run source/lunch before running " + sys.argv[0])
Expand Down Expand Up @@ -64,7 +67,7 @@ def analyze(name, speeds):
msg = "%s: %d runs: median %.2f MiB/s, mean %.2f MiB/s, stddev: %.2f MiB/s"
print(msg % (name, len(speeds), median, mean, stddev))

def benchmark_sink(device=None, size_mb=100):
def benchmark_sink(device=None, size_mb=transfer_size_mib):
if device == None:
device = adb.get_device()

Expand All @@ -74,89 +77,92 @@ def benchmark_sink(device=None, size_mb=100):
with tempfile.TemporaryFile() as tmpfile:
tmpfile.truncate(size_mb * 1024 * 1024)

for _ in range(0, 10):
for _ in range(0, num_runs):
tmpfile.seek(0)
begin = time.time()
subprocess.check_call(cmd, stdin=tmpfile)
end = time.time()
speeds.append(size_mb / float(end - begin))

analyze("sink %dMiB" % size_mb, speeds)
analyze("sink %dMiB (write RAM) " % size_mb, speeds)

def benchmark_source(device=None, size_mb=100):
def benchmark_source(device=None, size_mb=transfer_size_mib):
if device == None:
device = adb.get_device()

speeds = list()
cmd = device.adb_cmd + ["raw", "source:%d" % (size_mb * 1024 * 1024)]

with open(os.devnull, 'w') as devnull:
for _ in range(0, 10):
for _ in range(0, num_runs):
begin = time.time()
subprocess.check_call(cmd, stdout=devnull)
end = time.time()
speeds.append(size_mb / float(end - begin))

analyze("source %dMiB" % size_mb, speeds)
analyze("source %dMiB (read RAM) " % size_mb, speeds)

def benchmark_push(device=None, file_size_mb=100):
def benchmark_push(device=None, file_size_mb=transfer_size_mib):
if device == None:
device = adb.get_device()

remote_path = "/dev/null"
remote_path = "/data/local/tmp/adb_benchmark_push_tmp"
local_path = "/tmp/adb_benchmark_temp"

with open(local_path, "wb") as f:
f.truncate(file_size_mb * 1024 * 1024)

speeds = list()
for _ in range(0, 10):
for _ in range(0, num_runs):
begin = time.time()
device.push(local=local_path, remote=remote_path)
parameters = ['-Z'] # Disable compression since our file is full of 0s
device.push(local=local_path, remote=remote_path, parameters=parameters)
end = time.time()
speeds.append(file_size_mb / float(end - begin))

analyze("push %dMiB" % file_size_mb, speeds)
analyze("push %dMiB (write flash)" % file_size_mb, speeds)

def benchmark_pull(device=None, file_size_mb=100):
def benchmark_pull(device=None, file_size_mb=transfer_size_mib):
if device == None:
device = adb.get_device()

remote_path = "/data/local/tmp/adb_benchmark_temp"
remote_path = "/data/local/tmp/adb_benchmark_pull_temp"
local_path = "/tmp/adb_benchmark_temp"

device.shell(["dd", "if=/dev/zero", "of=" + remote_path, "bs=1m",
"count=" + str(file_size_mb)])
speeds = list()
for _ in range(0, 10):
for _ in range(0, num_runs):
begin = time.time()
device.pull(remote=remote_path, local=local_path)
end = time.time()
speeds.append(file_size_mb / float(end - begin))

analyze("pull %dMiB" % file_size_mb, speeds)
analyze("pull %dMiB (read flash) " % file_size_mb, speeds)

def benchmark_shell(device=None, file_size_mb=100):
def benchmark_device_dd(device=None, file_size_mb=transfer_size_mib):
if device == None:
device = adb.get_device()

speeds = list()
for _ in range(0, 10):
for _ in range(0, num_runs):
begin = time.time()
device.shell(["dd", "if=/dev/zero", "bs=1m",
"count=" + str(file_size_mb)])
end = time.time()
speeds.append(file_size_mb / float(end - begin))

analyze("shell %dMiB" % file_size_mb, speeds)
analyze("dd %dMiB (write flash)" % file_size_mb, speeds)

def main():
device = adb.get_device()
unlock(device)

benchmark_sink(device)
benchmark_source(device)
benchmark_push(device)
benchmark_pull(device)
benchmark_device_dd(device)

if __name__ == "__main__":
main()
11 changes: 6 additions & 5 deletions docs/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ Despite its name the `sync` protocol is also what powers operations such as `pul
### Benchmark sample run for Pixel 8,USB

```
$ ./benchmark_device.py
sink 100MiB: 10 runs: median 27.00 MiB/s, mean 26.39 MiB/s, stddev: 1.11 MiB/s
source 100MiB: 10 runs: median 36.97 MiB/s, mean 37.05 MiB/s, stddev: 0.46 MiB/s
push 100MiB: 10 runs: median 331.96 MiB/s, mean 329.81 MiB/s, stddev: 14.67 MiB/s
pull 100MiB: 10 runs: median 34.55 MiB/s, mean 33.57 MiB/s, stddev: 2.54 MiB/s
$ ./benchmark_device.py
sink 100MiB (write RAM) : 10 runs: median 128.07 MiB/s, mean 126.90 MiB/s, stddev: 19.37 MiB/s
source 100MiB (read RAM) : 10 runs: median 233.73 MiB/s, mean 250.81 MiB/s, stddev: 47.45 MiB/s
push 100MiB (write flash): 10 runs: median 142.82 MiB/s, mean 145.49 MiB/s, stddev: 16.57 MiB/s
pull 100MiB (read flash) : 10 runs: median 190.37 MiB/s, mean 189.08 MiB/s, stddev: 51.24 MiB/s
dd 100MiB (write flash): 10 runs: median 121.57 MiB/s, mean 125.60 MiB/s, stddev: 15.81 MiB/s
```

### Tests
Expand Down

0 comments on commit 2d45102

Please sign in to comment.