(两百五十八)以perfetto的视角观察flutter的加载

1.抓取trace

使用https://blog.csdn.net/sinat_20059415/article/details/106307905中网页抓取方式抓取trace

对应trace https://download.csdn.net/download/sinat_20059415/12452943

 

2.简要分析

测试flutter还是之前写的https://blog.csdn.net/sinat_20059415/article/details/105920254#t4里的app

        mCurrentUserId=0
        Current looper: Looper (android.ui, tid=1671)
      mCurrentUserId=0
  mCurrentFocus=Window{40b2a2c u0 com.example.flutterlayouttest/com.example.flutterlayouttest.MainActivity}
    mCurrent=[0,96][1080,2340]
        Current looper: Looper (android.ui, tid=1671)
    mCurrentAppOrientation=SCREEN_ORIENTATION_UNSPECIFIED
      mCurrentRotation=ROTATION_0

对应的包名是com.example.flutterlayouttest

2.1 线程

可以看到flutter包含了很多线程,具体用命令看一下

参考https://blog.csdn.net/sinat_20059415/article/details/94127428#t4

ps -AfT

raphael:/ # ps -AfT | grep flutter
u0_a234      27992 27992   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 27998   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28003   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28004   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28005   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28006   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28007   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28008   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28009   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28010   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28011   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28013   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28014   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28016   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28019   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28020   674   31 09:47:25 ?     00:00:01 com.example.flutterlayouttest
u0_a234      27992 28021   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28022   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28023   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28024   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28025   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28026   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28027   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28028   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28029   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28030   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28031   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28034   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28035   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28036   674   31 09:47:25 ?     00:00:00 com.example.flutterlayouttest
u0_a234      27992 28307   674   31 09:49:59 ?     00:00:00 com.example.flutterlayouttest

更优雅的命令应该是加上-p pid

raphael:/ # ps -AfT -p 27992                                                                                                                                                                               
UID            PID   TID  PPID TCNT STIME TTY          TIME CMD
u0_a234      27992 27992   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 27998   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28003   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28004   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28005   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28006   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28007   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28008   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28009   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28010   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28011   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28013   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28014   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28016   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28019   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28020   674   31 47:24 ?        00:00:01 com.example.flutterlayouttest
u0_a234      27992 28021   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28022   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28023   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28024   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28025   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28026   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28027   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28028   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28029   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28030   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28031   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28034   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28035   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28036   674   31 47:24 ?        00:00:00 com.example.flutterlayouttest
u0_a234      27992 28307   674   31 49:58 ?        00:00:00 com.example.flutterlayouttest

贴上对应help

1|raphael:/ # ps --help
usage: ps [-AadefLlnwZ] [-gG GROUP,] [-k FIELD,] [-o FIELD,] [-p PID,] [-t TTY,] [-uU USER,]

List processes.

Which processes to show (-gGuUpPt selections may be comma separated lists):

-A  All                    -a  Has terminal not session leader
-d  All but session leaders        -e  Synonym for -A
-g  In GROUPs                -G  In real GROUPs (before sgid)
-p  PIDs (--pid)            -P  Parent PIDs (--ppid)
-s  In session IDs            -t  Attached to selected TTYs
-T  Show threads also            -u  Owned by selected USERs
-U  Real USERs (before suid)

Output modifiers:

-k  Sort FIELDs (-FIELD to reverse)    -M  Measure/pad future field widths
-n  Show numeric USER and GROUP        -w  Wide output (don't truncate fields)

Which FIELDs to show. (-o HELP for list, default = -o PID,TTY,TIME,CMD)

-f  Full listing (-o USER:12=UID,PID,PPID,C,STIME,TTY,TIME,ARGS=CMD)
-l  Long listing (-o F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD)
-o  Output FIELDs instead of defaults, each with optional :size and =title
-O  Add FIELDS to defaults
-Z  Include LABEL
 

一共是31个线程

raphael:/ # ps -AfT -p 27992|wc -l                                                                                                                                                                         
32

对比普通Android 计算器有17个线程

1|raphael:/ # ps -A | grep calcula                                                                                                                                                                         
u0_a220      28589   674 5293336 150952 SyS_epoll_wait      0 S com.miui.calculator
raphael:/ # ps -AfT -p 28589|wc -l                                                                                                                                                                         
18

 

2.2 加载流程

PostFork + ZygoteInit + ActivityThreadMain

bindApplication + activityStart

其中ResourcesManager#applyConfigurationToResourcesLocked

花了50ms,挺长的

activityStart花了100ms

activity resume

没看到绘制页面的相关堆栈呀。。。只看到有个叫做ui的线程,这个是干啥的。。。

这里显示启动花了394ms

systemserver显示加载应用花了378ms

surfaceflinge也看不出什么花来

应该是atrace的category设置的不对,以Settings的WiFi界面抓取trace

选上

            atrace_categories: "gfx"
            atrace_categories: "view"
            atrace_categories: "wm"
            atrace_categories: "am"
            atrace_categories: "rs"
            atrace_categories: "pm"

就好了

再次抓取

可以看到对应的布局都显示出来了,使用了线程布局 + ViewStub + Framelayout

activityResume后Choreographer#doFrame,包含熟悉的measure+layout + draw过程

渲染线程在下面

 

 

3.总结

flutter的启动后总线程数比一般Android应用多,达到31个

启动过程PostFork + ZygoteInit + ActivityThreadMain + bindApplication + activityStart + activityResume + Choreographer#doFrame(measure + layout + draw)

 

相关推荐
©️2020 CSDN 皮肤主题: 鲸 设计师:meimeiellie 返回首页