赞
踩
解析Hprof文件
1.安装MemoryAnalyzer-1.15.0.20231206-win32.win32.x86_64
2.打开报错:Version1.8.0 of the jvm is not suitable for this product,Version17 or greater isrequired
配置java位置
MemoryAnalyzer.ini文件中添加:
-vm
C:Files
3.打开从设备中pull出的hprof文件报错:Unknown HPROF Version (JAVA PROFILE 1.0.3)
需要使用C:-tools下工具hprof-conv.exe
4.cmd到此目录下运行以下命令
hprof-conv aa.hprof bb.hprof
aa.hprof指需要转换的文件
bb.hprof转换完成之后生成的文件
5.使用MAT打开转化生成hprof文件
5.Objects表示这个类对应的对象数量
Shallow Heap:表示该对象在没有引用其他对象,它自己本身的大小
Retained Heap:表示该对象自己本身的大小再加上该对象直接或者间接引用的对象的大小总和
(一般操作是点击Objects按照数量排序,然后check Shallow Heap大小)
6.点击怀疑的类
设备压测MTBF发生OutOfResourcesException,设备发生重启
从log中可以看到是Layer创建过多导致的OutOfResourcesException
MFC42EE 04-24 06:41:16.322 732 732 W SurfaceFlinger: Too many open layers, may layer leak!
MFC42F8 04-24 06:41:16.322 732 732 W SurfaceFlinger: Dump layers:[3722], Leaf:15:36#258, parent layer = Display 2 name="rtc_screen"#252
>>> 33034 hits
MFC42F9 04-24 06:41:16.322 732 732 W SurfaceFlinger: Dump layers:[3722], WindowToken{709375f type=2032 android.os.Binder@e95b3fe}#1323, parent layer = Leaf:15:36#258
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: Unhandled exception in Window Manager
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: android.view.Surface$OutOfResourcesException
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: at android.view.SurfaceControl.nativeCreate(Native Method)
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: at android.view.SurfaceControl.<init>(SurfaceControl.java:1569)
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: at android.view.SurfaceControl.<init>(Unknown Source:0)
S17EEEA 04-24 08:02:54.162 1092 1131 E WindowManager: at android.view.SurfaceControl$Builder.build(SurfaceControl.java:1243)
1.怀疑可能是Surface的创建和销毁存在异常
(由于该问题只会在user版本上复现,userdebug版本上面不会复现到,因此需要添加log打印
debug版本可以查看wmtrace文件,文件位置:\data\misc\wmtrace)
Q:\SPRO_T\SPRDROID13_MAIN_W22.xx.x\idh.code\frameworks\base\services\core\java\com\android\server\wm\WindowStateAnimator.java WindowSurfaceController createSurfaceLocked() 方法中 添加create ProtoLog.i(WM_SHOW_SURFACE_ALLOC, " CREATE SURFACE %s IN SESSION %s: pid=%d format=%d flags=0x%x / %s", mSurfaceController, mSession.mSurfaceSession, mSession.mPid, attrs.format, flags, this); 添加destory Q:\SPRO_T\SPRDROID13_MAIN_W22.xx.x\idh.code\frameworks\base\services\core\java\com\android\server\wm\WindowSurfaceController.java void destroy(SurfaceControl.Transaction t) { ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "Destroying surface %s called by %s", this, Debug.getCallers(8)); if (Build.IS_USERDEBUG) { Slog.d(TAG, "Destroying surface, this = " + this + ", called by :" + Debug.getCallers(8)); } try { if (mSurfaceControl != null) { t.remove(mSurfaceControl); } } catch (RuntimeException e) { Slog.w(TAG, "Error destroying surface in: " + this, e); } finally { setShown(false); mSurfaceControl = null; } }
复现问题后查看log,create和destory对应,该怀疑点排除。
2.查看hprof文件,根据报错堆栈查看android.view.SurfaceControl$Transaction的引用对象,怀疑同mWindowMap相关
添加打印log
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 0a80d29f750f..9536a84ac8d2 100755 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1567,6 +1567,7 @@ public class DisplayContent extends RootDisplayArea implements WindowManagerPoli } mTokenMap.put(binder, token); + Log.e(TAG, "addWindowToken mTokenMap add display=" + getName() + " binder=" + binder + " token=" + token); if (token.asActivityRecord() == null) { // Set displayContent for non-app token to prevent same token will add twice after @@ -1583,6 +1584,7 @@ public class DisplayContent extends RootDisplayArea implements WindowManagerPoli WindowToken removeWindowToken(IBinder binder, boolean animateExit) { final WindowToken token = mTokenMap.remove(binder); + Log.e(TAG, "removeWindowToken mTokenMap remove display=" + getName() + " binder=" + binder + " token=" + token); if (token != null && token.asActivityRecord() == null) { token.setExiting(animateExit); } @@ -1645,9 +1647,12 @@ public class DisplayContent extends RootDisplayArea implements WindowManagerPoli return; } if (prevDc != null) { - if (prevDc.mTokenMap.remove(token.token) != null && token.asActivityRecord() == null) { + if (prevDc.mTokenMap.remove(token.token) == null) { + Log.w(TAG, "reParentWindowToken mTokenMap remove = null display=" + getName() + " prevDc=" + prevDc + " token=" + token + " token.token=" + token.token); + } else if (prevDc.mTokenMap.remove(token.token) != null && token.asActivityRecord() == null) { // Removed the token from the map, but made sure it's not an app token before // removing from parent. + Log.w(TAG, "reParentWindowToken mTokenMap remove != null display=" + getName() + " prevDc=" + prevDc + " token=" + token + " token.token=" + token.token); token.getParent().removeChild(token); } }
最终定位到一个mTokenMap只有add没有remove,推动三方应用进行修改。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。