android traceview and dmtracedump使用

來源:互聯網
上載者:User

如何分析android應用效能,java函數調用關係。

 

1.mksdcard  -l sdcard  512M /root/.android/sdcard.img

2.在應用程式中加入trace 的開始和結束函數(詳細說明參考開發文檔)

  
// start tracing to "/sdcard/calc.trace"

    
Debug
.
startMethodTracing
(
"calc"
);    --------calc是你要產生的.trace檔案的名字

 
// ..

 
// stop tracing

  Log.d("lizhenghui","NNNNNNN stop traceview debug");

 
Debug
.
stopMethodTracing
();

3 . 在eclipse 的run Configuraton-->Target 項的 Additional Emulator Command Line Options下指定Emulator啟動時的sdcard目錄: -sdcard /root/.android/sdcard.img

 

4.從eclipse運行android運用。

5. 退出運用程式,
用logcat 查看上面的log資訊是否出現,確保trace檔案不為空白。

6。adb ls /sdcard/

    會看到一個檔案:calc.trace 就是我們需要的檔案。

7。把trace檔案下載到本地。

 adb pull /sdcard/calc.trace ./

8。traceview calc.trace

    開啟了trace檔案,用點耐心看看協助文檔,可以知道這個檔案上部分為時間關係圖,反映的就是在什麼時間執行什麼函數,下部分為函數關係圖,反映的就是函數的調用關係。下部分各項的含義:

Name:列出的是所有的調用項,前面的數字是編號,展開可以看到有的有Parent 和Children子項,就是指被調用和調用。

Incl: inclusive時間佔總時間的白分比

inclusive: 調用佔用時間。(包括了所有的子方法的調用時間)

Excl: 執行佔總時間的白分比。

Exclusive: 執行時間,不包含子方法的時間。

Calls+Recur Calls/Total: 調用和重複調用的次數

Time/Call: 總的時間。(ms)

9.產生函數呼叫歷程圖

  A. apt-get install graphviz

  B. dmtracedump  -g aa.png calc.trace

  C. ls 查看是否產生aa.png 圖片。

10。用圖片工具開啟圖片。

11。圖片上函數顯示格式
(用開發文檔上的做例子,我用的是遠程外網)


    
<ref> callname
(<inc-ms>,
<exc-ms>,<numcalls>)

  • ref -- 編號
  • callname
    -- 函數名
  • <inc--ms>--調用時間
  • <exc-ms>
    -- 執行時間
  • <numcalls>
    -- 被調用的次數

12。OK 偷歡一會,嘿嘿!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.