简体   繁体   English

Android Eclipse:Traceview,我只是不明白

[英]Android Eclipse: Traceview, I just don't get it

I just don't get the various elements of the traceview output, and I can't find a tutorial. 我只是没有得到traceview输出的各种元素,我找不到教程。 Could someone please explain the following with reference to the diagram below: 有人可以参考下图解释以下内容:

在此输入图像描述

  1. The width of the bars corresponds to the time the function takes. 条形的宽度对应于函数所用的时间。 What does the height correspond to? 高度对应的是什么?
  2. What is specific difference between Inclusive and Exclusive. 包容性和独家性之间有什么具体区别。 I assumed that inclusive includes the calls of all the children functions? 我认为包容性包括所有儿童功能的召唤?
  3. Would this be true: The sum of (Time per call times Calls) = time the program runs (what about async tasks?) 这是真的:(每次通话时间调用的时间)=程序运行的时间(异步任务怎么样?)
  4. Can async tasks be ignored when debugging slowdown on the main thread ? 在主线程上调试减速时,是否可以忽略异步任务?
  5. Should the sum of all the percents in Excl% equal 100%? Excl%中所有百分比的总和应该等于100%吗?
  6. What happens when there are gaps (white in the midst of black)? 当有间隙时(白色在黑色中间)会发生什么? Is that when other android processes are running, or just your own async tasks (it looks like the gaps in one are aligned with the filled in part in the other, if thats the case then is there any point in moving intensive tasks to an AsyncTask)? 这是当其他android进程正在运行时,或者只是你自己的异步任务(看起来一个中的间隙与另一个中的填充部分对齐,如果那样的情况那么将密集型任务移动到AsyncTask中有任何意义)?

(I would have added this as a comment to @ron's answer, but my reputation is still not high enough that I can comment ;)). (我会在@ ron的回答中添加这个作为评论,但我的声誉仍然不高,我可以发表评论;))。

Since July 2011, you can in fact get traceview and VMDebug to give you wall clock time as well as cpu usage time, thanks to a code change by Jeff Brown. 自2011年7月起,由于Jeff Brown的代码更改,您实际上可以获得traceview和VMDebug,以便为您提供挂钟时间和CPU使用时间。 I'm afraid the necessary permissions require a rooted device however. 我担心必要的权限需要root设备。 This also leads to a slightly different traceview window than the post by tjb above. 这也导致跟上面的tjb稍微不同的跟踪视图窗口。

http://git.insignal.co.kr/?p=mirror/aosp/platform/dalvik.git;a=commitdiff;h=9f640af99bebc6e96f6e1e9903557e2c8f567483 http://git.insignal.co.kr/?p=mirror/aosp/platform/dalvik.git;a=commitdiff;h=9f640af99bebc6e96f6e1e9903557e2c8f567483

TLDR; TLDR; adb shell setprop dalvik.vm.extra-opts -Xprofile:dualclock and reboot your device. adb shell setprop dalvik.vm.extra-opts -Xprofile:dualclock并重启你的设备。

HRM, since I'm technically supposed to help answer the question: HRM,因为我在技术上应该帮助回答这个问题:

  1. My understanding of the heights of bars is that it's related to parent functions. 我对条形高度的理解是它与父函数有关。 Suppose a() calls b(). 假设a()调用b()。 Then a() is running while b() is also running. 然后a()正在运行,而b()也在运行。 While b() is running traceview will show b's color; 当b()运行时,traceview将显示b的颜色; but when a is running (ie excl time) it will draw a's color, and it will draw a's bar slightly higher than b's bar. 但是当a运行时(即excl时间)它将绘制一个颜色,并且它将绘制一个略高于b的条形的条形图。 At least, this is definitely how things work when you zoom in; 至少,这绝对是你放大时的工作方式; If you click on the function corresponding to the taller bar it will put brackets underneath the small bars near it showing that the parent was responsible for all of it; 如果你点击相应较高栏的功能,它会将括号放在靠近它的小栏下方,表明父母负责所有这些; and the parent is always shown as the taller bar. 父母总是显示为较高的栏。

  2. yes :). 是的:)。 Inclusive is time spent executing the function or any thing called by that function; 包含是执行函数所花费的时间或该函数调用的任何东西; Exclusive is 'exclusive of called functions', and is just the time spent in the function proper (or switching into/out of it). Exclusive是'不包括被调用函数',只是在函数中花费的时间(或切换到/退出它)。

  3. Only for the toplevel, which I think you implied; 只为了我认为你所暗示的顶层; and even then see @ron's answer - this is cpu usage time, not wall clock time. 甚至那时看@ ron的答案 - 这是cpu使用时间,而不是挂钟时间。 AsyncTasks run in the main thread, and so will be included somewhere in the toplevel breakdown. AsyncTasks在主线程中运行,因此将被包含在顶层故障中的某处。 Same for Handlers 处理程序相同

  4. answered by Eric 埃里克回答

  5. No, because of round up / round down (ie 1.87% would display as 1.9%); 不,因为向上/向下舍入(即1.87%将显示为1.9%); but the sum of the entries in "Exclusive" should add up to the total time shown in the upper right corner, which is the same as the number calculated for your question (3) 但“独家”中条目的总和应加起来在右上角显示的总时间,这与为您的问题计算的数字相同(3)

  6. answered by Eric 埃里克回答

