剖析Hprof文件
剖析Hprof文件1.安装MemoryAnalyzer-1.15.0.20231206-win32.win32.x86_64
https://img-blog.csdnimg.cn/direct/d013526134d84f53b7c5f386ee057b73.png
2.打开报错:Version1.8.0 of the jvm is not suitable for this product,Version17 or greater isrequired
https://img-blog.csdnimg.cn/direct/cd826912881c4869a3f16d5f088ec0c5.png
配置java位置
MemoryAnalyzer.ini文件中添加:
-vm
C:Files
3.打开从设备中pull出的hprof文件报错:Unknown HPROF Version (JAVA PROFILE 1.0.3)
需要利用C:-tools下工具hprof-conv.exe
4.cmd到此目录下运行以下下令
https://img-blog.csdnimg.cn/direct/b0028122cb2d456da6a39cec81eb28d7.png
hprof-conv aa.hprof bb.hprof
aa.hprof指需要转换的文件
bb.hprof转换完成之后生成的文件
5.利用MAT打开转化生成hprof文件
https://img-blog.csdnimg.cn/direct/937880a481bd42189765471079315e82.png
5.Objects体现这个类对应的对象数目
Shallow Heap:体现该对象在没有引用其他对象,它本身本身的大小
Retained Heap:体现该对象本身本身的大小再加上该对象直接或者间接引用的对象的大小总和
(一般操作是点击Objects按照数目排序,然后check Shallow Heap大小)
https://img-blog.csdnimg.cn/direct/a71e13c120a54f37b0db008a7b128ec4.png
6.点击怀疑的类
https://img-blog.csdnimg.cn/direct/513ad38c4089475b878c0c03e8e1500f.png
与此相关问题分析思路整理
设备压测MTBF发生OutOfResourcesException,设备发生重启
从log中可以看到是Layer创建过多导致的OutOfResourcesException
MFC42EE04-24 06:41:16.322 732 732 W SurfaceFlinger: Too many open layers, may layer leak!
MFC42F804-24 06:41:16.322 732 732 W SurfaceFlinger: Dump layers:, Leaf:15:36#258, parent layer = Display 2 name="rtc_screen"#252
>>> 33034 hits
MFC42F904-24 06:41:16.322 732 732 W SurfaceFlinger: Dump layers:, WindowToken{709375f type=2032 android.os.Binder@e95b3fe}#1323, parent layer = Leaf:15:36#258
S17EEEA04-24 08:02:54.16210921131 E WindowManager: Unhandled exception in Window Manager
S17EEEA04-24 08:02:54.16210921131 E WindowManager: android.view.Surface$OutOfResourcesException
S17EEEA04-24 08:02:54.16210921131 E WindowManager: at android.view.SurfaceControl.nativeCreate(Native Method)
S17EEEA04-24 08:02:54.16210921131 E WindowManager: at android.view.SurfaceControl.<init>(SurfaceControl.java:1569)
S17EEEA04-24 08:02:54.16210921131 E WindowManager: at android.view.SurfaceControl.<init>(Unknown Source:0)
S17EEEA04-24 08:02:54.16210921131 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相关
https://img-blog.csdnimg.cn/direct/f51b0322d6214b5cb5d01080980603cd.png
添加打印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,推动三方应用举行修改。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]