Instruments使用指南(二)--- 開始Instruments之旅

啓動Instrument

     Instruments應用程序存在於Xcode應用程序中,所以最直接的啓動方式是在Xcode中。 您也可以通過Dock,Launchpad或命令行間接啓動它。


一、從Xcode啓動

啓動instruments的最直接的方式從xcode菜單欄裏啓動.

xcode菜單欄啓動步驟:
  1. 打開xcode

  2. 選擇 Xcode > Open Developer Tool > Instruments.

    image: ../Art/xcode_instruments_menu_2x.png

TIP

您可以使用這種方法來啓動一些其他有用的開發工具。


您還可以啓動Instruments來分析您在Xcode中正在使用的應用程序。.

去分析一個xcode打開的工程
  1. 在xcode打開您的項目

  2. 執行下面任意一項:


         選擇 Product > Profile.


    • image: ../Art/xcode_product_profile_menu_2x.png

    • 點擊並按住Xcode工具欄中的運行按鈕並選擇Profile.

      image: ../Art/xcode_toolbar_profile_menuitem_2x.png

    • 按 Command-I.



然後Xcode開始編譯您的項目,Instruments啓動,然後Instruments會提示您去選擇要分析的模板(例如:內存、時間)


如果你經常需要使用相同的模板去分析您的app,那麼您可以將Xcode項目設置爲在啓動分析時自動使用它。設置Xcode項目以使用特定的Instruments分析模板

  1. 選擇 Product > Scheme > Edit Scheme.

    image: ../Art/xcode_product_scheme_edit_scheme_menu_2x.png


    或者,從Xcode工具欄的Scheme彈出菜單中選擇Edit Scheme


    image: ../Art/xcode_toolbar_target_edit_scheme_menu_2x.png

    或者,按下 Command–Less Than (<).


    出現Scheme編輯器對話框如下:

    image: ../Art/xcode_scheme_editor_dialog_2x.png

  2. 點擊側欄的profile

    image: ../Art/xcode_scheme_editor_profile_option_2x.png

  3. 在info 選項下面,點擊Instrument 彈出選擇欄,選擇需要的測試模板


    image: ../Art/xcode_scheme_editor_instrument_popup_2x.png

    如果選擇“啓動時詢問”,Instruments會在啓動時顯示其分析模板選擇對話框。

  4. 點擊關閉

Xcode構建您的項目,啓動Instrument,然後開始按照您在編輯scheme了的配置模板進行分析。 

二、Dock啓動

Instruments可以從Dock中的Xcode圖標啓動

 Dock啓動步驟:
  1. 打開Xcode.

  2. 按住Control鍵並點按Dock中的Xcode圖標,然後從快捷菜單中選擇 Open Developer Tool > Instruments

    image: ../Art/dock_xcode_contextualmenu_instruments_2x.png



您也可以將Instruments添加到Dock以便快速訪問。 最快的方法是啓動Instruments,然後將其設置爲停留在Dock中。


將Instruments永久添加到Dock中
  1. 打開Xcode

  2. 選擇 Xcode > Open Developer Tool > Instruments.

    image: ../Art/xcode_instruments_menu_2x.png

    Instruments啓動並且其圖標出現在您的Dock中

    image: ../Art/instruments_app_icon_small_2x.png

  3. 按住Control鍵並點按Dock中的Instruments圖標,然後從快捷菜單中選擇 Options > Keep in Dock 

    image: ../Art/instruments_dock_contextual_menu_options_keepindock_2x.png


三、Launchpad啓動


Launchpad 不直接顯示Instruments,因爲Instruments在Xcode中集成的。你可以手動的把Instruments放到Launchpad裏面。

添加Instruments到Launchpad步驟如下:

  1. 打開Xcode.

  2. 選擇 Xcode > Open Developer Tool > Instruments.

    image: ../Art/xcode_instruments_menu_2x.png

    Instruments啓動並且其圖標出現在您的Dock中

    image: ../Art/instruments_app_icon_small_2x.png

  3. 按住Control鍵並點按Dock中的Instruments圖標,然後從快捷菜單中選擇Options > Show in Finder

    image: ../Art/instruments_dock_contextual_menu_options_2x.png

  4. 選擇show in Finder的時候會打開Instruments.app所在的文件夾,然後把Instruments.app拖到您的應用程序文件夾中

  5. 你在Launchpad就會看到這個Instruments這個app,這時候你不能直接打開。要刪除應用程序文件夾中的Instruments這個app,然後就可以打開了。


    image: ../Art/launchpad_instruments_2x.png


四、命令行打開

你可以使用命令行打開

方法如下:

  1. 打開 Terminal (in /Applications/Utilities/).

  2. 運行下面的命令:

    open /Applications/Xcode.app/Contents/Applications/Instruments.app

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章