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

Commit ce6ebc04 authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

SF TimeStats: add global present to present histogram

Bug: b/79872109
Test: dumpsys SurfaceFlinger --timestats <options>
Change-Id: Iab8c01d66c69a04a89f7e9313e53ff961ce0175c
parent 3a226d2a
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -1909,6 +1909,8 @@ void SurfaceFlinger::postComposition()
        mTimeStats.incrementClientCompositionFrames();
        mTimeStats.incrementClientCompositionFrames();
    }
    }


    mTimeStats.setPresentFenceGlobal(presentFenceTime);

    if (display && getHwComposer().isConnected(display->getId()) &&
    if (display && getHwComposer().isConnected(display->getId()) &&
        display->getPowerMode() == HWC_POWER_MODE_OFF) {
        display->getPowerMode() == HWC_POWER_MODE_OFF) {
        return;
        return;
+49 −0
Original line number Original line Diff line number Diff line
@@ -479,6 +479,54 @@ void TimeStats::setPowerMode(int32_t powerMode) {
    mPowerTime.powerMode = powerMode;
    mPowerTime.powerMode = powerMode;
}
}


void TimeStats::flushAvailableGlobalRecordsToStatsLocked() {
    ATRACE_CALL();

    while (!mGlobalRecord.presentFences.empty()) {
        const nsecs_t curPresentTime = mGlobalRecord.presentFences.front()->getSignalTime();
        if (curPresentTime == Fence::SIGNAL_TIME_PENDING) break;

        if (curPresentTime == Fence::SIGNAL_TIME_INVALID) {
            ALOGE("GlobalPresentFence is invalid!");
            mGlobalRecord.prevPresentTime = 0;
            mGlobalRecord.presentFences.pop_front();
            continue;
        }

        ALOGV("GlobalPresentFenceTime[%" PRId64 "]",
              mGlobalRecord.presentFences.front()->getSignalTime());

        const int32_t presentToPresentMs = msBetween(mGlobalRecord.prevPresentTime, curPresentTime);
        ALOGV("Global present2present[%d]", presentToPresentMs);

        mTimeStats.presentToPresent.insert(presentToPresentMs);
        mGlobalRecord.prevPresentTime = curPresentTime;
        mGlobalRecord.presentFences.pop_front();
    }
}

void TimeStats::setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) {
    if (!mEnabled.load()) return;

    ATRACE_CALL();
    std::lock_guard<std::mutex> lock(mMutex);
    if (presentFence == nullptr) {
        mGlobalRecord.prevPresentTime = 0;
        return;
    }

    if (mGlobalRecord.presentFences.size() == MAX_NUM_TIME_RECORDS) {
        // The front presentFence must be trapped in pending status in this
        // case. Try dequeuing the front one to recover.
        ALOGE("GlobalPresentFences is already at its maximum size[%zu]", MAX_NUM_TIME_RECORDS);
        mGlobalRecord.prevPresentTime = 0;
        mGlobalRecord.presentFences.pop_front();
    }

    mGlobalRecord.presentFences.emplace_back(presentFence);
    flushAvailableGlobalRecordsToStatsLocked();
}

void TimeStats::enable() {
void TimeStats::enable() {
    if (mEnabled.load()) return;
    if (mEnabled.load()) return;


@@ -514,6 +562,7 @@ void TimeStats::clear() {
    mTimeStats.missedFrames = 0;
    mTimeStats.missedFrames = 0;
    mTimeStats.clientCompositionFrames = 0;
    mTimeStats.clientCompositionFrames = 0;
    mTimeStats.displayOnTime = 0;
    mTimeStats.displayOnTime = 0;
    mTimeStats.presentToPresent.hist.clear();
    mPowerTime.prevTime = systemTime();
    mPowerTime.prevTime = systemTime();
}
}


+8 −0
Original line number Original line Diff line number Diff line
@@ -73,6 +73,11 @@ class TimeStats {
        nsecs_t prevTime = 0;
        nsecs_t prevTime = 0;
    };
    };


    struct GlobalRecord {
        nsecs_t prevPresentTime = 0;
        std::deque<std::shared_ptr<FenceTime>> presentFences;
    };

public:
public:
    static TimeStats& getInstance();
    static TimeStats& getInstance();
    void parseArgs(bool asProto, const Vector<String16>& args, size_t& index, String8& result);
    void parseArgs(bool asProto, const Vector<String16>& args, size_t& index, String8& result);
