New Gingerbread API: StrictMode阅读笔记

原文: New Gingerbread API: StrictMode , posted by Brad Fitzpatrick, an Android Software Engineer who worries unreasonably about responsiveness.

先说作者,刚开始还没太注意,写这篇帖子时点开它的博客后发现了这个:http://www.danga.com/,有兴趣的童鞋可以去看看这个公司的开源软件(搞web的会有惊喜哦)。他是danga的创始人。

StrictMode是用于监测访问disk或者network时的低响应和ANR的,是一个development tool.
它的用法和具体细节详看api doc和这篇文章,碰到问题呢,可以去StackOverFlow的strictmode去查或问。

我对文章有下面几点理解和总结:
1.与monkey类似,StrictMode也是用于保障app质量的一个给力工具,前者更倾向于系统的稳健,后者呢更专注软件的性能
2.作者给出一个实例(文中Our Experience那一段)。大概意思就是他们自己搞了一个dogfood的玩意供整个team使用,使用dogfood之后,StrickMode会被开启,并且在Gingerbread开发过程中出现的那些violations(就是被StrickMode机制检测到的问题)都会被日志记录下来,然后有一个叫MapReduce的玩意,每小时执行一次,它会把这些log生成成一份interactive report(就是人看起来比较舒服的报告)。(原文:Every hour a MapReduce job runs and produces an interactive report of all the event loop stalls, their stack traces (including cross-process ones), their latency percentiles, which processes/packages they appear in, etc.)
据作者说,用这些从StrictMode得到的数据,整个google android解决了好几百响应不能的bug和动画问题(哇塞,听起来很诱人哪)。(原文:Using the data from StrictMode we fixed hundreds of responsiveness bugs and animation glitches all across the board. We made performance optimizations in the Android core (e.g. system services and providers) so all apps on the system will benefit, as well as fixing up tons of app-specific issues (in both AOSP apps and Google apps). Even if you’re using Froyo today, the recent updates to GMail, Google Maps, and YouTube all benefited from StrictMode data collection gathered on Gingerbread devices.)
不过从这个实例看出,想从StrictMode长久受益,前期的投入还是不低的,起码得开发一套dogfood build系统,一个定时报告生成系统MapReduce。这就跟我现在这家公司用的hudson一样,很庞大也很复杂,需要很多人力,但是呢,的确对制造高质量的软件很有帮助(我问了在联想的同学,他们是有这想法,一直没实施起来)。
3.让你的app更smooth(性能表现更好),去Thread, java.util.concurrent.*和 Handler, AsyncTask, AsyncQueryHandler, IntentService 这些类里面找办法。
4.HoneyComb将会有一项新机制:当你在main thread(也叫ui thread)里面进行network操作时,会报错。但是之前的sdk还没有这样的机制。
5.我们知道,android的disk用的类似ssd的flash(或者就是),这东东很快吧,但是快归快,你任何牛掰的disk没有file system总不能用吧。android设备上大多用的文件系统是一个叫 YAFFS的玩意,这玩意有一个全局锁(global lock),所有的操作都可能使用这个锁,那么可想而知,某一刻这锁被别人占了,那你的disk操作就可能被等待了。
还是看原文:
You can’t depend on the flash components or filesystems used in most Android devices to be consistently fast. The YAFFS filesystem used on many Android devices, for instance, has a global lock around all its operations. Only one disk operation can be in-flight across the entire device. Even a simple “stat” operation can take quite a while if you are unlucky. Other devices with more traditional block device-based filesystems still occasionally suffer when the block rotation layer decides to garbage collect and do some slow internal flash erase operations. (For some good geeky background reading, see lwn.net/Articles/353411)
6.嗯,没了。:)


ps:鉴于主站被和谐,我把原文下载一份贴上来。。

你可能感兴趣的:(mapreduce,android,Google,Flash,Youtube)