iOS Instruments Time Profiler

Time Profiler

有兩種方式能夠打開Time Profiler。咱們先來介紹第一種:

1、從Debug界面打開Time Profiler

1)首先打開Xcode,在編譯成功後運行App,這裏測試Demo是選擇在遊伴項目中直接添加一部分進行測試,打開Debug面板,以下圖所示。

 

    @測試代碼中主要是增長了兩個for循環,爲了方便Time Profiler分析。 api


2)右鍵點擊圖片左側中的CPU,顯示以下界面

 

    @(1) :圖片右側紅色線框圈住的部分。CPU佔用百分比。這裏是剛啓動的時候,CPU佔用比較高。CPU 最大爲400%,這裏能夠認爲是MAC機器的CPU共計400%,但只分配給Simulator 100%。 ide

    @(2) : 圖片右側藍色線框圈住的部分。CPU使用的比較。因爲是用Simulator進行演示分析,這裏有MAC機器的其餘程序也在運行。能夠看到紫色部分是咱們的項目MSGS佔用98%,Other Processes能夠忽略不計。 函數

    @(3) : 圖片右側紫色線框圈住的部分。CPU啓動的時間。這裏有三個參數。 工具

               Duration:CPU運行時間 (7 sec) 測試

               High:      最高佔用比   (98%) spa

               Low:         最低佔用比   (13%) 線程

    @(4): 圖片右側黑色線框圈住的部分。各個線程佔用CPU的詳情。剛啓動時,只有一個主線程運行。 code

    @(5): 圖片右側黃色線框圈住的部分。在Instruments裏打開Time Profiler。 圖片


3)打開上一步中的@(5),在Instruments 中打開Time Profiler。點擊後會彈出如下界面

 

     @(1) :Restart,在Instruments從新啓動項目進行Time Profiler分析。 get

     @(2):Transfer,在Instruments中繼續運行當前項目進行Time Profiler分析。


4)點擊Restart,從新分析項目。

 

     @(1):  紫色線框區域

                                                             :Record鍵,至關於開始和結束功能;

                                                             :Pause鍵,暫停功能,點擊暫停後,項目將會終止加載

                    : 當前正在分析的項目

                   :項目的運行時間。注意這裏有兩個時間:

  1. 項目運行時間,就是有藍色區域的部分,暫停後就終止,再也不向前推動,再次按暫停後繼續運行。
  2. Instruments工具運行時間,不隨項目暫停而暫停。紅色線框包圍區域爲暫停的時間,再按Pause後項目又開始運行(藍色區域)。

              

     @(2): 藍色線框區域

               這裏主要配合@(3)部分,設置其顯示的方式。

               Separate by Thread :     分開線程顯示

               Invert Call Tree:             以樹形方式顯示調用的方法

               Hide System Libraries:  不顯示系統函數佔用時間

      @(3): 紅色線框區域

               :這裏能夠選擇調用函數佔用時間顯示方式,通常選擇Call Tree方便查看。

              :對應後面函數的運行時間和佔用整個時間的百分比。


5)在雙擊一個方法後,會顯示該方法中的各代碼段的佔用時間比。

     選中其中一行雙擊,便可查看到以下界面。這裏顯示了每一個操做所佔用的時間比。(這裏的運行之和爲100%,即各個代碼段在當前方法中的佔用比,總和100%對應外部的90.2%)。

     @對比圖(此時項目運行到剛剛加載出遊伴主界面後,選擇暫停)

           @: i = 100  ;  j = 2000 ,UIApplicationMain()方法佔用時間比爲96.0%。

                    

              @:i = 1000 ;  j = 20000,將循環放大一百倍。此時UIApplicationMain()方法佔用時間比爲33.8%

                    

6)詳細分析這個界面(示例)

                 

       @1:打開某一個代碼文件

               

        @2:顯示彙編調用和代碼文件的對比

              

         @3:在彙編代碼和代碼文件切換視窗

              


         @4:在Xcode中打開代碼段所在文件,使用選中代碼片斷必須是OC語言

              

           @5:一些設置選項,能夠顯示值顯示和百分比顯示(目前還不知道x是什麼單位)

              


7)退出保存

             

        @點擊關閉按鈕,會提示是否保存。這裏能夠保存成一個文件到指定目錄

             

         @1:保存的文件名

         @2:保存位置


插入一個使用Time Profiler 的PPT

Time Profiler PPT.pptx

第二種打開方式

2、直接從Xcode界面打開Time Profiler

1)打開Xcode界面,Xcode->Open Developer Tool-> Instruments,這裏有全部的工具,圖示有對照表。

         


         

        @所有的Instruments以下:

            Trace template                                   Instruments               

Activity Monitor

Activity Monitor Instrument

Allocations

Allocations Instrument

VM Tracker Instrument

Automation

Automation Instrument

Cocoa Layout

Cocoa Layout Instrument

Core Animation

Core Animation Instrument

Time Profiler Instrument


Core Data

Core Data Cache Misses Instrument

Core Data Fetches Instrument

Core Data Saves Instrument

Counters

Counters Instrument

Dispatch

Dispatch Instrument





Energy Diagnostics

Bluetooth Instrument

CPU Activity Instrument

Display Brightness Instrument

Energy Usage Instrument

GPS Instrument

Network Activity Instrument

Sleep/Wake Instrument

WiFi Instrument



File Activity

File Activity Instrument

File Attributes Instrument

Directory I/O Instrument

Reads/Writes Instrument

GPU Driver

GPU Driver Instrument

Time Profiler Instrument

Leaks

Allocations Instrument

Leaks Instrument

Multicore

Dispatch Instrument

Thread States Instrument

Network

Connections Instrument

OpenGL ES Analysis

GPU Driver Instrument

OpenGL ES Analyzer Instrument

Sudden Termination

Sudden Termination Instrument


System Trace

Scheduling Instrument

System Calls Instrument

VM Operations Instrument

System Usage

Time Profiler

I/O Activity Instrument

Time Profiler Instrument

UI Recorder

Zombies

 User Interface Instrument

Allocations Instrument


2)點擊choose後,進入Time Profiler Instruments。

      

       @從這裏選擇咱們要測試的項目

3)其他步驟參考 1、4)及其後續的步驟便可。

相關文章
相關標籤/搜索