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

Commit 0e875399 authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "Add refresh rate stats to TimeStats."

parents 5ef8f96e fb571ea6
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ public:
        int configId;
        // Human readable name of the refresh rate.
        std::string name;
        // Refresh rate in frames per second, rounded to the nearest integer.
        uint32_t fps = 0;
    };

    // TODO(b/122916473): Get this information from configs prepared by vendors, instead of
@@ -63,7 +65,7 @@ private:
    void init(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) {
        // This is the rate that HWC encapsulates right now when the device is in DOZE mode.
        mRefreshRates.push_back(
                RefreshRate{RefreshRateType::POWER_SAVING, SCREEN_OFF_CONFIG_ID, "ScreenOff"});
                RefreshRate{RefreshRateType::POWER_SAVING, SCREEN_OFF_CONFIG_ID, "ScreenOff", 0});

        if (configs.size() < 1) {
            ALOGE("Device does not have valid configs. Config size is 0.");
@@ -86,10 +88,11 @@ private:
        nsecs_t vsyncPeriod = configIdToVsyncPeriod[0].second;
        if (vsyncPeriod != 0) {
            const float fps = 1e9 / vsyncPeriod;
            mRefreshRates.push_back(RefreshRate{RefreshRateType::DEFAULT,
                                                configIdToVsyncPeriod[0].first,
                                                base::StringPrintf("%2.ffps", fps)});
            mRefreshRates.push_back(
                    RefreshRate{RefreshRateType::DEFAULT, configIdToVsyncPeriod[0].first,
                                base::StringPrintf("%2.ffps", fps), static_cast<uint32_t>(fps)});
        }

        if (configs.size() < 2) {
            return;
        }
@@ -99,9 +102,9 @@ private:
        vsyncPeriod = configIdToVsyncPeriod[1].second;
        if (vsyncPeriod != 0) {
            const float fps = 1e9 / vsyncPeriod;
            mRefreshRates.push_back(RefreshRate{RefreshRateType::PERFORMANCE,
                                                configIdToVsyncPeriod[1].first,
                                                base::StringPrintf("%2.ffps", fps)});
            mRefreshRates.push_back(
                    RefreshRate{RefreshRateType::PERFORMANCE, configIdToVsyncPeriod[1].first,
                                base::StringPrintf("%2.ffps", fps), static_cast<uint32_t>(fps)});
        }
    }

+15 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include "Scheduler/RefreshRateConfigs.h"
#include "Scheduler/SchedulerUtils.h"
#include "TimeStats/TimeStats.h"

#include "android-base/stringprintf.h"
#include "utils/Timers.h"
@@ -41,8 +42,10 @@ class RefreshRateStats {

public:
    explicit RefreshRateStats(
            const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs)
            const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
            const std::shared_ptr<TimeStats>& timeStats)
          : mRefreshRateConfigs(std::make_unique<RefreshRateConfigs>(configs)),
            mTimeStats(timeStats),
            mPreviousRecordedTime(systemTime()) {}
    ~RefreshRateStats() = default;

@@ -116,10 +119,16 @@ private:
    // this method was called.
    void flushTimeForMode(int mode) {
        nsecs_t currentTime = systemTime();
        int64_t timeElapsedMs = ns2ms(currentTime - mPreviousRecordedTime);
        nsecs_t timeElapsed = currentTime - mPreviousRecordedTime;
        int64_t timeElapsedMs = ns2ms(timeElapsed);
        mPreviousRecordedTime = currentTime;

        mConfigModesTotalTime[mode] += timeElapsedMs;
        for (const auto& config : mRefreshRateConfigs->getRefreshRates()) {
            if (config.configId == mode) {
                mTimeStats->recordRefreshRate(config.fps, timeElapsed);
            }
        }
    }

    // Formats the time in milliseconds into easy to read format.
@@ -136,6 +145,9 @@ private:
    // Keeps information about refresh rate configs that device has.
    std::unique_ptr<RefreshRateConfigs> mRefreshRateConfigs;

    // Aggregate refresh rate statistics for telemetry.
    std::shared_ptr<TimeStats> mTimeStats;

    int64_t mCurrentConfigMode = 0;
    int32_t mCurrentPowerMode = HWC_POWER_MODE_OFF;

+4 −2
Original line number Diff line number Diff line
@@ -742,8 +742,10 @@ void SurfaceFlinger::init() {
            mVsyncModulator.setPhaseOffsets(early, gl, late);
            setRefreshRateTo(90.f /* fps */);
        });
        mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(
                getHwComposer().getConfigs(*display->getId()));
        mRefreshRateStats =
                std::make_unique<scheduler::RefreshRateStats>(getHwComposer().getConfigs(
                                                                      *display->getId()),
                                                              mTimeStats);
    }

    ALOGV("Done initializing");
+1 −1
Original line number Diff line number Diff line
@@ -1000,7 +1000,7 @@ private:
    std::unique_ptr<SurfaceInterceptor> mInterceptor{mFactory.createSurfaceInterceptor(this)};
    SurfaceTracing mTracing;
    LayerStats mLayerStats;
    std::unique_ptr<TimeStats> mTimeStats;
    std::shared_ptr<TimeStats> mTimeStats;
    bool mUseHwcVirtualDisplays = false;
    std::atomic<uint32_t> mFrameMissedCount{0};

+2 −2
Original line number Diff line number Diff line
@@ -128,8 +128,8 @@ sp<SurfaceFlinger> createSurfaceFlinger() {
            return new ColorLayer(args);
        }

        std::unique_ptr<TimeStats> createTimeStats() override {
            return std::make_unique<TimeStats>();
        std::shared_ptr<TimeStats> createTimeStats() override {
            return std::make_shared<android::impl::TimeStats>();
        }
    };
    static Factory factory;
Loading