android system traceview 和 hierarchy view

来源:互联网 发布:店铺如何关闭淘宝客 编辑:程序博客网 时间:2024/06/05 00:28

一、进行真机查看 hierarchy view步骤

1、首先集成 viewserver  代码到我们的项目中

2、在我们的工程的 Activity界面的 oncreate 和 ondestroy中  执行注册页面监听和注销页面监听动作

在进行切换到 android devices monitor中经常会需要在 dos命令行中执行  adb kill-server  adb start server  才可以发现我们的应用启动

3、设置环境变量 ANDROID_HVPRORO = .ddm

注意出来了 hierarchy view视图之后,,看到红点的,按  profile node按钮查看 具体的渲染绘制所耗时间


比较好的搜索方法,,,非常经典!!!!!!!!!!!!!!

通过view 的 id关键字搜索我们的想要查找的view在具体哪个地方,,,,

通过右上角的缩小页面,可以快速查看我们的所有view所在



常见问题

1、用relativelayout或者gridlayout来代替 两层linearlayout,,,但是单层的relativelayout每次渲染总是会有measure两次,linearlayout如果没有weight属性设置,也会比较快渲染

2、尽量少用weight属性,,,特殊情况除外

3、用merge标签来代替单独根布局是framelayout的形式

4、 用viewstub布局来进行占位,但是不渲染,用于 默认图的显示等

5、用include布局来复用布局

------------------------------------------------------------------------------------------------------------------------------------------------------------------

DDMS 中 android devices monitor 进行start profiling   和 stop  profiling

android  studio 中CPU  start method tracing  和 stop method tracing

然后点击进入页面,将生成的文件放到 ddms中


注意trace分析

include cpu time  cpu时间  父 + 子

exclu cpu time  real time   cpu时间  父

重要指标

include real time  方法执行时间  父 + 子

exclu real time  方法自身执行时间 父

重要指标

cpu time call 平均每次调用占用cpu时间  

real time call  平均每次调用所执行时间

重要指标

call + recure calls /total  递归调用和总时间调用  

======================================================================================================

通过 方法占用时间     和     调用次数两个  来分别查看,,,一般是 方法占用时间多,或者方法本身占用时间少,但是调用次数多两种情况导致渲染时间长

(解决过问题 某个聊天监听的注册和注销时间耗时问题,,,以及 recyclerview中的linearlayoutmanager中的onmeasure方法中每个子view重复调用问题(本来可以只调用一次的))

每个查看可以通过 cpu时间占比,找到最耗时的那个方法是哪个,之后再进行优化动作。


可以用intentserver进行优化启动时间,将耗时长的方法放到子线程中。
















0 0
原创粉丝点击