收藏 分享(赏)

Instruments 用户指南.pdf

上传人:HR专家 文档编号:6227874 上传时间:2019-04-03 格式:PDF 页数:126 大小:3.66MB
下载 相关 举报
Instruments 用户指南.pdf_第1页
第1页 / 共126页
Instruments 用户指南.pdf_第2页
第2页 / 共126页
Instruments 用户指南.pdf_第3页
第3页 / 共126页
Instruments 用户指南.pdf_第4页
第4页 / 共126页
Instruments 用户指南.pdf_第5页
第5页 / 共126页
点击查看更多>>
资源描述

1、Instruments 用户指南 原著:Apple Inc. 翻译:謝業蘭【老狼】 联系: 鸣谢:有米移动广告平台 CocoaChina 社区Instruments User Guide 目录 INSTRUMENTS用户指南 . I INSTRUMENTS用户指南介绍 2 本文档组织结构 2 第一章 INSTRUMENTS快速入门 . 4 1.1 启动I NSTRUMENTS . 5 1.2 创建一个跟踪文档 5 1.3 浏览跟踪文档窗口 7 1.4 示例:快速使用一个跟踪 10 1.5 下一步是什么? 10 第二章 添加和配置INSTRUMENTS 工具 11 2.1 使用I NSTRUM

2、ENT库 . 11 2.1.1 修改库试图模式 . 12 2.1.2 查找库里面的某个instrument 工具 13 2.1.3 新建一个自定义的instrument 分组 15 2.2 添加和删除I NSTRUMENTS工具 . 20 2.3 配置一个 INSTRUMENT工具 . 21 第三章 记录跟踪数据 23 3.1 选择需要跟踪的进程 23 3.1.1 跟踪所有进程 . 23 3.1.2 跟踪一个已有的进程 . 24 3.1.3 跟踪一个新的进程 . 24 3.1.4 给每个 Instrument工具指定不同的目标 26 3.2 收集数据 26 3.3 使用快速启动键启动I NST

3、RUMENTS . 27 3.4 以最小模式运行 28 3.5 从X CODE运行 INSTRUMENTS应用 . 29 3.6 无线连接 IOS设备 . 29 第四章 记录用户界面轨迹 32 4.1 记录用户界面轨迹 32 4.2 重复记录用户界面轨迹 33 4.3 回放用户界面轨迹 34 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.1 Instruments User Guide 第五章 查看和分析跟踪数据 36 5.1 查看数据的工具 36 5.1.1 跟踪面板 . 36 5.1.2 详细面板 . 41 5.1.3 扩展详细面板

4、. 44 5.1.4 运行浏览器 . 46 5.2 分析技术 47 5.2.1 使用Sampler Instrument 分析数据 47 5.2.2 使用Allocations Instrument工具分析数据 . 49 5.2.3 查找内存泄露 . 53 5.2.4 分析Core Data 应用程序 . 54 第六章 保存和导入跟踪数据 55 6.1 保存跟踪文档 55 6.2 导出跟踪数据 55 6.3 从S AMPLE工具中导入数据 . 56 6.4 使用DT RACE数据 56 第七章 使用DTRACE 创建自定义INSTRUMENTS 工具 57 7.1 关于自定义 INSTRUME

5、NTS工具 . 57 7.2 创建自定义的I NSTRUMENT工具 . 58 7.2.1 添加和删除探针 . 60 7.2.2 指定探针的提供者 . 60 7.2.3 给探针添加断言 . 61 7.2.4 给探针添加动作 . 63 7.2.5 编写自定义脚本的提示 . 65 7.2.6 编写BEGIN 和 END脚本 . 65 7.2.7 从自定义脚本里面访问内核数据 . 66 7.2.8 变量作用域 . 67 7.2.9 查找脚本错误 . 67 7.3 导出DT RACE脚本 68 第八章 内置INSTRUMENTS 工具 . 69 8.1 CORE DATA INSTRUMENTSCOR

6、E DATA相关 69 8.1.1 Core Data Saves 69 8.1.2 Core Data Fetches . 70 8.1.3 Core Data Faults 70 8.1.4 Core Data Cache Misses 71 8.2 DISPATCH INSTRUMENTS并发相关 72 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.2 Instruments User Guide 8.2.1 Dispatch . 73 8.3 ENERGY DIAGNOSITICS INSTRUMENTS电池诊断相关 75 8.3

