Android效能最佳化工具之Systrace

來源:互聯網
上載者:User

標籤:

  本文大部分內容來自: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
  1. In Eclipse, open an Android application project.
    1. Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
    2. 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.
    3. Click the Systrace icon at the top of the Devices panel to configure tracing.
    4. Set the tracing options and click OK to start the trace.
Using  Android Studio
  1. In Android Studio, open an Android application project.
    1. Open the Device Monitor by selecting Tools > Android > Monitor.
    2. 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.
    3. Click the Systrace icon at the top of the Devices panel to configure tracing.
    4. Set the tracing options and click OK to start the trace.
Using Device Monitor
  1. Navigate to your SDK tools/ directory.
    1. Run the monitor program.
    2. 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.
    3. Click the Systrace icon at the top of the Devices panel to configure tracing.
    4. 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.