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
This commit is contained in:
Alice Wang 2022-09-06 07:26:53 +00:00
parent 512a1f174d
commit f2685f68fb
4 changed files with 20 additions and 13 deletions

View File

@ -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);

View File

@ -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: [

View File

@ -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);
}
}

View File

@ -42,6 +42,7 @@ using android::base::unique_fd;
namespace {
constexpr uint64_t kBlockSizeBytes = 4096;
constexpr uint64_t kNumBytesPerMB = 1024 * 1024;
template <typename T>
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<double> read_file(const std::string& filename, int64_t fileSizeBytes, bool is_rand) {
/** Measures the read rate for reading the given file. */
Result<double> measure_read_rate(const std::string& filename, int64_t fileSizeBytes,
bool is_rand) {
const int64_t block_count = fileSizeBytes / kBlockSizeBytes;
std::vector<uint64_t> 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<size_t> read_meminfo_entry(const std::string& stat) {