7、.1 电量使用(Energy Usage ) . 76 8.3.2 CPU 活动(CPU Acitivity ) . 76 8.3.3 显示亮度(Display Brightness ) . 77 8.3.4 休眠/ 唤醒( Sleep/Wake) . 77 8.3.5 蓝牙(Bluetooth ) . 77 8.3.6 无线( WiFi) . 77 8.3.7 定位( GPS) 78 8.4 FILE SYSTEM INSTRUMENTS文件系统相关 78 8.4.1 I/O 活动 (I/O Activity) 78 8.4.2 文件锁 (File Locks) . 81 8.4.3 文件属

8、性 (File Attributes) . 81 8.4.4 文件活动(File Activity) . 82 8.4.5 目录I/O( Directory I/O) 83 8.5 GARBAGE COLLECTION INSTRUMENTS垃圾回收相关 84 8.5.1 GC Total 84 8.5.2 垃圾回收(Garbage Collection ) 85 8.6 GRAPHICS INSTRUMENTS绘图相关 . 86 8.6.1 核心动画(Core Animation ) . 86 8.6.2 OpenGL驱动器( OpenGL Driver) 87 8.6.3 OpenGL E

9、S驱动器( OpenGL ES Driver) . 87 8.6.4 OpenGL ES分析器( OpenGL ES Analyzer) . 89 8.7 INPUT/OUTPUT INSTRUMENTS输入输出相关 . 90 8.7.1 读/ 写(Reads/Wirtes) . 90 8.8 MASTER TRACKS INSTRUMENTS界面操作跟踪相关 91 8.8.1 用户界面(User Interface ) 91 8.9 MEMORY INSTRUMENTS内存相关 91 8.9.1 共享内存(Shared Memory ) . 91 8.9.2 分配内存(Allocations

10、 ) . 92 8.9.3 内存泄露(Leaks) . 94 8.10 SYSTEM INSTRUMENTS系统相关 95 8.10.1 时间分析器( Time Profiler) 95 8.10.2 旋转监控器( Spin Monitor) 96 8.10.3 取样(Sampler ) 97 8.10.4 进程(Process ) . 98 8.10.5 网络活动监控器(Network Activity Monitor ) . 99 8.10.6 内存监控器( Memory Monitor) . 99 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsRes

11、erved.3 Instruments User Guide 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.4 8.10.7 硬盘监控器( Disk Monitor) . 99 8.10.8 CPU监控器( CPU Monitor) . 100 8.10.9 活动监控器( Activity Monitor) 100 8.11 THREADS/LOCKS INSTRUMENTS线程相关 100 8.11.1 Java线程( Java Thread) . 100 8.12 UI AUTOMATION界面自动化相关 101 8.12.1 使用A

12、utomation Instrument 工具 101 8.12.2 访问和操作用户界面元素 . 104 8.12.3 添加灵活的超时间 113 8.12.4 验证测试结果 114 8.12.5 输出测试结果和数据的日子 114 8.12.6 处理警告 115 8.12.7 检测和指定设备的方向 116 8.12.8 测试多任务 118 8.13 USER INTERFACE INSTRUMENTS用户界面相关 118 8.13.1 Cocoa事件( Cocoa Events) 118 8.13.2 Carbon事件( Carbon Events) . 119 结束语 . 120 推荐资源 .

13、 121 Instruments User Guide 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.1 Instruments User Guide Instruments用户指南介绍 Instruments 是应用程序用来动态跟踪和分析 Mac OS X 和 iOS 代码的实用工具。这是一个灵活而强大的工具,它让你可以跟踪一个或多个进程,并检查收集的数据。这样,Instruments 可以帮你更好的理解应用程序和操作系统的行为。 使用 Instruments 应用,你可以使用特殊的工具(即 instruments 工具)来跟踪同一进程

14、不同方面的行为。 你也可以使用该应用来记录一系列用户界面的动作并响应它们,同时也可以使用一个或多个 instruments 工具来收集数据。 Instruments 应用包含以下功能: z 分析一个或多个进程的行为 z 记录一系列用户的动作并响应它们,可靠 的再现这些事件并收集多次运行的数据 z 创建你自己自定义的 DTrace instruments 来分析系统和应用程序的行为 z 保存用户界面记录和 instruments 的配置为模板,并从 Xcode 里面访问 使用 Instruments,你可以: z 追查代码中难以重现的问题 z 对你的程序进行性能分析 z 自动化测试你的代码 z

