本文介绍了国米preting多核性能跟踪(Eclipse中/安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个机器人游戏,我就开始在开发过程中注意到一个有点呆滞,所以我想尝试利用多线程的乐趣和学习。

我的应用程序有3个主题:

  1. 在UI线程(应该大部分空闲)
  2. 在游戏逻辑主线
  3. 图形主题

我最小线程2和3尽我所能的关键部分,用的想法,游戏逻辑可以独立渲染线程的更新,然后在两个线程结束时,我能有尽可能短窗口,我把从逻辑线程游戏循环中的所有图形更新。这应使两个线程独立工作的一个好大部分时间。在理论上听起来像一个表现的胜利。

然而,一旦我抽时间去实现,我的表现了一大跳水。它比以前差多了,更新和渲染的一个循环正在像50毫秒(20FPS),所以它看起来像垃圾。这只是呈现了20个三角形,也许20纹理的四边形,一个非常简单的工作负载(我不敢想什么这将是我实施适当的图形)。

无论如何,我花了DDMS轨迹Android的个人资料在那里的事情了错误的或者有待改进。

http://i.stack.imgur.com/DDUYE.png

这是我的比赛大约3帧的景色。到目前为止,这似乎是在做大概是我的预期。这是在蓝色高亮显示的部分是被锁定的部分,看起来约权(保持glThread主要是等待,而它被锁定)。然而,一旦我解开它,我应该看到两个线程同时工作,而且看起来是这样,但如果我仔细看:

http://i.stack.imgur.com/vukXQ.png

我在做我的开发在双核手机,但如果我的理解跟踪右它看起来并不像它以往任何时候都在做并行什么,什么是它似乎是切换活动线程数百倍每差毫秒! (除非我是跨preting这个错误)。所有这一切都上下文切换似乎将是可怕的性能,所以我不知道为什么它会想来回切换如此之快。

于是经过我的长篇大论的解释,我想知道的几件事情:

  1. 在我的理解是正确的,即在跟踪填充矩形是活动线程,和彩色线条是睡眠线程的?否则,它们意味着什么?
  2. 为什么不我曾经看到我的线程在一个所谓的双核手机同时运行?
  3. 为什么交换活动线程得如此之快?
  4. 在DDMS我得到警告警告:一个调试器是活动的,方法跟踪的结果将被扭曲。这是什么可担心的?我怎样才能摆脱这个警告? (我launced应用程序,通过运行,而不是通过调试,如果它有差别)
解决方案

很有趣的问题,让我先回答:

  1. 您已经混了线程/方法/ activeMethod。在traceview每一行都是线程(如果你命名你的线程,你会看到它在左边的名称,如GL主题,主,等等。)。矩形(彩色)重新presents 有效的执行每个线程里面的方法,而颜色的线重新presents暂停内螺纹的方法。所谓暂停,我的意思是方法仍在执行,但上下文切换到其他线程,当环境再次切换到这个线程,此方法将继续努力,在术语,你已经在你的问题时,你们,线都在睡觉线程的方法和矩形活动的线程执行的方法,你可以找到的 DDMS traceview更多信息。
  2. 分配线程内核之间则是另一回事,并在很大程度上依赖于底层Android操作系统的机制。首先,要确保目标的Andr​​oid操作系统开始在SMP(对称多处理)选项,这是默认的情况下,多核手机,我猜:),但我不擅长这些东西。 有关SMP有些话你可以找到这里
  3. 在线程切换依赖于操作系统的线程/进程调度程序,线程优先级等更多关于这个事情,你可以找到在这个答案。
  4. 即使你跑在非调试模式,应用程序时使用DDMS连接,并且做的事情,方法分析,你就会启动调试davlik VM的部分。 有关调试这里,部分执行。更多细节

希望你会发现这个答案有帮助。

I'm working on an android game, and I started noticing a little sluggishness during development so I wanted to try to utilize multithreading for fun and learning.

My application has 3 threads:

  1. UI thread (should be mostly idle)
  2. Game Logic Thread
  3. Graphics Thread

I minimized the critical section between threads 2 and 3 as best I could, with the idea that the game logic could update independently of the rendering thread, and then at the end of both threads I could have a short as possible window where I push all the graphics updates from the logic thread to the game loop. This should allow the two threads to work independently for a good majority of the time. In theory sounds like a performance win.

However once I got around to implementing, my performance took a big dive. It much worse than before, one loop of updating and rendering is taking like 50 ms (20fps), so it looks like garbage. This is just rendering some 20 triangles and maybe 20 textured quads, a really simple workload (I afraid to think of what it will be when I implement proper graphics).

Anyway I took a DDMS trace in android to profile where things were going wrong or could be improved.

http://i.stack.imgur.com/DDUYE.png

This is a view of roughly 3 frames of my game. So far it seems to be doing roughly what I expected. The parts that are highlighted in blue is the locked section, which looks about right (keeps the glThread mostly waiting while it is locked). However once I unlock it I should see both threads working simultaneously, and it looks like they are, but if I look closer:

http://i.stack.imgur.com/vukXQ.png

I'm doing my development on a dual core phone, but if I understand the trace right it doesn't look like it's ever doing anything in parallel, and what's worse it appears to be switching the active thread hundreds of times per millisecond! (unless I'm interpreting this incorrectly). All this context switching seems like it would be awful for performance, so I'm not sure why it would want to switch back and forth so fast.

So after my long winded explanation, I'm wondering a few things:

  1. Is my understanding correct, that the filled rectangles in the trace are the active threads, and the colored lines are sleeping threads? Otherwise what do they mean?
  2. Why don't I ever see my threads running simultaneously on a supposedly dual core phone?
  3. Why is it switching active threads so rapidly?
  4. In DDMS I get the warning "WARNING: a debugger is active; method-tracing results will be skewed". Is this something to worry about? How can I get rid of this warning? (I launced app via Run, not via Debug if it makes a difference)
解决方案

Very nice question, let me start with answers:

  1. You have mixed up threads/methods/activeMethod. Each line in traceview is thread (and if you named your threads, you'll see it's name on left side, like "GL Thread", "main", etc..). Rectangles(colored) represents active executing methods inside each thread, while colored lines represents "paused" methods inside thread. By "paused", i mean "method is still executing, but context was switched to some other thread, and when context switched again to this thread, this method will continue to work. In terminology you've used in your question, ye, lines are sleeping thread's methods, and rectangle is active thread executing method. You can find more info about DDMS traceview here.
  2. Distributing threads among cores is another story and heavily depends on underlying Android OS mechanisms. First of all, be sure that target Android OS is started with SMP (Symmetric Multi-Processing) option on, which is default case for multicore phones, i guess :), but i'm not expert in those things. Some words about SMP you can find here.
  3. Thread switching depends on OS Thread/Process scheduler, thread priority, etc. More info about this things you can find in this answers.
  4. Even if you ran application in non-debugging mode, when you connect with DDMS, and do things such Method profiling, you'll activate debugging parts of davlik vm. More details about debugging here, section "Implementation".

Hope you'll find this answer helpful.

这篇关于国米preting多核性能跟踪(Eclipse中/安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:57