From 712eae053ccc6e91298a8430208cdc846cd42145 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 1 Oct 2021 15:24:27 -0400 Subject: [PATCH] Support dump gfxinfo reset for process' without a Window Bug: 199791928 Test: manual Change-Id: I995d236c2c9d60194f72275a3da1c82340f77898 --- core/java/android/app/ActivityThread.java | 4 +-- core/java/android/view/ThreadedRenderer.java | 22 ++++++++---- core/jni/android_app_ActivityThread.cpp | 9 ----- .../android/graphics/HardwareRenderer.java | 9 +++++ libs/hwui/Android.bp | 1 - .../include/android/graphics/renderthread.h | 34 ------------------- libs/hwui/apex/renderthread.cpp | 25 -------------- .../jni/android_graphics_HardwareRenderer.cpp | 9 +++++ libs/hwui/libhwui.map.txt | 3 +- libs/hwui/renderthread/RenderProxy.cpp | 9 +++-- libs/hwui/renderthread/RenderProxy.h | 3 +- 11 files changed, 45 insertions(+), 83 deletions(-) delete mode 100644 libs/hwui/apex/include/android/graphics/renderthread.h delete mode 100644 libs/hwui/apex/renderthread.cpp diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index f1fd8b7c035b1..6353977e724a0 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4578,8 +4578,7 @@ public final class ActivityThread extends ClientTransactionHandler private void handleDumpGfxInfo(DumpComponentInfo info) { try { - nDumpGraphicsInfo(info.fd.getFileDescriptor()); - WindowManagerGlobal.getInstance().dumpGfxInfo(info.fd.getFileDescriptor(), info.args); + ThreadedRenderer.handleDumpGfxInfo(info.fd.getFileDescriptor(), info.args); } catch (Exception e) { Log.w(TAG, "Caught exception from dumpGfxInfo()", e); } finally { @@ -7905,6 +7904,5 @@ public final class ActivityThread extends ClientTransactionHandler // ------------------ Regular JNI ------------------------ private native void nPurgePendingResources(); - private native void nDumpGraphicsInfo(FileDescriptor fd); private native void nInitZygoteChildHeapProfiling(); } diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java index bee0709556e74..7af77ca263fef 100644 --- a/core/java/android/view/ThreadedRenderer.java +++ b/core/java/android/view/ThreadedRenderer.java @@ -609,11 +609,7 @@ public final class ThreadedRenderer extends HardwareRenderer { return mHeight; } - /** - * Outputs extra debugging information in the specified file descriptor. - */ - void dumpGfxInfo(PrintWriter pw, FileDescriptor fd, String[] args) { - pw.flush(); + private static int dumpArgsToFlags(String[] args) { // If there's no arguments, eg 'dumpsys gfxinfo', then dump everything. // If there's a targetted package, eg 'dumpsys gfxinfo com.android.systemui', then only // dump the summary information @@ -631,7 +627,21 @@ public final class ThreadedRenderer extends HardwareRenderer { break; } } - dumpProfileInfo(fd, flags); + return flags; + } + + /** @hide */ + public static void handleDumpGfxInfo(FileDescriptor fd, String[] args) { + dumpGlobalProfileInfo(fd, dumpArgsToFlags(args)); + WindowManagerGlobal.getInstance().dumpGfxInfo(fd, args); + } + + /** + * Outputs extra debugging information in the specified file descriptor. + */ + void dumpGfxInfo(PrintWriter pw, FileDescriptor fd, String[] args) { + pw.flush(); + dumpProfileInfo(fd, dumpArgsToFlags(args)); } Picture captureRenderingCommands() { diff --git a/core/jni/android_app_ActivityThread.cpp b/core/jni/android_app_ActivityThread.cpp index e9d9a20c7538f..e25ba76cbbeb6 100644 --- a/core/jni/android_app_ActivityThread.cpp +++ b/core/jni/android_app_ActivityThread.cpp @@ -21,7 +21,6 @@ #include #include -#include namespace android { @@ -30,12 +29,6 @@ static void android_app_ActivityThread_purgePendingResources(JNIEnv* env, jobjec mallopt(M_PURGE, 0); } -static void -android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { - int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); - ARenderThread_dumpGraphicsMemory(fd); -} - static void android_app_ActivityThread_initZygoteChildHeapProfiling(JNIEnv* env, jobject clazz) { android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0); } @@ -44,8 +37,6 @@ static JNINativeMethod gActivityThreadMethods[] = { // ------------ Regular JNI ------------------ { "nPurgePendingResources", "()V", (void*) android_app_ActivityThread_purgePendingResources }, - { "nDumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", - (void*) android_app_ActivityThread_dumpGraphics }, { "nInitZygoteChildHeapProfiling", "()V", (void*) android_app_ActivityThread_initZygoteChildHeapProfiling } }; diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java index abdf1a25f29d9..2b18350460726 100644 --- a/graphics/java/android/graphics/HardwareRenderer.java +++ b/graphics/java/android/graphics/HardwareRenderer.java @@ -820,6 +820,13 @@ public class HardwareRenderer { return nLoadSystemProperties(mNativeProxy); } + /** + * @hide + */ + public static void dumpGlobalProfileInfo(FileDescriptor fd, @DumpFlags int dumpFlags) { + nDumpGlobalProfileInfo(fd, dumpFlags); + } + /** * @hide */ @@ -1390,6 +1397,8 @@ public class HardwareRenderer { private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd, @DumpFlags int dumpFlags); + private static native void nDumpGlobalProfileInfo(FileDescriptor fd, @DumpFlags int dumpFlags); + private static native void nAddRenderNode(long nativeProxy, long rootRenderNode, boolean placeFront); diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index b931d030f2a02..fea1e15a52603 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -272,7 +272,6 @@ cc_defaults { "apex/android_bitmap.cpp", "apex/android_canvas.cpp", "apex/jni_runtime.cpp", - "apex/renderthread.cpp", ], }, host: { diff --git a/libs/hwui/apex/include/android/graphics/renderthread.h b/libs/hwui/apex/include/android/graphics/renderthread.h deleted file mode 100644 index 50280a6dd1fbd..0000000000000 --- a/libs/hwui/apex/include/android/graphics/renderthread.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef ANDROID_GRAPHICS_RENDERTHREAD_H -#define ANDROID_GRAPHICS_RENDERTHREAD_H - -#include -#include - -__BEGIN_DECLS - -/** - * Dumps a textual representation of the graphics stats for this process. - * @param fd The file descriptor that the available graphics stats will be appended to. The - * function requires a valid fd, but does not persist or assume ownership of the fd - * outside the scope of this function. - */ -ANDROID_API void ARenderThread_dumpGraphicsMemory(int fd); - -__END_DECLS - -#endif // ANDROID_GRAPHICS_RENDERTHREAD_H diff --git a/libs/hwui/apex/renderthread.cpp b/libs/hwui/apex/renderthread.cpp deleted file mode 100644 index 5d26afe7a2aba..0000000000000 --- a/libs/hwui/apex/renderthread.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "android/graphics/renderthread.h" - -#include - -using namespace android; - -void ARenderThread_dumpGraphicsMemory(int fd) { - uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd); -} diff --git a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp index e536950d0d041..bd93a4f9b8a5c 100644 --- a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp +++ b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp @@ -379,6 +379,13 @@ static void android_view_ThreadedRenderer_dumpProfileInfo(JNIEnv* env, jobject c proxy->dumpProfileInfo(fd, dumpFlags); } +static void android_view_ThreadedRenderer_dumpGlobalProfileInfo(JNIEnv* env, jobject clazz, + jobject javaFileDescriptor, + jint dumpFlags) { + int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); + RenderProxy::dumpGraphicsMemory(fd, true, dumpFlags & DumpFlags::Reset); +} + static void android_view_ThreadedRenderer_addRenderNode(JNIEnv* env, jobject clazz, jlong proxyPtr, jlong renderNodePtr, jboolean placeFront) { RenderProxy* proxy = reinterpret_cast(proxyPtr); @@ -910,6 +917,8 @@ static const JNINativeMethod gMethods[] = { {"nNotifyFramePending", "(J)V", (void*)android_view_ThreadedRenderer_notifyFramePending}, {"nDumpProfileInfo", "(JLjava/io/FileDescriptor;I)V", (void*)android_view_ThreadedRenderer_dumpProfileInfo}, + {"nDumpGlobalProfileInfo", "(Ljava/io/FileDescriptor;I)V", + (void*)android_view_ThreadedRenderer_dumpGlobalProfileInfo}, {"setupShadersDiskCache", "(Ljava/lang/String;Ljava/lang/String;)V", (void*)android_view_ThreadedRenderer_setupShadersDiskCache}, {"nAddRenderNode", "(JJZ)V", (void*)android_view_ThreadedRenderer_addRenderNode}, diff --git a/libs/hwui/libhwui.map.txt b/libs/hwui/libhwui.map.txt index 77b8a44d85a14..087c006a86801 100644 --- a/libs/hwui/libhwui.map.txt +++ b/libs/hwui/libhwui.map.txt @@ -1,4 +1,4 @@ -LIBHWUI { +LIBHWUI { # platform-only /* HWUI isn't current a module, so all of these are still platform-only */ global: /* listing of all C APIs to be exposed by libhwui to consumers outside of the module */ ABitmap_getInfoFromJava; @@ -39,7 +39,6 @@ LIBHWUI { ARegionIterator_next; ARegionIterator_getRect; ARegionIterator_getTotalBounds; - ARenderThread_dumpGraphicsMemory; local: *; }; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 72d4ac5081e6c..430c4d3321b93 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -257,10 +257,15 @@ uint32_t RenderProxy::frameTimePercentile(int percentile) { }); } -void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData) { +void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData, bool resetProfile) { if (RenderThread::hasInstance()) { auto& thread = RenderThread::getInstance(); - thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd, includeProfileData); }); + thread.queue().runSync([&]() { + thread.dumpGraphicsMemory(fd, includeProfileData); + if (resetProfile) { + thread.globalProfileData()->reset(); + } + }); } } diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 6417b38df064a..6d46be4b07397 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -108,7 +108,8 @@ public: // Not exported, only used for testing void resetProfileInfo(); uint32_t frameTimePercentile(int p); - static void dumpGraphicsMemory(int fd, bool includeProfileData = true); + static void dumpGraphicsMemory(int fd, bool includeProfileData = true, + bool resetProfile = false); static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage); static void rotateProcessStatsBuffer();