15、对你程序进行压力测试 z 进行一般的系统级故障诊断 z 对你的代码如何工作有更深入的了解 Instruments 在 Xcode 3.0 和 Mac OS X 10.5 及其之后可用。 本文档描述了 Instruments 的用户界面,给出了一个如何使用 Instruments 来跟踪进程和查看数据的预留。 目的是让开发人员和系统管理员使用 Instruments 能更好的了解他们程序或系统作为一个整体的行为。 本文档组织结构 以下章节描述了如何使用 Instruments 应用: z “Instruments 快速入门 ”给出了Instruments的概要预览,并介绍了主体窗2011-12-

16、07|2011YouMiMobileCo.Ltd.AllRightsReserved.2 Instruments User Guide 口。 z “ 添加和配置Instruments ”描述了如何添加和配置instruments工具,以及在一个或多个进程里面运行它们收集数据 。本章还介绍如何对程序进行选择行跟踪。 z “记录跟踪数据 ”描述了如何初始化跟踪并收集跟踪数据的方法。 z “记录用户界面轨迹 ”描述如何记录和重放一系列有顺的用户操作。 z “查看和分析跟踪数据 ”描述了用来查看Instruments返回数据的工具。 z “ 保存和导入跟踪数据 ”描述了如何保存跟踪文档和数据,以及如何

17、从其他来源导入数据。 z “ 使用DTrace创建自定义工具 ”显示了如何创建和配置基于DTrace的自定义工具。 z “内置的instruments工具 ”详细介绍了Instruments内置的工具。 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.3 Instruments User Guide 第一章 Instruments快速入门 Instruments 是一个很强大的工具,你可以用它来收集关于一个或多个系统进程的性能和行为的数据,并跟踪随着时间产生的数据。不像其他大部分性能和调试工具那样,Instruments 让你可以广泛收集不

18、同类型的数据,并且可以一边查看它们。这样你可以发现变化趋势,这在其他工具里面是很难做到的。比如,你之前需要采样程序的样本,并分析它们在两个独立的执行文件里面运行的内存行为。在 Instruments里面,你可以同时完成这些工作。你可以用这些结果数据来发现你代码中正在运行部分的变化趋势和它们的内存使用情况。 Instruments 应用使用 instruments 工具来收集关于进程随时间推移产生的数据。每个 instruments 收集和显示不同类型的数据,比如文件访问、内存使用等等。Instruments 包括一个标准 instruments 工具库,你可以使用它分析你代码的很多方面。你可以

19、配置 instruments 来收集关于同一个或者不同系统进程的数据。你可以使用自定义的 instruments 工具新建接口来创建新的自定义 instruments 工具,它使用DTrace 程序来收集你想要的数据。 注意: 不少应用程序(iTunes、DVD Pla yer 和 Front Row,还有使用 QuickTime 的应用)为了保护敏感数据,不允许使用 DTrace 来收集数据(无论暂时的还是永久的) 。 所有 Instruments 的工作都在一个跟踪文档(trace documents)里面完成。一个跟踪文档收集那些被 instruments 聚集的与该文档有关的数据。 每

20、个跟踪文档通常包含一个会话的价值数据,这也是作为一个单一的跟踪。你可以保存跟踪文档到你已经收集的跟踪数据备份里面,然后可以在以后再次打开并查看它们。 尽管大部分的 instruments 工具旨在收集数据,但是其中最精密的 instruments工具可以帮助自动化收集数据。使用 Instruments User Interface 工具,你可以在收集数据的过程中记录用户事件。你可以使用这些数据来可靠的重复重现这一系列有序的事件。每次你通过这序列运行,你的跟踪文档在其他 instruments 工具里面收集新的跟踪数据,并且和之前一样边收集边显示这些数据。这些特性让你比较跟踪的数据来提高你的代码

21、,并验证你的改动获得预期的结果。 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.4 Instruments User Guide 1.1 启动 Instruments Instruments 作为 Xcode 工具安装的一部分。有几个启动 Instruments 的方法: z 你可以在 Finder 里面双击 Instruments 应用的图标来启动它。 Instruments 应用位于 /Applications 目录下面, 代表你 Xcode 安装的根路径。(Xcode 默认的安装根路径时 /Developer 目录。) z 你可以通

