clean-up/simplify all dump() APIs
remove the scratch buffer parameter and use
String8::appendFormat() instead.
Change-Id: Ib96c91617c8e7292de87433d15cf6232b7d591b0
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 68b0b7f..42b30cc 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -424,9 +424,9 @@
mFrame = frame;
}
-void DisplayDevice::dump(String8& result, char* buffer, size_t SIZE) const {
+void DisplayDevice::dump(String8& result) const {
const Transform& tr(mGlobalTransform);
- snprintf(buffer, SIZE,
+ result.appendFormat(
"+ DisplayDevice: %s\n"
" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
"flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%u\n"
@@ -443,8 +443,6 @@
tr[0][1], tr[1][1], tr[2][1],
tr[0][2], tr[1][2], tr[2][2]);
- result.append(buffer);
-
String8 surfaceDump;
mDisplaySurface->dump(surfaceDump);
result.append(surfaceDump);
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index 377d924..047eecd 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -153,7 +153,7 @@
* Debugging
*/
uint32_t getPageFlipCount() const;
- void dump(String8& result, char* buffer, size_t SIZE) const;
+ void dump(String8& result) const;
private:
/*
diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp
index 54a3ce8..8b454ce 100644
--- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp
+++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp
@@ -175,11 +175,10 @@
ConsumerBase::dump(result);
}
-void FramebufferSurface::dumpLocked(String8& result, const char* prefix,
- char* buffer, size_t SIZE) const
+void FramebufferSurface::dumpLocked(String8& result, const char* prefix) const
{
mHwc.fbDump(result);
- ConsumerBase::dumpLocked(result, prefix, buffer, SIZE);
+ ConsumerBase::dumpLocked(result, prefix);
}
// ----------------------------------------------------------------------------
diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h
index 2fde789..c86e9ae 100644
--- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h
+++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h
@@ -55,8 +55,7 @@
virtual void onFrameAvailable();
virtual void freeBufferLocked(int slotIndex);
- virtual void dumpLocked(String8& result, const char* prefix,
- char* buffer, size_t SIZE) const;
+ virtual void dumpLocked(String8& result, const char* prefix) const;
// nextBuffer waits for and then latches the next buffer from the
// BufferQueue and releases the previously latched buffer to the
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 3f00f07..6bdccb9 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -546,9 +546,6 @@
// triggers a Surface::queueBuffer() on some
// devices (!?) -- log and ignore.
ALOGE("HWComposer: framebufferTarget is null");
-// CallStack stack;
-// stack.update();
-// stack.dump("");
return NO_ERROR;
}
@@ -958,7 +955,7 @@
return getLayerIterator(id, numLayers);
}
-void HWComposer::dump(String8& result, char* buffer, size_t SIZE) const {
+void HWComposer::dump(String8& result) const {
if (mHwc) {
result.appendFormat("Hardware Composer state (version %8x):\n", hwcApiVersion(mHwc));
result.appendFormat(" mDebugForceFakeVSync=%d\n", mDebugForceFakeVSync);
@@ -1026,6 +1023,8 @@
}
if (mHwc && mHwc->dump) {
+ const size_t SIZE = 4096;
+ char buffer[SIZE];
mHwc->dump(mHwc, buffer, SIZE);
result.append(buffer);
}
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index 604de38..a20da08 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -275,7 +275,7 @@
friend class VSyncThread;
// for debugging ----------------------------------------------------------
- void dump(String8& out, char* scratch, size_t SIZE) const;
+ void dump(String8& out) const;
private:
void loadHwcModule();
diff --git a/services/surfaceflinger/EventThread.cpp b/services/surfaceflinger/EventThread.cpp
index 4d0fc79..4126c8a 100644
--- a/services/surfaceflinger/EventThread.cpp
+++ b/services/surfaceflinger/EventThread.cpp
@@ -320,7 +320,7 @@
mDebugVsyncEnabled = false;
}
-void EventThread::dump(String8& result, char* buffer, size_t SIZE) const {
+void EventThread::dump(String8& result) const {
Mutex::Autolock _l(mLock);
result.appendFormat("VSYNC state: %s\n",
mDebugVsyncEnabled?"enabled":"disabled");
diff --git a/services/surfaceflinger/EventThread.h b/services/surfaceflinger/EventThread.h
index 1934f98..f6bd676 100644
--- a/services/surfaceflinger/EventThread.h
+++ b/services/surfaceflinger/EventThread.h
@@ -84,7 +84,7 @@
Vector< sp<EventThread::Connection> > waitForEvent(
DisplayEventReceiver::Event* event);
- void dump(String8& result, char* buffer, size_t SIZE) const;
+ void dump(String8& result) const;
private:
virtual bool threadLoop();
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 4779804..91113c9 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1178,21 +1178,19 @@
// debugging
// ----------------------------------------------------------------------------
-void Layer::dump(String8& result, char* buffer, size_t SIZE) const
+void Layer::dump(String8& result) const
{
const Layer::State& s(drawingState());
- snprintf(buffer, SIZE,
+ result.appendFormat(
"+ %s %p (%s)\n",
getTypeId(), this, getName().string());
- result.append(buffer);
s.activeTransparentRegion.dump(result, "transparentRegion");
visibleRegion.dump(result, "visibleRegion");
sp<Client> client(mClientRef.promote());
- snprintf(buffer, SIZE,
- " "
+ result.appendFormat( " "
"layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
"isOpaque=%1d, invalidate=%1d, "
"alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n"
@@ -1205,7 +1203,6 @@
s.transform[0][0], s.transform[0][1],
s.transform[1][0], s.transform[1][1],
client.get());
- result.append(buffer);
sp<const GraphicBuffer> buf0(mActiveBuffer);
uint32_t w0=0, h0=0, s0=0, f0=0;
@@ -1215,26 +1212,24 @@
s0 = buf0->getStride();
f0 = buf0->format;
}
- snprintf(buffer, SIZE,
+ result.appendFormat(
" "
"format=%2d, activeBuffer=[%4ux%4u:%4u,%3X],"
" queued-frames=%d, mRefreshPending=%d\n",
mFormat, w0, h0, s0,f0,
mQueuedFrames, mRefreshPending);
- result.append(buffer);
-
if (mSurfaceFlingerConsumer != 0) {
- mSurfaceFlingerConsumer->dump(result, " ", buffer, SIZE);
+ mSurfaceFlingerConsumer->dump(result, " ");
}
}
-void Layer::shortDump(String8& result, char* scratch, size_t size) const {
- Layer::dump(result, scratch, size);
+void Layer::shortDump(String8& result) const {
+ Layer::dump(result);
}
-void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const {
+void Layer::dumpStats(String8& result) const {
mFrameTracker.dump(result);
}
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 2765db1..2c06f1a 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -304,9 +304,9 @@
/* always call base class first */
- virtual void dump(String8& result, char* scratch, size_t size) const;
- virtual void shortDump(String8& result, char* scratch, size_t size) const;
- virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
+ virtual void dump(String8& result) const;
+ virtual void shortDump(String8& result) const;
+ virtual void dumpStats(String8& result) const;
virtual void clearStats();
protected:
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e647275..dc73fe7 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2141,19 +2141,15 @@
status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
{
- const size_t SIZE = 4096;
- char buffer[SIZE];
String8 result;
-
IPCThreadState* ipc = IPCThreadState::self();
const int pid = ipc->getCallingPid();
const int uid = ipc->getCallingUid();
if ((uid != AID_SHELL) &&
!PermissionCache::checkPermission(sDump, pid, uid)) {
- snprintf(buffer, SIZE, "Permission Denial: "
+ result.appendFormat("Permission Denial: "
"can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid);
- result.append(buffer);
} else {
// Try to get the main lock, but don't insist if we can't
// (this would indicate SF is stuck, but we want to be able to
@@ -2164,10 +2160,9 @@
}
const bool locked(retry >= 0);
if (!locked) {
- snprintf(buffer, SIZE,
+ result.append(
"SurfaceFlinger appears to be unresponsive, "
"dumping anyways (no locks held)\n");
- result.append(buffer);
}
bool dumpAll = true;
@@ -2177,27 +2172,27 @@
if ((index < numArgs) &&
(args[index] == String16("--list"))) {
index++;
- listLayersLocked(args, index, result, buffer, SIZE);
+ listLayersLocked(args, index, result);
dumpAll = false;
}
if ((index < numArgs) &&
(args[index] == String16("--latency"))) {
index++;
- dumpStatsLocked(args, index, result, buffer, SIZE);
+ dumpStatsLocked(args, index, result);
dumpAll = false;
}
if ((index < numArgs) &&
(args[index] == String16("--latency-clear"))) {
index++;
- clearStatsLocked(args, index, result, buffer, SIZE);
+ clearStatsLocked(args, index, result);
dumpAll = false;
}
}
if (dumpAll) {
- dumpAllLocked(result, buffer, SIZE);
+ dumpAllLocked(args, index, result);
}
if (locked) {
@@ -2209,19 +2204,18 @@
}
void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE) const
+ String8& result) const
{
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
const size_t count = currentLayers.size();
for (size_t i=0 ; i<count ; i++) {
const sp<Layer>& layer(currentLayers[i]);
- snprintf(buffer, SIZE, "%s\n", layer->getName().string());
- result.append(buffer);
+ result.appendFormat("%s\n", layer->getName().string());
}
}
void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE) const
+ String8& result) const
{
String8 name;
if (index < args.size()) {
@@ -2241,14 +2235,14 @@
for (size_t i=0 ; i<count ; i++) {
const sp<Layer>& layer(currentLayers[i]);
if (name == layer->getName()) {
- layer->dumpStats(result, buffer, SIZE);
+ layer->dumpStats(result);
}
}
}
}
void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE)
+ String8& result)
{
String8 name;
if (index < args.size()) {
@@ -2288,8 +2282,8 @@
result.append(config);
}
-void SurfaceFlinger::dumpAllLocked(
- String8& result, char* buffer, size_t SIZE) const
+void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index,
+ String8& result) const
{
// figure out if we're stuck somewhere
const nsecs_t now = systemTime();
@@ -2316,56 +2310,46 @@
*/
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
const size_t count = currentLayers.size();
- snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count);
- result.append(buffer);
+ result.appendFormat("Visible layers (count = %d)\n", count);
for (size_t i=0 ; i<count ; i++) {
const sp<Layer>& layer(currentLayers[i]);
- layer->dump(result, buffer, SIZE);
+ layer->dump(result);
}
/*
* Dump Display state
*/
- snprintf(buffer, SIZE, "Displays (%d entries)\n", mDisplays.size());
- result.append(buffer);
+ result.appendFormat("Displays (%d entries)\n", mDisplays.size());
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
const sp<const DisplayDevice>& hw(mDisplays[dpy]);
- hw->dump(result, buffer, SIZE);
+ hw->dump(result);
}
/*
* Dump SurfaceFlinger global state
*/
- snprintf(buffer, SIZE, "SurfaceFlinger global state:\n");
- result.append(buffer);
+ result.append("SurfaceFlinger global state:\n");
HWComposer& hwc(getHwComposer());
sp<const DisplayDevice> hw(getDefaultDisplayDevice());
const GLExtensions& extensions(GLExtensions::getInstance());
- snprintf(buffer, SIZE, "EGL implementation : %s\n",
- eglQueryStringImplementationANDROID(mEGLDisplay, EGL_VERSION));
- result.append(buffer);
- snprintf(buffer, SIZE, "%s\n",
+ result.appendFormat("EGL implementation : %s\n%s\n",
+ eglQueryStringImplementationANDROID(mEGLDisplay, EGL_VERSION),
eglQueryStringImplementationANDROID(mEGLDisplay, EGL_EXTENSIONS));
- result.append(buffer);
- snprintf(buffer, SIZE, "GLES: %s, %s, %s\n",
+ result.appendFormat("GLES: %s, %s, %s\n",
extensions.getVendor(),
extensions.getRenderer(),
extensions.getVersion());
- result.append(buffer);
- snprintf(buffer, SIZE, "%s\n", extensions.getExtension());
- result.append(buffer);
+ result.appendFormat("%s\n", extensions.getExtension());
hw->undefinedRegion.dump(result, "undefinedRegion");
- snprintf(buffer, SIZE,
- " orientation=%d, canDraw=%d\n",
+ result.appendFormat(" orientation=%d, canDraw=%d\n",
hw->getOrientation(), hw->canDraw());
- result.append(buffer);
- snprintf(buffer, SIZE,
+ result.appendFormat(
" last eglSwapBuffers() time: %f us\n"
" last transaction time : %f us\n"
" transaction-flags : %08x\n"
@@ -2383,31 +2367,26 @@
hwc.getDpiY(HWC_DISPLAY_PRIMARY),
mEGLNativeVisualId,
!mGpuToCpuSupported);
- result.append(buffer);
- snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
+ result.appendFormat(" eglSwapBuffers time: %f us\n",
inSwapBuffersDuration/1000.0);
- result.append(buffer);
- snprintf(buffer, SIZE, " transaction time: %f us\n",
+ result.appendFormat(" transaction time: %f us\n",
inTransactionDuration/1000.0);
- result.append(buffer);
/*
* VSYNC state
*/
- mEventThread->dump(result, buffer, SIZE);
+ mEventThread->dump(result);
/*
* Dump HWComposer state
*/
- snprintf(buffer, SIZE, "h/w composer state:\n");
- result.append(buffer);
- snprintf(buffer, SIZE, " h/w composer %s and %s\n",
+ result.append("h/w composer state:\n");
+ result.appendFormat(" h/w composer %s and %s\n",
hwc.initCheck()==NO_ERROR ? "present" : "not present",
(mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled");
- result.append(buffer);
- hwc.dump(result, buffer, SIZE);
+ hwc.dump(result);
/*
* Dump gralloc state
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 739099c..d387a60 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -385,12 +385,13 @@
* Debugging & dumpsys
*/
void listLayersLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE) const;
+ String8& result) const;
void dumpStatsLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE) const;
+ String8& result) const;
void clearStatsLocked(const Vector<String16>& args, size_t& index,
- String8& result, char* buffer, size_t SIZE);
- void dumpAllLocked(String8& result, char* buffer, size_t SIZE) const;
+ String8& result);
+ void dumpAllLocked(const Vector<String16>& args, size_t& index,
+ String8& result) const;
bool startDdmConnection();
static void appendSfConfigString(String8& result);