}对于模拟器我们还得创建一个带有SD card的AVD,这样才能使trace文件保存到/sdcard/...当中。可以在命令中分别单独创建,也可以在创建avd的时候一起将sdcard创建。创建之后通过DDMS file explore我们就可以看到/sdcard/目录下有一个trace文件,如果没有在Debug语句中设置名字则默认为dmtrace.trace.1.3、 把trace文件从SD卡拷到电脑上现在我们把这个文件copy到我们的电脑上指定的目录:adb pull /sdcard/dmtrace.trace d:1.4、启动traceview可视界面现在就可以通过命令行来执行traceview了。进入SDK的tools目录后,执行traceview,如下: traceview D:\dmtrace.trace.之后即可以看到图形界面了。1.5、分析traceview结果Timeline Panel窗口的上半部分是时间轴面图(Timeline Panel)The image below shows a close up of the timeline panel. Each thread’s execution is shown in its own row, with time increasing to the right. Each method is shown in another color (colors are reused in a round-robin fashion starting with the methods that have the most inclusive time). The thin lines underneath the first row show the extent (entry to exit) of all the calls to the selected method.界面上方的尺子代表了MethodTracing的时间段(从Debug.startMethodTracing()到Debug.stopMethodTracing()的时间)。每个线程的函数执行时间图处于和线程名同一行的右侧。注1:线宽度代表执行该函数本身操作所用的时间。注2:函数所调用的子函数时间线夹杂在该函数本身操作所用的时间线之间。注3:时间线的高度不知道有什么意义。注4:函数本身是嵌套的。注5:每行下面粗的线段标注了Profile Panel中被选中函数调用所消耗的时间段。每个线段对应一次函数的运行。在下面的图中我们可以看到有11次对LoadListener.nativeFinished()的调用,其中有一次调用耗时特别的多。这里的11次和图2并不一致,应该是google的疏忽。图1The Traceview Timeline Panel Profile Panel窗口的下半界面是对各个函数调用的汇总图Profile Panel Figure 2 shows the profile pane, a summary of all the time spent in a method. The table shows both the inclusive and exclusive times (as well as the percentage of the total time). Exclusive time is the time spent in the method. Inclusive time is the time spent in the method plus the time spent in any called functions. We refer to calling methods as "parents" and called methods as "children." When a method is selected (by clicking on it), it expands to show the parents and children. Parents are shown with a purple background and children with a yellow background. The last column in the table shows the number of calls to this method plus the number of recursive calls. The last column shows the number of calls out of the total number of calls made to that method. In this view, we can see that there were 14 calls to LoadListener.nativeFinished(); looking at the timeline panel shows that one of those calls took an unusually long time.图2是对各个函数调用的汇总图Profile Panel。该表给出了the inclusive and exclusive times及他们所占有的百分比。Exclusive time是该函数本身基本操作(不包括子函数调用)的时间。Inclusive time是该函数调用所用的时间(包括子函数调用)的时间。列1:"Name"表示函数名。双击函数名,可以看到在上半界面是时间轴面图(Timeline Panel)看他的所消耗的时间段。(用粗的线段标注)。双击函数名左边的"+"展开后可以看到,该函数的"parents"和"children"列2:"incl%"表示函数的Inclusive time在整个MethodTracing时间里占的百分比。列3:"Inclusive"表示Inclusive time。列4:"Excl%"表示函数的Exclusive time在整个MethodTracing时间里占的百分比。列5:"Exclusive"表示Exclusive time。列6:"Calls+RecurCalls/Total"表示对函数的调用次数(包括递归调用)。如图2的nativeFinished()那列为"14+0"表示14次非递归调用,0次递归调用.列7:新的版本(比如2.1)还有"time/calls"表示平均的调用时间(即Inclusive time/ total calls)。如图3。来自google文档的图2感觉有老了。注:如果函数A调用函数B那么函数A称为函数B的"parents",函数B称为函数A的"children."
以下是翻译
英语 | 中文 |
Incl | 调用方法占用时间百分比 |
Inclusive | 调用方法时间(ms)(包括了所有方法的调用) |
Excl | 执行方法占用时间百分比 |
Exclusive | 执行方法占用时间(ms)(不包括子方法的调用) |
Calls+Recur Calls/Total | 调用和重复调用的次数 |
Time/Call | 总的时间(ms) |