Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a525c455 authored by Xiang Wang's avatar Xiang Wang
Browse files

Update power manager benchmark to use power ndk

Bug: 280438886
Test: mm
Change-Id: I581a644af69eb54eb5b50199c77aa811e354ee67
parent d9af4b8f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ cc_benchmark {
    shared_libs: [
        "libbase",
        "libbinder",
        "libbinder_ndk",
        "libhidlbase",
        "liblog",
        "libpowermanager",
@@ -40,7 +41,7 @@ cc_benchmark {
        "android.hardware.power@1.1",
        "android.hardware.power@1.2",
        "android.hardware.power@1.3",
        "android.hardware.power-V4-cpp",
        "android.hardware.power-V4-ndk",
    ],
    static_libs: [
        "libtestUtil",
+33 −29
Original line number Diff line number Diff line
@@ -16,21 +16,24 @@

#define LOG_TAG "PowerHalAidlBenchmarks"

#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
#include <android/hardware/power/WorkDuration.h>
#include <aidl/android/hardware/power/Boost.h>
#include <aidl/android/hardware/power/IPower.h>
#include <aidl/android/hardware/power/IPowerHintSession.h>
#include <aidl/android/hardware/power/Mode.h>
#include <aidl/android/hardware/power/WorkDuration.h>
#include <benchmark/benchmark.h>
#include <binder/IServiceManager.h>
#include <binder/Status.h>
#include <powermanager/PowerHalLoader.h>
#include <testUtil.h>
#include <chrono>

using android::hardware::power::Boost;
using android::hardware::power::IPower;
using android::hardware::power::IPowerHintSession;
using android::hardware::power::Mode;
using android::hardware::power::WorkDuration;
using aidl::android::hardware::power::Boost;
using aidl::android::hardware::power::IPower;
using aidl::android::hardware::power::IPowerHintSession;
using aidl::android::hardware::power::Mode;
using aidl::android::hardware::power::WorkDuration;
using android::power::PowerHalLoader;
using std::chrono::microseconds;

using namespace android;
@@ -63,15 +66,15 @@ static constexpr microseconds ONEWAY_API_DELAY = 100us;
template <class R, class... Args0, class... Args1>
static void runBenchmark(benchmark::State& state, microseconds delay, R (IPower::*fn)(Args0...),
                         Args1&&... args1) {
    sp<IPower> hal = waitForVintfService<IPower>();
    std::shared_ptr<IPower> hal = PowerHalLoader::loadAidl();

    if (hal == nullptr) {
        ALOGV("Power HAL not available, skipping test...");
        return;
    }

    binder::Status ret = (*hal.*fn)(std::forward<Args1>(args1)...);
    if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
    ndk::ScopedAStatus ret = (*hal.*fn)(std::forward<Args1>(args1)...);
    if (ret.getExceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
        ALOGV("Power HAL does not support this operation, skipping test...");
        return;
    }
@@ -79,7 +82,7 @@ static void runBenchmark(benchmark::State& state, microseconds delay, R (IPower:
    while (state.KeepRunning()) {
        ret = (*hal.*fn)(std::forward<Args1>(args1)...);
        state.PauseTiming();
        if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
        if (!ret.isOk()) state.SkipWithError(ret.getDescription().c_str());
        if (delay > 0us) {
            testDelaySpin(std::chrono::duration_cast<std::chrono::duration<float>>(delay).count());
        }
@@ -90,9 +93,9 @@ static void runBenchmark(benchmark::State& state, microseconds delay, R (IPower:
template <class R, class... Args0, class... Args1>
static void runSessionBenchmark(benchmark::State& state, R (IPowerHintSession::*fn)(Args0...),
                                Args1&&... args1) {
    sp<IPower> pwHal = waitForVintfService<IPower>();
    std::shared_ptr<IPower> hal = PowerHalLoader::loadAidl();

    if (pwHal == nullptr) {
    if (hal == nullptr) {
        ALOGV("Power HAL not available, skipping test...");
        return;
    }
@@ -100,32 +103,32 @@ static void runSessionBenchmark(benchmark::State& state, R (IPowerHintSession::*
    // do not use tid from the benchmark process, use 1 for init
    std::vector<int32_t> threadIds{1};
    int64_t durationNanos = 16666666L;
    sp<IPowerHintSession> hal;
    std::shared_ptr<IPowerHintSession> session;

    auto status = pwHal->createHintSession(1, 0, threadIds, durationNanos, &hal);
    auto status = hal->createHintSession(1, 0, threadIds, durationNanos, &session);

    if (hal == nullptr) {
    if (session == nullptr) {
        ALOGV("Power HAL doesn't support session, skipping test...");
        return;
    }

    binder::Status ret = (*hal.*fn)(std::forward<Args1>(args1)...);
    if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
    ndk::ScopedAStatus ret = (*session.*fn)(std::forward<Args1>(args1)...);
    if (ret.getExceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
        ALOGV("Power HAL does not support this operation, skipping test...");
        return;
    }

    while (state.KeepRunning()) {
        ret = (*hal.*fn)(std::forward<Args1>(args1)...);
        ret = (*session.*fn)(std::forward<Args1>(args1)...);
        state.PauseTiming();
        if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
        if (!ret.isOk()) state.SkipWithError(ret.getDescription().c_str());
        if (ONEWAY_API_DELAY > 0us) {
            testDelaySpin(std::chrono::duration_cast<std::chrono::duration<float>>(ONEWAY_API_DELAY)
                                  .count());
        }
        state.ResumeTiming();
    }
    hal->close();
    session->close();
}

static void BM_PowerHalAidlBenchmarks_isBoostSupported(benchmark::State& state) {
@@ -155,16 +158,17 @@ static void BM_PowerHalAidlBenchmarks_createHintSession(benchmark::State& state)
    int64_t durationNanos = 16666666L;
    int32_t tgid = 999;
    int32_t uid = 1001;
    sp<IPowerHintSession> appSession;
    sp<IPower> hal = waitForVintfService<IPower>();
    std::shared_ptr<IPowerHintSession> appSession;
    std::shared_ptr<IPower> hal = PowerHalLoader::loadAidl();

    if (hal == nullptr) {
        ALOGV("Power HAL not available, skipping test...");
        return;
    }

    binder::Status ret = hal->createHintSession(tgid, uid, threadIds, durationNanos, &appSession);
    if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
    ndk::ScopedAStatus ret =
            hal->createHintSession(tgid, uid, threadIds, durationNanos, &appSession);
    if (ret.getExceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
        ALOGV("Power HAL does not support this operation, skipping test...");
        return;
    }
@@ -172,7 +176,7 @@ static void BM_PowerHalAidlBenchmarks_createHintSession(benchmark::State& state)
    while (state.KeepRunning()) {
        ret = hal->createHintSession(tgid, uid, threadIds, durationNanos, &appSession);
        state.PauseTiming();
        if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
        if (!ret.isOk()) state.SkipWithError(ret.getDescription().c_str());
        appSession->close();
        state.ResumeTiming();
    }
+4 −4
Original line number Diff line number Diff line
@@ -16,15 +16,15 @@

#define LOG_TAG "PowerHalControllerBenchmarks"

#include <android/hardware/power/Boost.h>
#include <android/hardware/power/Mode.h>
#include <aidl/android/hardware/power/Boost.h>
#include <aidl/android/hardware/power/Mode.h>
#include <benchmark/benchmark.h>
#include <powermanager/PowerHalController.h>
#include <testUtil.h>
#include <chrono>

using android::hardware::power::Boost;
using android::hardware::power::Mode;
using aidl::android::hardware::power::Boost;
using aidl::android::hardware::power::Mode;
using android::power::HalResult;
using android::power::PowerHalController;

+3 −5
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

#define LOG_TAG "PowerHalHidlBenchmarks"

#include <aidl/android/hardware/power/Boost.h>
#include <aidl/android/hardware/power/IPower.h>
#include <aidl/android/hardware/power/Mode.h>
#include <android/hardware/power/1.1/IPower.h>
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
#include <android/hardware/power/Mode.h>
#include <benchmark/benchmark.h>
#include <hardware/power.h>
#include <hardware_legacy/power.h>
@@ -27,8 +27,6 @@
#include <chrono>

using android::hardware::Return;
using android::hardware::power::Boost;
using android::hardware::power::Mode;
using android::hardware::power::V1_0::Feature;
using android::hardware::power::V1_0::PowerHint;
using std::chrono::microseconds;