22、过 Xcode 来启动 Instruments,并把你工程下的可执行文件作为它的目标。在 Xcode 的菜单里面选择 Run Start with Performance Tool 来选择Instruments 模板(注:在 Xcode 4.0 以上已经无此方法,你需要通过 Profile来启动,更多请 Google 一下)。Instruments 以特定的模板启动,并且准备好运行 Xcode 配置的当前可执行文件。 注意: 当你以这种方式来启动一个 Instruments 模板的时候,在完成跟踪之后,你必须显示的停止你当前的执行文件(无论是从程序里面还是从 Instruments 里面)。这

23、不会关闭Instruments 的跟踪文档。相反,你可以重启可执行文件,Instruments 显示旧的对话框旁边显示新的对话框,就如图 4-2 显示那样。这样可以让你在 Xcode 里面修改你的代码,重新编译,运行和比较新的改变产生的跟踪数据。 z 你可以通过双击一个 Instruments 的模板文件或者跟踪文档来启动它。查看”保存和导入跟踪数据”部分来掌握如何保存一个Instruments的配置文件或者使用用户界面记录作为一个模板文件。 1.2 创建一个跟踪文档 当你启动 Instruments 后,应用会自动为你创建一个文档。你同样可以通过选择File New 来创建一个新的文档。 你

24、每创建一个新的文档,Instruments 都会提示你选择一个开始模板。这些模板定义了一些你将要在你的跟踪文档里面使用的 instruments 工具集。Instruments 提供了几种不同的模板,在表 1-1 里面列举出来,每个模板都有不同的使用目的。如果你手工的给你的跟踪文档添加一个指定的 instruments 工具的话,你可以使用空白模板。 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.5 Instruments User Guide Table 1-1 Instruments starting templates Templa

25、te Type DescriptionBlank Mac OS X, iOS, iOS Simulator, User Creates an empty trace document to which you can add your own combination of instruments. To learn how to select and add instruments, see “Adding and Configuring Instruments.” For descriptions of the individual built-in instruments, see “Bu

26、ilt-in Instruments.” Activity Monitor Mac OS X, iOS, iOS Simulator Adds the Activity Monitor instrument to your document. Use this template if you want to correlate the system workload with the virtual memory size. Allocations Mac OS X, iOS, iOS Simulator Adds the Allocations and VM Tracker instrume

27、nts to your document. Use this template to monitor memory and object-allocation patterns in your program. (To use this template, you must launch your process from Instruments.) Automation iOS, iOS Simulator Adds the Automation instrument to your document. Use this template to automate user interface

28、 tests of your iOS application. Core Animation iOS Adds the Core Animation and Sampler instruments to your document. Use this template to measure the number of Core Animation frames per second in a process running on an iOS device, and to see visual hints that help you understand how content is rend

29、ered on the screen. Core Data Mac OS X Adds the Core Data Fetches, Core Data Cache Misses, and Core Data Saves instruments to your document. Use this template to monitor data store interactions in a Core Data application. CPU Sampler Mac OS X, iOS, iOS Simulator Adds the Sampler and CPU Monitor inst

30、ruments to your document. Use this template if you want to correlate the overall system workload with the work being done specifically by your application. Dispatch Mac OS X Adds the Dispatch instrument to your document. Use this template if you want to capture information about GCD queues created b

31、y your application and about the block objects executing on these queues. Energy Diagnostics iOS Adds the Energy Diagnostics, CPU Activity, Display Brightness, Sleep/Wake, Bluetooth, WiFi, and GPS instruments to your document. Use this template to get diagnostic information regarding energy usage in

32、 iOS devices. File Activity Mac OS X, iOS Simulator Adds the File Activity, Reads/Writes, File Attributes, and Directory I/O instruments to your document. Use this template if you want to examine file usage patterns in the system. This combination of instruments monitors open, close, read, and write

33、 operations on files and also monitors changes in the file system itself, including permission and owner changes. GC Monitor Mac OS X Adds the ObjectGraph, Allocations, and Garbage Collection instruments to your document. Use this template to measure the data reclaimed in the scavenge phase of the g