@@ -99,6 +104,7 @@ public:
    void removeTimeRecord(const std::string& layerName, uint64_t frameNumber);
    void removeTimeRecord(const std::string& layerName, uint64_t frameNumber);


    void setPowerMode(int32_t powerMode);
    void setPowerMode(int32_t powerMode);
    void setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence);


private:
private:
    TimeStats() = default;
    TimeStats() = default;
@@ -106,6 +112,7 @@ private:
    bool recordReadyLocked(const std::string& layerName, TimeRecord* timeRecord);
    bool recordReadyLocked(const std::string& layerName, TimeRecord* timeRecord);
    void flushAvailableRecordsToStatsLocked(const std::string& layerName);
    void flushAvailableRecordsToStatsLocked(const std::string& layerName);
    void flushPowerTimeLocked();
    void flushPowerTimeLocked();
    void flushAvailableGlobalRecordsToStatsLocked();


    void enable();
    void enable();
    void disable();
    void disable();
@@ -118,6 +125,7 @@ private:
    TimeStatsHelper::TimeStatsGlobal mTimeStats;
    TimeStatsHelper::TimeStatsGlobal mTimeStats;
    std::unordered_map<std::string, LayerRecord> mTimeStatsTracker;
    std::unordered_map<std::string, LayerRecord> mTimeStatsTracker;
    PowerTime mPowerTime;
    PowerTime mPowerTime;
    GlobalRecord mGlobalRecord;
};
};


} // namespace android
} // namespace android
+7 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,8 @@ std::string TimeStatsHelper::TimeStatsGlobal::toString(std::optional<uint32_t> m
    StringAppendF(&result, "missedFrames = %d\n", missedFrames);
    StringAppendF(&result, "missedFrames = %d\n", missedFrames);
    StringAppendF(&result, "clientCompositionFrames = %d\n", clientCompositionFrames);
    StringAppendF(&result, "clientCompositionFrames = %d\n", clientCompositionFrames);
    StringAppendF(&result, "displayOnTime = %lld ms\n", static_cast<long long int>(displayOnTime));
    StringAppendF(&result, "displayOnTime = %lld ms\n", static_cast<long long int>(displayOnTime));
    StringAppendF(&result, "presentToPresent histogram is as below:\n");
    result.append(presentToPresent.toString());
    const auto dumpStats = generateDumpStats(maxLayers);
    const auto dumpStats = generateDumpStats(maxLayers);
    for (const auto& ele : dumpStats) {
    for (const auto& ele : dumpStats) {
        result.append(ele->toString());
        result.append(ele->toString());
@@ -128,6 +130,11 @@ SFTimeStatsGlobalProto TimeStatsHelper::TimeStatsGlobal::toProto(
    globalProto.set_missed_frames(missedFrames);
    globalProto.set_missed_frames(missedFrames);
    globalProto.set_client_composition_frames(clientCompositionFrames);
    globalProto.set_client_composition_frames(clientCompositionFrames);
    globalProto.set_display_on_time(displayOnTime);
    globalProto.set_display_on_time(displayOnTime);
    for (const auto& histEle : presentToPresent.hist) {
        SFTimeStatsHistogramBucketProto* histProto = globalProto.add_present_to_present();
        histProto->set_time_millis(histEle.first);
        histProto->set_frame_count(histEle.second);
    }
    const auto dumpStats = generateDumpStats(maxLayers);
    const auto dumpStats = generateDumpStats(maxLayers);
    for (const auto& ele : dumpStats) {
    for (const auto& ele : dumpStats) {
        SFTimeStatsLayerProto* layerProto = globalProto.add_stats();
        SFTimeStatsLayerProto* layerProto = globalProto.add_stats();
+1 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@ public:
        int32_t missedFrames = 0;
        int32_t missedFrames = 0;
        int32_t clientCompositionFrames = 0;
        int32_t clientCompositionFrames = 0;
        int64_t displayOnTime = 0;
        int64_t displayOnTime = 0;
        Histogram presentToPresent;
        std::unordered_map<std::string, TimeStatsLayer> stats;
        std::unordered_map<std::string, TimeStatsLayer> stats;


        std::string toString(std::optional<uint32_t> maxLayers) const;
        std::string toString(std::optional<uint32_t> maxLayers) const;
Loading