如何理解Android SDK中的个人资料traceview ...? [英] How to understand Android SDK profile traceview...?

查看:240
本文介绍了如何理解Android SDK中的个人资料traceview ...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Jsoup获取并解析某些HTML页面的一些code,然后我操纵的HTML树,把它传递给绘制它的WebView之前。如果我绕过我的操作中,code在对Android SDK模拟器可以接受的时间(2-3秒)上运行,但是当我做我的操作时间跳转到不可接受的(〜60秒只加载一个页面!)

I have some code that uses Jsoup to get and parse some html pages, and then I manipulate the html tree, before passing it to a WebView that draws it. If I bypass my manipulations, the code runs in acceptable times (2-3 seconds) on the Android SDK simulator, but when I do my manipulations the time jumps to unacceptable (~60 seconds to just load a single page!).

使用Eclipse和Android SDK我有异形跑,现在我想跨preT的结果。从这里 http://android-developers.blogspot.com/2010 /10/traceview-war-story.html 了尖端排序的独占CPU时间%配置文件。令我惊讶的是,我自己的code甚至没有列出在1%。最大的一次消费者android.view.ViewGroup.drawChild()为11.9%。列出(通过异CPU%作为排序)第一非机器人功能是java.lang.ref.Reference.get()和它在0.4%列出。

Using Eclipse and the Android SDK I had a run profiled, and now I'm trying to interpret the results. from here http://android-developers.blogspot.com/2010/10/traceview-war-story.html took the tip to sort profile on the "Exclusive Cpu Time %". To my surprise, my own code did not even list at 1%. The biggest time consumer is android.view.ViewGroup.drawChild() at 11.9%. The first non-android function listed (as sorted by exclusive cpu %) is java.lang.ref.Reference.get() and it lists at 0.4%.

不过,我想德奇怪的是,我自己的code,我只能找到我的AsyncTask的doInBackground()挂牌​​;这依次调用的功能,甚至没有present,即使我可以通过调试输出,他们被称为见。为什么那些不上市?

But I guess teh strangest thing is that of my own code, I can only find my AsyncTask's doInBackground() listed; the functions this calls in turn are not even present, even though I can see by the debug output that they are called. Why are those not listed?

我不明白做任何此类东西。任何提示都非常AP preciated。

I don't understand what to make of any of this. Any hints are very much appreciated.

推荐答案

虽然我没有手头的参考,我认为它是安全的假设,在Android的优先android.os一个线程执行AsyncTask.doInBackground() .Process.THREAD_PRIORITY_BACKGROUND

Although I don't have a reference at hand, I think it's safe to assume that Android executes AsyncTask.doInBackground() in a Thread with priority android.os.Process.THREAD_PRIORITY_BACKGROUND

这意味着,此主题定在Linux cgroup中(调度类)该背景下 - 总是或在频繁的情况下,我不知道,看了各种说法 - 上限的通用CPU时间5%或10% - 再次,不同的来源作出不同的要求 - 适用

This means that this Thread is scheduled in the context of a Linux cgroup (scheduling class) for which -- always or under frequent circumstances, I'm not sure and have read various claims -- an upper bound of common CPU time of 5% or 10% -- again, different sources make different claims -- is applied.

在换句话说,所有后台线程必须共享5%或可用的CPU时间的10%。同样,我已阅读,如果前景和实时任务都处于空闲这是动态调整的要求,但我很高兴能指着一个可靠的消息来源我自己。另外,我不会指望它,因为用户可以在使用我的应用程序收听实时音频流。

In other words, all background threads have to share 5% or 10% of the available CPU time. Again, I have read claims that this is dynamically adjusted if the foreground and real time tasks are idle, but I'd be happy to be pointed to a credible source myself. Also, I wouldn't count on it since the user can listen to a real time audio stream while using my app.

如果您调整背景线程的优先级,像这样:

If you adjust the background Thread's priority, like so:

private static final int bgThreadPrio = Process.THREAD_PRIORITY_BACKGROUND +
                                        Process.THREAD_PRIORITY_MORE_FAVORABLE;
protected YourReturnType doInBackground() {
    Process.setThreadPriority(bgThreadPrio);
    ....
}

然后你实现两件事情。

then you achieve two things.


  • 您解除螺纹出背景cgroup中这样的,它不具有与其它背景线程共享的CPU时间的10%(至少目前,直到Android的在这方面的改变其政策)。

  • 您分配优先级通常不会对用户界面和实时线程了极其恶劣的影响,螺纹的,因为THREAD_PRIORITY_DEFAULT为0,而THREAD_PRIORITY_BACKGROUND是10.所以,你的线程将在优先级9比0差很多运行但它会避免的后台任务的人为限制。

不过,您也可能会改变它的基本AsyncTask的执行者为您的AsyncTask线程的优先级。此主题将被回收利用,并且它可以是一个单一的线程或从池中选择。所以它可能是设置优先于所有AsyncTasks所有doInBackground()方法,在你的应用程序是个好主意。

However, you also probably change the priority of the Thread which the underlying AsyncTask executor provides for your AsyncTask. This Thread is going to be recycled, and it may be a single Thread or chosen from a pool. So it might be a good idea to set the priority in all doInBackground() methods in all AsyncTasks in your app.

这篇关于如何理解Android SDK中的个人资料traceview ...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