34、arbage collector. Leaks Mac OS X, iOS, iOS Simulator Adds the Allocations and Leaks instruments to your document. Use this template to monitor memory usage in your application and to detect memory leaks. (To use this template, you must launch your process from Instruments.) Multicore Mac OS X Adds t

35、he Thread States and Dispatch instruments to your document. Use this template to analyze multicore performance, including thread state, dispatch queues, and block usage. OpenGL ES Analysis iOS Adds the OpenGL ES Analyzer and OpenGL ES Driver instruments to your document. Use this template to measure

36、 OpenGL ES activity and get 2011-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.6 Instruments User Guide recommendations for addressing problems.OpenGL ES Driver iOS Adds the OpenGL ES Driver and Sampler instruments to your document. Use this template to determine how efficiently youre using OpenGL a

37、nd the GPU on iOS devices. Sudden Termination Mac OS X Adds the Sudden Termination and Activity Monitor instruments to your document. Use this template to analyze sudden termination support. It reports unprotected file-system access the target process should be, but is not, guarding with calls to di

38、sable sudden termination. It also provides activity monitoring across all processes, including sudden termination status for each. System Usage iOS Adds the I/O Activity instrument to your document. Use this template to record calls to functions that operate on files in a process running on an iOS d

39、evice. Threads Mac OS X, iOS Simulator Adds the Thread States instrument to your document. Use this template to analyze thread state transitions within a process, including running and terminated threads, thread state, and associated backtraces. Time Profiler Mac OS X, iOS, iOS Simulator Adds the Ti

40、me Profiler instrument to your document. Use this template to perform low-overhead time-based sampling of one or all processes. UI Recorder Mac OS X Adds the User Interface instrument to your document. Use this template as a starting point for recording a series of user interactions with your applic

41、ation. You can use this feature to reproduce a series of events multiple times, gathering a new set of data during each successive run. You can then compare the sets of data knowing that the behavior that generated them was identical. Typically, you would start with this template and add additional

42、instruments to your document to gather data. Zombies Mac OS X, iOS Simulator Adds the Allocations instrument to your document. Use this template to measure general memory usage while focusing on the detection of over-released “zombie“ objects. 如果你不想让 Instruments 在你新建一个文档的时候询问你使用那个模板,你可以在 Instruments

43、 的偏好设置里面勾选 Suppress template chooser 选项来禁止模板选择。关于更多在 Instruments 文档里面添加和配置 instrumtns 工具的的信息,参阅“添加和配置 Instruments”部分。 1.3 浏览跟踪文档窗口 跟踪文档自己包含一个收集和分析数据的空间。你使用这些文档来组织和配置你需要用来收集数据的 instruments 工具, 并且可以使用这些文档来查看你已经收集的高级和低级的数据。 图 1-1 显示了典型的跟踪文档。一个跟踪文档窗口显示很多信息,所以需要很好的组织。正如你使用跟踪文档来工作一样,信息流从左到右。在你的文档窗口里面,2011

44、-12-07|2011YouMiMobileCo.Ltd.AllRightsReserved.7 Instruments User Guide 越右边的窗口数据越详细。表 1-2 提供了该窗口关键区域的介绍。 Figure 1-1 The Instruments window while tracing 表 1-2 列出了图 1-1 中显示的关键特性,并提供了一个更深入使用这些特性的讨论。 Table 1-2 Trace document key features Feature Description Instruments pane This pane holds the instrume

45、nts you want to run. You can drag instruments into this pane or delete them. You can click the inspector button in an instrument to configure its data display and gathering parameters. To learn more about instruments, see“Adding and Configuring Instruments.” Track pane The track pane displays a grap

46、hical summary of the data returned by the current instruments. Each instrument has its own “track,” which provides a chart of the data collected by that instrument. The information in this pane is read-only. You do use this pane to select specific data points you want to examine more closely, howeve

47、r. The track pane is described in more detail in “The Track Pane.” Detail pane The Detail pane shows the details of the data collected by each instrument. Typically, this pane displays the explicit set of “events” that were gathered and used to create the graphical view in the track pane. If the cur

48、rent instrument allows you to customize the way detailed data is displayed, those options are also listed in this pane. For more information about this pane, see “The Detail Pane.” Extended Detail pane The Extended Detail pane shows even more detailed information about the item currently selected in the Detail pane. Most commonly, this pane displays the complete stack trace, timestamp, and other instrument-specific d

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 实用文档 > 简明教程

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报