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

Commit aed22829 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Pass metrics buffer as std::array

Before this change, metrics were passed around as a raw array, without clear guidance of how big the array was or how to use it. The callers had to look into the implementation to understand that to use this array, "FrameInfo.h" needed to be included, and that the array size and indices were there.

With the current refactor, it will become slightly easier to use these metrics.

Bug: 376713684
Change-Id: Iecc04a0a215a7913ca8f49e4611fb104e1cacb8e
Test: compile only
Flag: EXEMPT refactor
parent 6dd107ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static_assert(static_cast<int>(FrameInfoIndex::NumIndexes) == 24,
              "Must update value in FrameMetrics.java#FRAME_STATS_COUNT (and here)");

void FrameInfo::importUiThreadInfo(int64_t* info) {
    memcpy(mFrameInfo, info, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
    memcpy(mFrameInfo.data(), info, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
    mSkippedFrameReason.reset();
}

+4 −2
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ enum {
};
};

using FrameInfoBuffer = std::array<int64_t, static_cast<size_t>(FrameInfoIndex::NumIndexes)>;

class UiFrameInfoBuilder {
public:
    static constexpr int64_t INVALID_VSYNC_ID = -1;
@@ -152,7 +154,7 @@ public:
        set(FrameInfoIndex::Flags) |= static_cast<uint64_t>(frameInfoFlag);
    }

    const int64_t* data() const { return mFrameInfo; }
    const FrameInfoBuffer& data() const { return mFrameInfo; }

    inline int64_t operator[](FrameInfoIndex index) const { return get(index); }

@@ -201,7 +203,7 @@ public:
    }

private:
    int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::NumIndexes)];
    FrameInfoBuffer mFrameInfo;
    std::optional<SkippedFrameReason> mSkippedFrameReason;
};

+3 −1
Original line number Diff line number Diff line
@@ -18,12 +18,14 @@

#include <utils/RefBase.h>

#include "FrameInfo.h"

namespace android {
namespace uirenderer {

class FrameMetricsObserver : public VirtualLightRefBase {
public:
    virtual void notify(const int64_t* buffer) = 0;
    virtual void notify(const FrameInfoBuffer& buffer) = 0;
    bool waitForPresentTime() const { return mWaitForPresentTime; };

    void reportMetricsFrom(uint64_t frameNumber, int32_t surfaceControlId) {
+3 −1
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

#include "FrameMetricsReporter.h"

#include "FrameInfo.h"

namespace android {
namespace uirenderer {

void FrameMetricsReporter::reportFrameMetrics(const int64_t* stats, bool hasPresentTime,
void FrameMetricsReporter::reportFrameMetrics(const FrameInfoBuffer& stats, bool hasPresentTime,
                                              uint64_t frameNumber, int32_t surfaceControlId) {
    FatVector<sp<FrameMetricsObserver>, 10> copy;
    {
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public:
     * stats of frames that are from "old" surfaces (i.e. with surfaceControlIds older than the one
     * the observer was attached on) nor those that are from "old" frame numbers.
     */
    void reportFrameMetrics(const int64_t* stats, bool hasPresentTime, uint64_t frameNumber,
    void reportFrameMetrics(const FrameInfoBuffer& stats, bool hasPresentTime, uint64_t frameNumber,
                            int32_t surfaceControlId);

private:
Loading