標籤:
本文大部分內容來自:http://www.androidperformance.com/android-performance-tools-systrace-1.html?utm_source=tuicool
Systrace是Android4.1中新增的效能資料採樣和分析工具。它可協助開發人員收集Android關鍵子系統(如surfaceflinger、WindowManagerService等Framework部分關鍵模組、服務,View系統等)的運行資訊,從而協助開發人員更直觀的分析系統瓶頸,改進效能。
Systrace的功能包括跟蹤系統的I/O操作、核心工作隊列、CPU負載以及Android各個子系統的健全狀態等。在Android平台中,它主要由3部分組成:
- 核心部分:Systrace利用了Linux Kernel中的ftrace功能。所以,如果要使用Systrace的話,必須開啟kernel中和ftrace相關的模組。
- 資料擷取部分:Android定義了一個Trace類。應用程式可利用該類把統計資訊輸出給ftrace。同時,Android還有一個atrace程式,它可以從ftrace中讀取統計資訊然後交給資料分析工具來處理。
- 資料分析工具:Android提供一個systrace.py(python指令檔,位於Android SDK目錄/tools/systrace中,其內部將調用atrace程式)用來配置資料擷取的方式(如採集資料的標籤、輸出檔案名等)和收集ftrace統計資料並產生一個結果網頁檔案供使用者查看。 從本質上說,Systrace是對Linux Kernel中ftrace的封裝。應用進程需要利用Android提供的Trace類來使用Systrace.
關於Systrace的官方介紹和使用可以看這裡:Systrace
1.Systrace簡單使用
使用Systrace前,要先瞭解一下Systrace在各個平台上的使用方法,鑒於大家使用Eclipse和Android Studio的居多,所以直接摘抄官網關於這個的使用方法,不過不管是什麼工具,流程是一樣的:
- 手機準備好你要進行抓取的介面
- 點擊開始抓取(命令列的話就是開始執行命令)
- 手機上開始操作
- 設定好的時間到了之後,會將產生Trace檔案,使用Chrome將這個檔案開啟進行分析
Using Eclipse
- In Eclipse, open an Android application project.
- Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
Using Android Studio
- In Android Studio, open an Android application project.
- Open the Device Monitor by selecting Tools > Android > Monitor.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
Using Device Monitor
- Navigate to your SDK tools/ directory.
- Run the monitor program.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
圖解:
首先進入DDMS,然後點擊裝置,點擊Systrace按鈕,接著選擇測試項,這裡可以設定時間。點擊確定後開始操作手機,在時間到了後會自動產生報表。
參考自:
http://blog.csdn.net/tommy_wxie/article/details/8636853
http://www.androidperformance.com/android-performance-tools-systrace-1.html?utm_source=tuicool
Android效能最佳化工具之Systrace