Android性能優化工具之Systrace


  本文大部分內容來自: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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM