冷啓動
click event -> IPC -> Process.start -> ActivityThread -> bindApplication -> LifeCycle -> ViewRootImplhtml
熱啓動
後臺 -> 前臺android
溫啓動
Lifecycleshell
Application和Activity生命週期bash
adb shell am start -W packagename/首屏Activity(含有包名)
複製代碼
JamesdeMBP:~ zhanxuzhao$ adb shell am start -W com.example.demo_0227/com.example.demo_0227.SplashActivity
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.demo_0227/.SplashActivity }
Status: ok
Activity: com.example.demo_0227/.MainActivity
ThisTime: 123
TotalTime: 285
WaitTime: 304
Complete
複製代碼
ThisTime:最後一個Activity啓動耗時(如MainActivity,不會包含前面的SplashActivity)
TotalTime:全部Activity啓動耗時
WaitTime:AMS啓動Activity總耗時
ThisTime < TotalTime < WaitTimeide
開始點:工具
Application#attachBaseContext()
複製代碼
結束點:佈局
**方案一:**首幀開始繪製(不推薦)post
onWindowFocusChanged
複製代碼
**方案二:**真實數據展現(第一條feed加載:onBindViewHolder)性能
onBindViewHolder
holder.linearLayout.getViewTreeOvserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){
@Override
public boolean onPregraw(){
LaunchTimer.endRecord();
holder.linearLayout.getViewTreeObserver().removeOnPredrwaListener(this);
return true;}
}
複製代碼
Debug.startMethodTracing("fileName"); // 方法開始
Debug.stopMethodTracing(); // 方法結束
複製代碼
生成文件路徑:sdcard/android/data/packagename/files 優化
結合 Android 內核數據, 生成 html 報告
TraceCompat.beginSection("section name");
TraceCompat.endSection();
複製代碼
特色 輕量級,開銷小。 直觀反映CPU利用率。