• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 使用traceview和dmtracedump調試Android代碼

    發表于:2011-08-26來源:CSDN作者:yiyaaixuexi點擊數: 標簽:
    使用traceview和dmtracedump調試Android代碼Google為我們提供的代碼調試工具的亮點:traceview 和 dmtracedump 。有了這兩個工具,我們調試程序分析bug就非常得心應手了。traceview幫助我們分析程序性能,dmtracedump生成函數調用圖。遺憾的是,google提供的d

    使用traceview和dmtracedump調試Android代碼 

     ✿Android 程序調試工具

      Google為我們提供的代碼調試工具的亮點:traceview 和 dmtracedump 。有了這兩個工具,我們調試程序分析bug就非常得心應手了。traceview幫助我們分析程序性能,dmtracedump生成函數調用圖。遺憾的是,google提供的dmtracedump是個失敗的工具,并不能繪圖,本文會詳細介紹解決方案,實現繪圖。

      ✿生成.trace文件

      android.os.Debug類,其中重要的兩個方法Debug.startMethodTracing()和Debug.stopMethodTracing()。這兩個方法用來創建.trace文件,將從Debug.startMethodTracing()開始,到Debug.stopMethodTracing()結束,期間所有的調用過程保存在.trace文件中,包括調用的函數名稱和執行的時間等信息。

      把下面代碼分別在加在調試起始代碼的位置,和終止位置。

      Debug.startMethodTracing(“test”);

      Debug.stopMethodTracing();

      Debug.startMethodTracing(“test”);

      Debug.stopMethodTracing();

      其中參數test是要創建的trace文件的名稱,test.trace。默認路徑是/sdcard/test.trace,也可以自己制定/data/log/test,表示文件在/data/log/test.trace。

      ✿traceview

      在SDK中執行 :

      ./traceview test.trace

      我們可以得到

      1.程序中每個線程調用方法的啟動和停止時間

      2.函數執行的信息和效率分析

      ✿dmtracedump

      dmtracedump原本的用意是將整個調用過程和時間分析結合,以函數調用圖的形式表現出來??墒莋oogle這個項目一直處于broken狀態,遲遲不能得到完善?,F在的dmtracdump只有-o選項可以使用,在終端上列出函數調用信息,和traceview功能相似,如果執行./dmtracedump –g test.png test.trace就會卡住不動。

      起初我以為是test.trace文件的問題,對文件的結束符稍作修改,畫出了一副雷人的圖片:

      

      后來,搜到了網絡上有牛人提供了dmtracedump的替代,是一個python腳本,借助dot來繪制矢量圖。python腳本一定要注意對齊格式,對齊縮進就是他的邏輯結構。

      view plaincopy to clipboardprint?

      #!/usr/bin/env python

      """

      turn the traceview data into a jpg pic, showing methods call relationship

      """

      import sys

      import os

      import struct

      import re

      ###################################################

      ######################## Global Variable ##########

      ###################################################

      target_thread=1 #the thread that we want to track, filt out other threads

      #all_actions = ["enter","exit","exception","reserved"]

      all_threads = {}

      all_methods = {}

      all_records = []

      parent_methods = {}

      child_methods = {}

      method_calls = {}

      #####################################################

      ############################## Methods ##############

      #####################################################

      def add_one_thread(line):

      fields = line.split("/t")

      all_threads[int(fields[0],10)]=fields

      def add_one_method(line):

      fields = line.split("/t")

      all_methods[int(fields[0],16)]=fields

      def add_one_record(one):

      thread_id,=struct.unpack("B",one[:1])

      if (thread_id == target_thread):

      tmp,=struct.unpack("L",one[1:5])

      method_id= (tmp / 4) * 4;

      method_action= tmp % 4;

      time_offset,=struct.unpack("L",one[5:])

      all_records.append([thread_id, method_id, method_action, time_offset])

      def handle_one_call(parent_method_id,method_id):

      if not (parent_methods.has_key(parent_method_id)):

      parent_methods[parent_method_id]=1

      if not (child_methods.has_key(method_id)):

      child_methods[method_id]=1

      if method_calls.has_key(parent_method_id):

      if method_calls[parent_method_id].has_key(method_id):

      method_calls[parent_method_id][method_id]+=1

      else:

      method_calls[parent_method_id][method_id]=1

      else:

      method_calls[parent_method_id]={}

      method_calls[parent_method_id][method_id]=1

      def gen_funcname(method_id):

      r1=re.compile(r'[/{1}lt;>]')

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>