標籤:android style class blog c code
使用 Shark 來對你的 iPhone 應用進行效能調優(Using Shark to Performance Tune Your iPhone App)
太陽火神的美麗人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商業用途-保持一致”創作公用協議
轉載請保留此句:太陽火神的美麗人生 - 本部落格專註於 敏捷開發及移動和物聯裝置研究:iOS、Android、Html5、Arduino、pcDuino,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。
使用 Shark 來對你的 iPhone 應用進行效能調優
Using Shark to Performance Tune Your iPhone App
問題是這樣的:我們正處理一個 OpenGL 的 iPhone 遊戲,不知什麼原因楨率非常低 - 尤其有一些小的操作發生在螢幕上的時侯。我首先打算著手處理的是開始償試成塊注釋掉系統部分,看看哪個模組導致的這個問題。我移除了物理系統、邏輯更新以及一些要被渲染的東西。然而,我什麼也沒做,好像就有顯蓍的效能提升。現在該到時侯,深入點查看系統並讓 Shark 找出問題出在哪兒了。
Here was the problem: we were working on an OpenGL iPhone game and for some reason the frame rates were unusually low - especially for what little action was happening on the screen at the time. My first plan of attack was to begin commenting out chunks of the system in an attempt to see what module was causing the problem. I removed the physics, the logic updates, and some of the things being rendered. Nothing I did, however, seemed to create a noticeable improvement in performance. It was now time to look a little deeper into the system and let Shark figure out what was wrong.
Shark 是一個效能描述工具,自從 Mac OS X 10.3 開始每一個版本都內建。它作為 Xcode 工具的一部分。本教程將向你介紹 Shark,如何使用它來描述一個 iPhone 應用,以及解釋結果。
Shark is a performance profiling tool shipped with every version of Mac OS X 10.3 or newer. It comes as part of the Xcode Tools. This tutorial will introduce you to Shark, how to have it profile an iPhone application, and how to interpret the results.
最先需要做的事情就是弄一份調試版本的應用下載到你的電話上。
The very first thing you‘re going to need to do it get a debug version of your app onto your phone. If you‘re to the point of wanting to use Shark, I‘m going to assume you already know how to do this. To make the recording and analysis a little quicker, we‘re going to target your specific application, which means you‘ll want to go ahead launch it before you launch Shark. You‘ll also want to run your application outside of the Xcode debugger - just launch it directly using the phone.
Up next, launch Shark. It should installed here:
/Developer/Applications/Performance Tools/Shark
In order to connect Shark to an iPhone, you‘ll need to change the sampling mode to Network/iPhone Profiling. You do this through Shark‘s Sampling menu.
At this point, your iPhone should be connected to the computer and your app should be running. When your phone appears in the list, simply check the box next to it. Shark should now look something like the image below.
Shark has several different configurations, however Time Profile is the one we‘ll be looking at today. This mode will tell us how much processing time is spent in what functions. Under Target, choose the app you‘d like to profile. The current name of our app is "drop n lock", so that‘s what I have chosen. When everything is ready to go, just hit "Start".
Shark doesn‘t let you view the performance information real-time. Simply do the actions you‘d like performance information for and when you‘re done, hit "Stop". At this point, Shark is going to spend a long time analyzing the sample and then will create a session file that we can review.
When the report is complete, it will display automatically.
There‘s lots of ways to view session information, however Tree (Top-Down) is the one I like the best. Looking at this report, we can see that the function responsible for rendering text is taking up 16% of the processing time. When I was first hunting for the problem, text rendering didn‘t even occur to me as a potential problem. And sure enough, when I disabled the text, my frame rate doubled. Obviously we‘ll need to find a more optimized way to display text.
There you have it. Using Shark is a great way to find and eliminate performance bottlenecks in your iPhone applications. It took me no time at all to pin-point exactly where in our code a potential problem was. Unfortunately it can‘t fix the code for you - that you‘ll have to do on your own.