解释多核性能跟踪(Eclipse / Android) [英] Interpreting Multicore Performance Trace (Eclipse/Android)

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

问题描述

我正在开发一款Android游戏,在开发过程中,我开始注意到有点迟钝,所以我想尝试利用多线程来学习乐趣。



我的应用程序有3个线程:


  1. UI线程)

  2. 游戏逻辑线程

  3. 图形线程





然而,一旦我实施了,我的表现就大大的下降了。它比以前差得多,一个更新和渲染的循环像50 ms(20fps),所以看起来像垃圾。这只是渲染了大约20个三角形,也许20个纹理四边形,一个非常简单的工作量(我不敢想到,当我实现正确的图形将是什么)。



无论如何,我在Android中采用了DDMS跟踪来描述发生错误或可能改进的内容。






我正在双核心手机上进行开发,但如果我明白跟踪它看起来并不像以前一直在做任何事情并且更糟糕的是,似乎是每毫秒数百次切换活动线程! (除非我不正确地解释)。所有这些上下文切换似乎对性能来说都是可怕的,所以我不知道为什么它会想要快速切换。



所以在我的长我想知道一些事情:


  1. 我的理解正确,跟踪中填充的矩形是活动线程,彩色线是睡线?否则它们是什么意思?

  2. 为什么我看不到我的线程在所谓的双核手机上同时运行?

  3. 为什么要切换主动线程如此之快?

  4. 在DDMS中,我收到警告警告:调试器处于活动状态;方法跟踪结果将被偏移。这是值得担心的吗?如何摆脱这个警告? (我通过运行启动应用程序,而不是通过调试,如果它有所作为)


解决方案

好的问题,让我从答案开始:


  1. 你已经混合了线程/方法/ activeMethod。 traceview中的每行都是线程(如果你命名你的线程,你会看到它的名字在左边,如GL线程,主等)。矩形(彩色)表示每个线程内执行方法的活动,而彩色线代表线程内的已暂停方法。通过暂停,我的意思是方法仍然执行,但上下文切换到其他线程,并且当上下文切换到此线程时,此方法将继续工作。在您的问题中使用的术语中,线是睡眠线程的方法,矩形是主动线程执行方法,你可以找到关于DDMS traceview的更多信息这里

  2. 在核心之间分配线程是另一个故事,很大程度上取决于底层的Android操作系统机制。首先,确保目标Android操作系统从SMP(对称多处理)选项开始,这是多核手机的默认情况,我猜:),但我不是那些东西的专家。关于SMP的一些话你可以在这里找到

  3. 线程切换取决于OS Threa d /进程调度程序,线程优先级等。有关这些事情的更多信息,可以找到此答案。

  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.

这篇关于解释多核性能跟踪(Eclipse / Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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