iOS Instruments Time Profiler

Time Profiler

有两种方式可以打开Time Profiler。我们先来介绍第一种:

一、从Debug界面打开Time Profiler

1)首先打开Xcode,在编译成功后运行App,这里测试Demo是选择在游伴项目中直接添加一部分进行测试,打开Debug面板,如下图所示。

 

    @测试代码中主要是增加了两个for循环,为了方便Time Profiler分析。


2)右键点击图片左侧中的CPU,显示如下界面

 

    @(1) :图片右侧红色线框圈住的部分。CPU占用百分比。这里是刚启动的时候,CPU占用比较高。CPU 最大为400%,这里可以认为是MAC机器的CPU共计400%,但只分配给Simulator 100%。

    @(2) : 图片右侧蓝色线框圈住的部分。CPU使用的比较。由于是用Simulator进行演示分析,这里有MAC机器的其他程序也在运行。可以看到紫色部分是我们的项目MSGS占用98%,Other Processes可以忽略不计。

    @(3) : 图片右侧紫色线框圈住的部分。CPU启动的时间。这里有三个参数。

               Duration:CPU运行时间 (7 sec)

               High:      最高占用比   (98%)

               Low:         最低占用比   (13%)

    @(4): 图片右侧黑色线框圈住的部分。各个线程占用CPU的详情。刚启动时,只有一个主线程运行。

    @(5): 图片右侧黄色线框圈住的部分。在Instruments里打开Time Profiler。


3)打开上一步中的@(5),在Instruments 中打开Time Profiler。点击后会弹出以下界面

 

     @(1) :Restart,在Instruments重新启动项目进行Time Profiler分析。

     @(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

第二种打开方式

二、直接从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)其余步骤参考 一、4)及其后续的步骤即可。


转载于:https://my.oschina.net/u/1782374/blog/385282

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值