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

Commit 82d7ab6c authored by Mathias Agopian's avatar Mathias Agopian
Browse files

improve SurfaceFlinger dumpsys

It is now possible to say:

dumpsys SurfaceFlinger --latency

to print latency information about all windows

dumpsys SurfaceFlinger --latency window-name

to print the latency stats of the specified window

for instance: dumpsys SurfaceFlinger --latency SurfaceView

The data consists of one line containing global stats, followed by
128 lines of tab separated timestamps in nanosecond.

The first line currently contains the refresh period in nanosecond.
Each 128 following line contains 3 timestamps, of respectively
the app draw time, the vsync timestamp just prior the call to set and
the timestamp of the call to set.

Change-Id: Ib6b6da1d7e2e6ba49c282bdbc0b56a7dc203343a
parent e8696a40
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -350,15 +350,28 @@ uint32_t DisplayHardware::getPageFlipCount() const {
}

// this needs to be thread safe
nsecs_t DisplayHardware::waitForVSync() const {
nsecs_t DisplayHardware::waitForRefresh() const {
    nsecs_t timestamp;
    if (mVSync.wait(&timestamp) < 0) {
        // vsync not supported!
        usleep( getDelayToNextVSyncUs(&timestamp) );
    }
    mLastHwVSync = timestamp; // FIXME: Not thread safe
    return timestamp;
}

nsecs_t DisplayHardware::getRefreshTimestamp() const {
    // this returns the last refresh timestamp.
    // if the last one is not available, we estimate it based on
    // the refresh period and whatever closest timestamp we have.
    nsecs_t now = systemTime();
    return now - ((now - mLastHwVSync) %  mRefreshPeriod);
}

nsecs_t DisplayHardware::getRefreshPeriod() const {
    return mRefreshPeriod;
}

int32_t DisplayHardware::getDelayToNextVSyncUs(nsecs_t* timestamp) const {
    Mutex::Autolock _l(mFakeVSyncMutex);
    const nsecs_t period = mRefreshPeriod;
+4 −1
Original line number Diff line number Diff line
@@ -76,7 +76,9 @@ public:
    uint32_t    getMaxViewportDims() const;

    // waits for the next vsync and returns the timestamp of when it happened
    nsecs_t        waitForVSync() const;
    nsecs_t     waitForRefresh() const;
    nsecs_t     getRefreshPeriod() const;
    nsecs_t     getRefreshTimestamp() const;

    uint32_t getPageFlipCount() const;
    EGLDisplay getEGLDisplay() const { return mDisplay; }
@@ -119,6 +121,7 @@ private:
    mutable Mutex   mFakeVSyncMutex;
    mutable nsecs_t mNextFakeVSync;
    nsecs_t         mRefreshPeriod;
    mutable nsecs_t mLastHwVSync;

    HWComposer*     mHwc;

+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ bool EventThread::threadLoop() {

            // at least one listener requested VSYNC
            mLock.unlock();
            timestamp = mHw.waitForVSync();
            timestamp = mHw.waitForRefresh();
            mLock.lock();
            mDeliveredEvents++;

+28 −20
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "Layer.h"
#include "SurfaceFlinger.h"
#include "SurfaceTextureLayer.h"
#include <math.h>

#define DEBUG_RESIZE    0

@@ -54,6 +55,8 @@ Layer::Layer(SurfaceFlinger* flinger,
        mCurrentTransform(0),
        mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
        mCurrentOpacity(true),
        mFrameLatencyNeeded(false),
        mFrameLatencyOffset(0),
        mFormat(PIXEL_FORMAT_NONE),
        mGLExtensions(GLExtensions::getInstance()),
        mOpaqueLayer(true),
@@ -63,19 +66,14 @@ Layer::Layer(SurfaceFlinger* flinger,
{
    mCurrentCrop.makeInvalid();
    glGenTextures(1, &mTextureName);

    mFrameLatencyNeeded = false;
    mFrameLatencyOffset = 0;
    for (int i = 0; i < 128; i++) {
        mFrameLatencies[i] = 0;
    }
}

void Layer::onLayerDisplayed() {
    if (mFrameLatencyNeeded) {
        int64_t now = systemTime(SYSTEM_TIME_MONOTONIC);
        mFrameLatencies[mFrameLatencyOffset] = now -
                mSurfaceTexture->getTimestamp();
        const DisplayHardware& hw(graphicPlane(0).displayHardware());
        mFrameStats[mFrameLatencyOffset].timestamp = mSurfaceTexture->getTimestamp();
        mFrameStats[mFrameLatencyOffset].set = systemTime();
        mFrameStats[mFrameLatencyOffset].vsync = hw.getRefreshTimestamp();
        mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128;
        mFrameLatencyNeeded = false;
    }
@@ -555,23 +553,33 @@ void Layer::dump(String8& result, char* buffer, size_t SIZE) const

    result.append(buffer);

    const int64_t* l = mFrameLatencies;
    int o = mFrameLatencyOffset;
    for (int i = 0; i < 128; i += 8) {
        snprintf(buffer, SIZE,
                "      "
                "% 12lld % 12lld % 12lld % 12lld "
                "% 12lld % 12lld % 12lld % 12lld\n",
                l[(o+i+0)%128], l[(o+i+1)%128], l[(o+i+2)%128], l[(o+i+3)%128],
                l[(o+i+4)%128], l[(o+i+5)%128], l[(o+i+6)%128], l[(o+i+7)%128]);
        result.append(buffer);
    }
    LayerBase::dumpStats(result, buffer, SIZE);

    if (mSurfaceTexture != 0) {
        mSurfaceTexture->dump(result, "            ", buffer, SIZE);
    }
}

void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
{
    LayerBaseClient::dumpStats(result, buffer, SIZE);
    const size_t o = mFrameLatencyOffset;
    const DisplayHardware& hw(graphicPlane(0).displayHardware());
    const nsecs_t period = hw.getRefreshPeriod();
    result.appendFormat("%lld\n", period);
    for (size_t i=0 ; i<128 ; i++) {
        const size_t index = (o+i) % 128;
        const nsecs_t time_app   = mFrameStats[index].timestamp;
        const nsecs_t time_set   = mFrameStats[index].set;
        const nsecs_t time_vsync = mFrameStats[index].vsync;
        result.appendFormat("%lld\t%lld\t%lld\n",
                time_app,
                time_vsync,
                time_set);
    }
    result.append("\n");
}

uint32_t Layer::getEffectiveUsage(uint32_t usage) const
{
    // TODO: should we do something special if mSecure is set?
+10 −4
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "LayerBase.h"
#include "SurfaceTextureLayer.h"
#include "Transform.h"
#include <utils/Timers.h>

namespace android {

@@ -86,6 +87,7 @@ public:
protected:
    virtual void onFirstRef();
    virtual void dump(String8& result, char* scratch, size_t size) const;
    virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;

private:
    friend class SurfaceTextureLayer;
@@ -114,7 +116,14 @@ private:
    bool mCurrentOpacity;
    bool mFrameLatencyNeeded;
    int mFrameLatencyOffset;
    int64_t mFrameLatencies[128];
    struct Statistics {
        Statistics() : timestamp(0), set(0), vsync(0) { }
        nsecs_t timestamp;  // buffer timestamp
        nsecs_t set;        // buffer displayed timestamp
        nsecs_t vsync;      // vsync immediately before set
    };
    // protected by mLock
    Statistics mFrameStats[128];

    // constants
    PixelFormat mFormat;
@@ -126,9 +135,6 @@ private:
    bool mSecure;         // no screenshots
    bool mProtectedByApp; // application requires protected path to external sink
    Region mPostedDirtyRegion;

    // binder thread, transaction thread
    mutable Mutex mLock;
};

// ---------------------------------------------------------------------------
Loading