From f2685f68fb6b671ef4aaf571f6026f3aabbcb0bd Mon Sep 17 00:00:00 2001 From: Alice Wang Date: Tue, 6 Sep 2022 07:26:53 +0000 Subject: [PATCH] cleanup:Rename IBenchmarkService#readFile to measureReadRate This CL renames IBenchmarkService#readFile to measureReadRate to make the code more clear when introducing new read method later for authfs. Test: atest MicrodroidBenchmarks Change-Id: I1e39063ec704fcefb96f7d307e6598d291443645 --- .../testservice/IBenchmarkService.aidl | 8 ++++++-- tests/benchmark/Android.bp | 4 ++-- .../benchmark/MicrodroidBenchmarks.java | 5 ++--- tests/benchmark/src/native/benchmarkbinary.cpp | 16 ++++++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/aidl/com/android/microdroid/testservice/IBenchmarkService.aidl b/tests/aidl/com/android/microdroid/testservice/IBenchmarkService.aidl index e34c4b01..260f8044 100644 --- a/tests/aidl/com/android/microdroid/testservice/IBenchmarkService.aidl +++ b/tests/aidl/com/android/microdroid/testservice/IBenchmarkService.aidl @@ -20,8 +20,12 @@ package com.android.microdroid.testservice; interface IBenchmarkService { const int SERVICE_PORT = 5677; - /** Reads a file and returns the elapsed seconds for the reading. */ - double readFile(String filename, long fileSizeBytes, boolean isRand); + /** + * Measures the read rate for reading the given file. + * + * @return The read rate in MB/s. + */ + double measureReadRate(String filename, long fileSizeBytes, boolean isRand); /** Returns an entry from /proc/meminfo. */ long getMemInfoEntry(String name); diff --git a/tests/benchmark/Android.bp b/tests/benchmark/Android.bp index bf78202c..f1aebd28 100644 --- a/tests/benchmark/Android.bp +++ b/tests/benchmark/Android.bp @@ -29,7 +29,7 @@ android_test { cc_library_shared { name: "MicrodroidBenchmarkNativeLib", srcs: ["src/native/benchmarkbinary.cpp"], - static_libs: ["libiovsock_vm"], + static_libs: ["libiobenchmark"], shared_libs: [ "android.system.virtualmachineservice-ndk", "com.android.microdroid.testservice-ndk", @@ -41,7 +41,7 @@ cc_library_shared { } cc_library { - name: "libiovsock_vm", + name: "libiobenchmark", srcs: ["src/native/io_vsock.cpp"], export_include_dirs: ["src/native/include"], shared_libs: [ diff --git a/tests/benchmark/src/java/com/android/microdroid/benchmark/MicrodroidBenchmarks.java b/tests/benchmark/src/java/com/android/microdroid/benchmark/MicrodroidBenchmarks.java index cdaf70c3..7bf3c4e4 100644 --- a/tests/benchmark/src/java/com/android/microdroid/benchmark/MicrodroidBenchmarks.java +++ b/tests/benchmark/src/java/com/android/microdroid/benchmark/MicrodroidBenchmarks.java @@ -268,9 +268,8 @@ public class MicrodroidBenchmarks extends MicrodroidDeviceTestBase { @Override public void onPayloadReady(VirtualMachine vm, IBenchmarkService benchmarkService) throws RemoteException { - double elapsedSeconds = benchmarkService.readFile(FILENAME, mFileSizeBytes, mIsRand); - double fileSizeMb = mFileSizeBytes / SIZE_MB; - mReadRates.add(fileSizeMb / elapsedSeconds); + double readRate = benchmarkService.measureReadRate(FILENAME, mFileSizeBytes, mIsRand); + mReadRates.add(readRate); } } diff --git a/tests/benchmark/src/native/benchmarkbinary.cpp b/tests/benchmark/src/native/benchmarkbinary.cpp index 28799c8e..58b4cf02 100644 --- a/tests/benchmark/src/native/benchmarkbinary.cpp +++ b/tests/benchmark/src/native/benchmarkbinary.cpp @@ -42,6 +42,7 @@ using android::base::unique_fd; namespace { constexpr uint64_t kBlockSizeBytes = 4096; +constexpr uint64_t kNumBytesPerMB = 1024 * 1024; template static ndk::ScopedAStatus resultStatus(const T& result) { @@ -56,9 +57,9 @@ static ndk::ScopedAStatus resultStatus(const T& result) { class IOBenchmarkService : public aidl::com::android::microdroid::testservice::BnBenchmarkService { public: - ndk::ScopedAStatus readFile(const std::string& filename, int64_t fileSizeBytes, bool isRand, - double* out) override { - auto res = read_file(filename, fileSizeBytes, isRand); + ndk::ScopedAStatus measureReadRate(const std::string& filename, int64_t fileSizeBytes, + bool isRand, double* out) override { + auto res = measure_read_rate(filename, fileSizeBytes, isRand); if (res.ok()) { *out = res.value(); } @@ -90,8 +91,9 @@ public: } private: - /** Returns the elapsed seconds for reading the file. */ - Result read_file(const std::string& filename, int64_t fileSizeBytes, bool is_rand) { + /** Measures the read rate for reading the given file. */ + Result measure_read_rate(const std::string& filename, int64_t fileSizeBytes, + bool is_rand) { const int64_t block_count = fileSizeBytes / kBlockSizeBytes; std::vector offsets; if (is_rand) { @@ -120,7 +122,9 @@ private: return ErrnoError() << "failed to read"; } } - return {((double)clock() - start) / CLOCKS_PER_SEC}; + double elapsed_seconds = ((double)clock() - start) / CLOCKS_PER_SEC; + double read_rate = (double)fileSizeBytes / kNumBytesPerMB / elapsed_seconds; + return {read_rate}; } Result read_meminfo_entry(const std::string& stat) {