From c751e92c56de5f335a36e68607c7a6c627dcd0dc Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 8 May 2014 14:53:26 -0700 Subject: Add "dumpsys SurfaceFlinger --dispsync" Dumps the current DispSync state. Bug 14651879 Change-Id: Ide4e6dbd58b117bc1a6b97b57d10cd92ec86dc84 --- services/surfaceflinger/DispSync.cpp | 45 +++++++++++++++++++++++++ services/surfaceflinger/DispSync.h | 3 ++ services/surfaceflinger/SurfaceFlinger.cpp | 7 ++++ services/surfaceflinger/main_surfaceflinger.cpp | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/services/surfaceflinger/DispSync.cpp b/services/surfaceflinger/DispSync.cpp index 2ee7570365..d771e2c2ae 100644 --- a/services/surfaceflinger/DispSync.cpp +++ b/services/surfaceflinger/DispSync.cpp @@ -514,4 +514,49 @@ nsecs_t DispSync::computeNextRefresh(int periodOffset) const { return (((now - mPhase) / mPeriod) + periodOffset + 1) * mPeriod + mPhase; } +void DispSync::dump(String8& result) const { + Mutex::Autolock lock(mMutex); + result.appendFormat("mPeriod: %"PRId64" ns\n", mPeriod); + result.appendFormat("mPhase: %"PRId64" ns\n", mPhase); + result.appendFormat("mError: %"PRId64" ns (sqrt: %.1f)\n", + mError, sqrt(mError)); + result.appendFormat("mNumResyncSamplesSincePresent: %d (max %d)\n", + mNumResyncSamplesSincePresent, MAX_RESYNC_SAMPLES_WITHOUT_PRESENT); + result.appendFormat("mNumResyncSamples: %d (max %d)\n", + mNumResyncSamples, MAX_RESYNC_SAMPLES); + + result.appendFormat("mResyncSamples:\n"); + nsecs_t previous = -1; + for (size_t i = 0; i < mNumResyncSamples; i++) { + size_t idx = (mFirstResyncSample + i) % MAX_RESYNC_SAMPLES; + nsecs_t sampleTime = mResyncSamples[idx]; + if (i == 0) { + result.appendFormat(" %"PRId64"\n", sampleTime); + } else { + result.appendFormat(" %"PRId64" (+%"PRId64")\n", + sampleTime, sampleTime - previous); + } + previous = sampleTime; + } + + result.appendFormat("mPresentFences / mPresentTimes [%d]:\n", + NUM_PRESENT_SAMPLES); + previous = 0; + for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) { + size_t idx = (i + mPresentSampleOffset) % NUM_PRESENT_SAMPLES; + bool signaled = mPresentFences[idx] == NULL; + nsecs_t presentTime = mPresentTimes[idx]; + if (!signaled) { + result.appendFormat(" [unsignaled fence]\n"); + } else if (previous == 0) { + result.appendFormat(" %"PRId64"\n", presentTime); + } else { + result.appendFormat(" %"PRId64" (+%"PRId64" / %.3f)\n", + presentTime, presentTime - previous, + (presentTime - previous) / (double) mPeriod); + } + previous = presentTime; + } +} + } // namespace android diff --git a/services/surfaceflinger/DispSync.h b/services/surfaceflinger/DispSync.h index 5826a785cd..a33ce5d8b0 100644 --- a/services/surfaceflinger/DispSync.h +++ b/services/surfaceflinger/DispSync.h @@ -108,6 +108,9 @@ public: // the refresh after next. etc. nsecs_t computeNextRefresh(int periodOffset) const; + // dump appends human-readable debug info to the result string. + void dump(String8& result) const; + private: void updateModelLocked(); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 7bd8d38184..4a52284884 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2228,6 +2228,13 @@ status_t SurfaceFlinger::dump(int fd, const Vector& args) clearStatsLocked(args, index, result); dumpAll = false; } + + if ((index < numArgs) && + (args[index] == String16("--dispsync"))) { + index++; + mPrimaryDispSync.dump(result); + dumpAll = false; + } } if (dumpAll) { diff --git a/services/surfaceflinger/main_surfaceflinger.cpp b/services/surfaceflinger/main_surfaceflinger.cpp index b161480b3e..90e3f7de9e 100644 --- a/services/surfaceflinger/main_surfaceflinger.cpp +++ b/services/surfaceflinger/main_surfaceflinger.cpp @@ -27,7 +27,7 @@ using namespace android; -int main(int argc, char** argv) { +int main(int, char**) { // When SF is launched in its own process, limit the number of // binder threads to 4. ProcessState::self()->setThreadPoolMaxThreadCount(4); -- cgit v1.2.3-59-g8ed1b