I cant answer all your questions, but I can say... 我无法回答你的所有问题,但我可以说......

for #4 no, You're running a single core processor (or at least emulating one) so async tasks on their own thread have to interrupt main thread to get processing time. 对于#4 no,你正在运行一个核心处理器(或至少模拟一个),因此他们自己的线程上的异步任务必须中断主线程以获得处理时间。 Any time another thread executes will be "slowdown" on the main thread, so you should be watching that. 任何时候另一个线程执行将在主线程上“减速”,所以你应该看着它。

for #6, those gaps you see in your main threads execution trace correlate exactly to the times when your asynctask is getting processor time. 对于#6,您在主线程执行跟踪中看到的那些差距与您的asynctask获取处理器时间的时间完全相关。 Again, single core, can only do 1 thread at a time. 同样,单核,一次只能做1个线程。 In this time slice it doesnt look like any other process got any processor time at all, but those threads were still sleeping in the background. 在这个时间片中,它看起来不像任何其他进程有任何处理器时间,但这些线程仍然在后台休眠。 Since this was (likely) an emulator, thats common. 由于这是(可能)一个模拟器,这很常见。 On a live phone you will see many more :) 在实时手机上你会看到更多:)

I'm also fairly sure for #1 that the height of each spike in the thread's execution is the %processor utilization. 我也非常确定#1线程执行中每个尖峰的高度是%处理器利用率。 For example the main thread's "black" area is system idle. 例如,主线程的“黑色”区域是系统空闲的。 Edit: Ok, i'm for sure now. 编辑:好的,我现在肯定。 This is what that is. 就是这样。 So in your main thread, that area that is solid pink is solid 100% processor utilization. 所以在你的主线程中,那个粉红色的区域是100%处理器利用率。

An other important know-how about the traceview graph (as mentioned here ): The time displayed by traceview is not real-world wall clock time, but used CPU time. 关于traceview图的另一个重要技术诀窍(如此处所述 ):traceview显示的时间不是真实的挂钟时间,而是使用CPU时间。

For example, by reducing the FPS the shape of the traceview graph may not change, since it does not include the idle duty cycles. 例如,通过减小FPS,跟踪视图的形状可能不会改变,因为它不包括空闲占空比。 Therefore when measuring performance, it is also recommended to run the app for a fixed amount of time (10 sec, 60 sec, etc), and check if the time taken by 100% inclusive calls is lower than before. 因此,在测量性能时,还建议运行应用程序一段固定的时间(10秒,60秒等),并检查100%包含呼叫所用的时间是否比以前低。

Google just released an amazing course on Udacity on Android performance. 谷歌刚刚在Udacity上发布了关于Android性能的精彩课程。 There's this module that provides a walkthrough of Traceview , as well as a link below the video module to their course guide that covers the usage of Traceview in great depth. 这个模块提供了Traceview的演练 ,以及视频模块下面的链接到他们的课程指南,其中深入介绍了Traceview的使用。 Looking over these will answer most of your questions. 查看这些内容将回答您的大部分问题。 I highly recommend you check it out! 我强烈建议你看看吧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM