diff --git a/project/visionos/Markdown/diagnosing-and-resolving-bugs-in-your-running-app.md b/project/visionos/Markdown/diagnosing-and-resolving-bugs-in-your-running-app.md new file mode 100644 index 0000000..f117001 --- /dev/null +++ b/project/visionos/Markdown/diagnosing-and-resolving-bugs-in-your-running-app.md @@ -0,0 +1,116 @@ +# 诊断和解决运行中应用的错误 + +检查应用以隔离错误、定位崩溃、识别过多的系统资源使用、可视化内存错误并调查其外观问题。 + +## 概述 + +单元测试能确定代码是否能提供符合预期的结果,但不能解释不符合预期的原因。要诊断错误,请连接调试器,重现错误,然后在应用运行时使用断点检查代码中关键点的变量,从而找出错误的根本原因。如果在配置方案的运行操作的“信息(Info)”标签下勾选了“调试可执行文件(Debug executable)”复选框,应用在使用该配置方案时就会自动附加调试器。要将调试器附加到已运行的进程,请选择“调试(Debug)” → “附加到进程(Attach to Process)”,然后从列表中选择应用进程。按照同样的流程诊断并解决代码中的错误、崩溃、内存泄漏和布局问题。 + +### 暂停应用以检查变量并隔离错误 + +要修复错误,首先需要了解导致错误的原因。要缩小错误原因的范围,需要制定一套可靠的重现步骤: + +1. 确定源代码中错误发生的位置。 +2. 源代码中,在你认为错误出现的位置之前设置断点,暂停应用。 +3. 查看变量,确认它们是否拥有你所期望的值。如果没有,请从步骤1重新开始。 +4. 逐步检查代码,观察变量的变化。注意变量出现意外值的位置。 +5. 分析代码,确定修复方法。 + +确定了错误的尝试性修复方案后,修改代码并重新测试来试着重现错误,从而确认诊断。如果更改后问题得到了解决,则说明你已经解决了错误。如果更改后问题仍未解决,则应重新考虑错误可能发生的位置,并重复上述步骤以隔离和修复错误。 + +有关设置断点和检查变量的更多信息,请参阅[设置断点以暂停正在运行的应用](https://developer.apple.com/documentation/Xcode/setting-breakpoints-to-pause-your-running-app),以及[逐步检查代码和变量以隔离错误](https://developer.apple.com/documentation/Xcode/stepping-through-code-and-inspecting-variables-to-isolate-bugs)。 + +### 查找崩溃、异常和运行时问题 + +当你的应用出现崩溃、异常或运行时问题时,由于崩溃的堆栈跟踪并不总是指向导致崩溃的代码行,因此要准确定位导致问题的代码可能很有难度。请使用下面的规则识别问题的特征,然后设置正确的断点类型: + +- 停止在 `main` 或突出显示 `AppDelegate` 的崩溃通常是 Objective-C 异常。 +- 由运行时问题导致的崩溃也会在 `main` 或突出显示 `AppDelegate` 时停止,并可能出现类似以下的消息: “Thread 8: EXC_BAD_INSTRUCTION (code=…)”。 +- 在未捕获或未处理的 Swift 错误处停止的崩溃会显示致命错误消息并指向 Swift 错误。 + +根据问题特征在代码中的特定位置添加断点,然后当应用在断点处停止时,检查代码执行的状态。有关设置断点和识别崩溃的更多信息,请参阅[设置断点以暂停正在运行的应用](https://developer.apple.com/documentation/Xcode/setting-breakpoints-to-pause-your-running-app)和[识别常见崩溃的原因](https://developer.apple.com/documentation/xcode/identifying-the-cause-of-common-crashes)。 + +> 注意 +> 当你的 Swift 代码使用来自使用 Objective-C 的模块代码时,可能会接收到 Objective-C 异常。 + +### 在不暂停的情况下检查变量和执行顺序 + +在开发代码时,记录操作和变量值很有帮助,这样你就能了解代码的运行方式以及变量在应用中不同点的值。当你开发*并行代码*(即在多个队列或线程中同时执行的代码)时尤其如此,因为错误可能是间歇性的,很难重现。通常情况下,你在正常执行时会重现错误,但在调试器中却不会,因为正常执行和调试之间的时序不同。调试器提供了在不暂停和干扰并行代码时序的情况下检查变量的工具。 + +开发人员通常会添加 `print` 或 `NSLog` 语句来查看变量值。这种方法虽然有效,但会增加额外的代码,且这些代码在开发完成后并无用处,还会给应用留下一个嘈杂的控制台,使诊断后续错误变得更加困难。相反,我们可以使用断点操作来了解应用中事件的发生时间,并在不暂停的情况下检查变量值。 + +想要在对时序影响最小的情况下确认代码是否执行,请使用断点操作播放声音并继续执行。如果调试器在运行应用时到达了断点,它就会播放声音并确认执行。 + +要在不暂停的情况下将变量值记录到控制台,可通过“调试器命令”操作添加一个断点,使用 `po` 将对象的评估结果打印出来,或使用 `v` 将变量值打印到控制台。为断点选择“评估操作后自动继续”选项以防止暂停。 + + + +要将自定义文本记录到控制台并为变量值添加上下文,可添加带“日志信息”操作的断点。指定自定义文本,并包含表达式、断点名称或断点命中计数,以提供更多信息。 + +> 注意 +> 由于 `po` 会动态编译代码以评估表达式,因此评估变量并将其记录到控制台需要更多时间。为减少时序问题,可使用 `v` 来记录变量值。 + +使用其他断点操作可执行 AppleScript 或 shell 脚本,或捕获 GPU 帧。 + +有关检查变量的更多信息,请参阅[设置断点以暂停正在运行的应用](https://developer.apple.com/documentation/Xcode/setting-breakpoints-to-pause-your-running-app),以及[逐步检查代码和变量以隔离错误](https://developer.apple.com/documentation/Xcode/stepping-through-code-and-inspecting-variables-to-isolate-bugs)。 + +### 识别潜在的 CPU 和内存过度使用 + +在开发和测试过程中,CPU 和内存的过度使用是一个经常容易被忽视的问题。Xcode 的调试器在调试导航器中提供了仪表盘,以帮助调查潜在问题。在测试应用时监控仪表盘,以发现异常使用情况。点击仪表盘可查看更详细的信息。 + +

+ +

+ +CPU 测量值显示应用在一段时间内处理指令所需的 CPU 占用率。当应用正在绘制用户界面、处理从网络获取的数据或执行计算时,CPU 使用率会在短时间内上升到相当高的水平,这是正常现象。当这些任务完成后,应用处于闲置状态,等待用户执行操作时,CPU 使用率应为零或非常低。如果出现以下情况,请进行额外分析: + +- 当应用看似闲置时,CPU 使用率持续高于零。 +- 使用率多次超过100%。 +- 非常高且用户界面出现卡顿。 + +有关提高性能的更多信息,请参阅[提高应用的性能](https://developer.apple.com/documentation/Xcode/improving-your-app-s-performance)。 + +内存量表显示应用在一段时间内使用的内存量。第一次启动应用时,内存使用量很小,不到 10 MB,随着用户浏览用户界面,内存使用量会逐渐增加。如果你从网络中获取、处理和存储数据,或执行复杂的计算,它也会增加。当处理完成后,它就会降低。在你浏览应用时,请注意观察仪表盘,并注意内存使用量何时上升,何时下降。当你显示模态视图或向将视图添加到导航控制器时,内存使用量会增加;而当你取消或从这些视图返回时,内存使用量会减少。如果内存使用量持续增加而不减少,请调查是否存在内存泄漏或内存弃用的情况。有关减少内存使用和解决内存泄漏问题的更多信息,请参阅下面的章节[可视化并诊断内存使用量的增加](https://developer.apple.com/documentation/xcode/diagnosing-and-resolving-bugs-in-your-running-app#Visualize-and-diagnose-increasing-memory-usage)和[减少应用的内存使用量](https://developer.apple.com/documentation/xcode/reducing-your-app-s-memory-use)。 + +### 检测高磁盘访问和网络使用 + +请注意频繁访问磁盘和网络资源导致的问题。你也可以使用 Xcode 调试器中的仪表来监控这些资源。磁盘 I/O 仪表显示应用在一段时间内从磁盘读取和写入的数据量。该仪表显示你是否 + +- 在应用中存储用户生成的数据。 +- 在用户偏好设置中存储数据。 +- 从网络获取数据并存储。 +- 从应用捆绑包或应用目录中读取数据。 + +频繁从磁盘存储和读取数据比从内存存储和读取数据耗电更多,而且会增加用户设备的损耗。要知道磁盘使用是否异常,需要了解存储和读取数据的大小,并将其与仪表中观察到的数据进行比较。例如,如果你下载并存储了一个 5 MB 的图片文件用于在经常使用的视图中显示,但却写入了超过 50 MB 的数据,那么请调查云端图像是否经常变化,或者你是否需要配置网络以防止重新下载相同的图像。如果从磁盘读取的数据比预期的要多,请调查内存缓存解决方案是否有帮助,或者你是否从应用或视图生命周期中的错误点启动了数据读取,且读取频率过高。有关减少磁盘写入的更多信息,请参阅[减少磁盘写入](https://developer.apple.com/documentation/xcode/reducing-disk-writes)。 + +网络 I/O 仪表显示了一段时间内应用从网络读取和写入的数据量。如果应用只使用本地资源,则可能不会从网络读取或写入任何数据。通过网络通信数据会消耗能源并缩短设备的电池寿命,因此应尽可能减少数据传输。要了解应用的网络使用情况,请在应用从网络发送或接收数据时观察网络 I/O 测量值。例如,如果你对下载的图片添加了缓存系统,而网络使用量在访问图片时增加,请确认应用和服务器中的缓存设置是否正确。如果你正在上传用户生成的内容,而在网络状况不佳的情况下频繁上传失败会导致网络使用量增加,那么请构建一个在上传失败时恢复并重新启动,而不是重新上传整个文件的系统。 + +### 可视化并诊断内存使用量的增加 + +利用内存图诊断内存泄漏和内存弃用的原因。内存泄漏的明显症状是尽管应用的使用情况表明内存使用正在减少,实际上内存使用量却随着时间的推移持续增加。内存泄漏可能发生在*循环引用*中,即对象之间保持强引用,但应用不再引用它们。这些对象保留在内存中,应用无法删除它们。当你创建了对象且代码仍在引用它们,但应用不再需要或使用它们时,就会发生*内存弃用*。 + + + +要在调试器中查看内存图,请在断点处暂停应用,然后单击调试栏中的“调试内存图(Debug Memory Graph)”按钮。或者,在应用运行时单击“调试内存图”按钮,暂停应用并显示内存图。 + +内存图视图将调试导航器中的堆栈跟踪替换为按库排列的类型列表,每个类型都有一个称为*节点*的实例列表。选择一个节点即可查看其内存图。 + +节点的内存图显示该节点的所有内存引用,并突出显示强引用。按住 Control 键单击内存图中的任意节点,可执行更多操作,如“快速查看(Quick Look)”或将说明打印到控制台。选择“聚焦节点(Focus on Node)”以显示所选节点的图表。单击引用可查看其详细信息,包括变量名称、引用类型以及内存中的源对象和目标对象。 + + + +要解决循环引用的内存泄漏问题: + +1. 在浏览应用时观察内存仪表。 +2. 注意当应用实例化对象时,内存使用量会增加,而当你期望系统释放对象时,内存使用量却不减少。 +3. 检查内存图,查看对象实例的数量是否出乎意料,或者是否存在不恰当的强引用。 +4. 如果存在对某个对象的强引用,请按住 Control 键并单击强引用的节点,然后选择“聚焦节点”查看其图表。如果此节点也有来自对象的强引用,则这是一个循环引用。 +5. 解决循环引用的方法是令引用关系的一方使用弱声明来引用另一个对象,或者通过删除对其他对象的所有依赖关系来完全删除引用。重新测试以确认更改是否修复了问题。 + +要解决内存弃用问题,请确定应用生命周期中不再需要废弃对象的时间,并删除对该对象的所有引用。 + +### 检查并解决外观和布局问题 + +某些应用外观或布局方面的问题,只有当你将系统配置为特定界面风格、动态文本大小或当你的应用使用特定辅助功能时才会出现。在以 iOS、macOS 和 tvOS 应用为目标时,请使用环境覆盖在这些环境中测试你的界面。要了解涉及视图位置或大小的问题,可能需要在其他图层的视图上下文中进行检查。在面向 iOS、macOS、tvOS 和 watchOS 应用时,可使用视图调试器显示视图层次结构的 3D 表示形式,来帮助诊断这些问题。visionOS 应用中的实体与其周围环境有时会以你意想不到的方式进行交互。启用可视化来表示坐标轴、边界框和其他通常不可见的信息,这有助于理解这些交互。 + +有关使用这些功能调试应用外观的信息,请参阅[诊断运行中应用的外观问题](https://developer.apple.com/documentation/xcode/diagnosing-issues-in-the-appearance-of-your-running-app)。 \ No newline at end of file diff --git a/project/visionos/diagnosing-and-resolving-bugs-in-your-running-app.yml b/project/visionos/diagnosing-and-resolving-bugs-in-your-running-app.yml index b2a3b06..5b8cb89 100644 --- a/project/visionos/diagnosing-and-resolving-bugs-in-your-running-app.yml +++ b/project/visionos/diagnosing-and-resolving-bugs-in-your-running-app.yml @@ -1,186 +1,186 @@ - 内容: 'Diagnosing and resolving bugs in your running app' 提示: '' - 翻译: '' + 翻译: '诊断和解决运行中应用的错误' - 内容: 'Inspect your app to isolate bugs, locate crashes, identify excess system-resource usage, visualize memory bugs, and investigate problems in its appearance.' 提示: '' - 翻译: '' + 翻译: '检查应用以隔离错误、定位崩溃、识别过多的系统资源使用、可视化内存错误并调查其外观问题。' - 内容: 'Overview' 提示: '' - 翻译: '' + 翻译: '概述' - 内容: 'Unit testing determines whether your code delivers results that meet your expectations, but it doesn’t explain the cause when it doesn’t. To diagnose an error, attach the debugger, reproduce the error, and then narrow down its root cause by inspecting your variables at key points in your code while the app is running with breakpoints. If you configure a scheme’s run action for debugging by using the Debug executable checkbox in Info settings, the app will attach to the debugger automatically when the app uses the scheme. To attach the debugger to a process that is already running, choose Debug → Attach to Process, and select your app’s process from the list. Follow this same process to diagnose and resolve errors in your code, crashes, memory leaks, and layout problems.' 提示: '' - 翻译: '' + 翻译: '单元测试能确定代码是否能提供符合预期的结果,但不能解释不符合预期的原因。要诊断错误,请连接调试器,重现错误,然后在应用运行时使用断点检查代码中关键点的变量,从而找出错误的根本原因。如果在配置方案的运行操作的“信息(Info)”标签下勾选了“调试可执行文件(Debug executable)”复选框,应用在使用该配置方案时就会自动附加调试器。要将调试器附加到已运行的进程,请选择“调试(Debug)” → “附加到进程(Attach to Process)”,然后从列表中选择应用进程。按照同样的流程诊断并解决代码中的错误、崩溃、内存泄漏和布局问题。' - 内容: 'Pause the app to inspect variables and isolate bugs' 提示: '' - 翻译: '' + 翻译: '暂停应用以检查变量并隔离错误' - 内容: 'To fix a bug, you first need to understand what is causing it. To narrow down the cause of a bug, develop a set of steps to reliably reproduce it:' 提示: '' - 翻译: '' + 翻译: '要修复错误,首先需要了解导致错误的原因。要缩小错误原因的范围,需要制定一套可靠的重现步骤:' - 内容: 'Determine where the bug happens in your source code.' 提示: '' - 翻译: '' + 翻译: '确定源代码中错误发生的位置。' - 内容: 'Pause your app with a breakpoint in your source code before the point at which you believe the bug occurs.' 提示: '' - 翻译: '' + 翻译: '源代码中,在你认为错误出现的位置之前设置断点,暂停应用。' - 内容: 'Look at your variables and confirm they have the values you expect. If they don’t, begin again with step 1.' 提示: '' - 翻译: '' + 翻译: '查看变量,确认它们是否拥有你所期望的值。如果没有,请从步骤1重新开始。' - 内容: 'Step through your code and watch your variables change. Note where your variables have unexpected values.' 提示: '' - 翻译: '' + 翻译: '逐步检查代码,观察变量的变化。注意变量出现意外值的位置。' - 内容: 'Analyze your code to determine a fix.' 提示: '' - 翻译: '' + 翻译: '分析代码,确定修复方法。' - 内容: 'After determining a potential fix for the bug, confirm the diagnosis by changing your code and retesting to reproduce it. If the change addresses the problem, you’ve resolved the bug. If your change doesn’t resolve it, reconsider where the bug might be occurring, and repeat the steps to isolate and fix it.' 提示: '' - 翻译: '' + 翻译: '确定了错误的尝试性修复方案后,修改代码并重新测试来试着重现错误,从而确认诊断。如果更改后问题得到了解决,则说明你已经解决了错误。如果更改后问题仍未解决,则应重新考虑错误可能发生的位置,并重复上述步骤以隔离和修复错误。' - 内容: 'For more information on setting breakpoints and inspecting variables, see Setting breakpoints to pause your running app and Stepping through code and inspecting variables to isolate bugs.' 提示: '' - 翻译: '' + 翻译: '有关设置断点和检查变量的更多信息,请参阅设置断点以暂停正在运行的应用,以及逐步检查代码和变量以隔离错误。' - 内容: 'Locate crashes, exceptions, and runtime issues' 提示: '' - 翻译: '' + 翻译: '查找崩溃、异常和运行时问题' - 内容: 'When your app experiences a crash, exception, or runtime issue, it can be challenging to pinpoint the code causing the problem because the stack trace for the crash doesn’t always point to the line of code that causes the crash. Use the rubric below to identify the problem characteristics and then set the correct type of breakpoint:' 提示: '' - 翻译: '' + 翻译: '当你的应用出现崩溃、异常或运行时问题时,由于崩溃的堆栈跟踪并不总是指向导致崩溃的代码行,因此要准确定位导致问题的代码可能很有难度。请使用下面的规则识别问题的特征,然后设置正确的断点类型:' - 内容: 'A crash that stops at main or highlights AppDelegate is frequently an Objective-C exception.' 提示: '' - 翻译: '' + 翻译: '停止在 main 或突出显示 AppDelegate 的崩溃通常是 Objective-C 异常。' - 内容: 'A crash that is the result of a runtime issue also stops at main or highlights AppDelegate, and may have a message similar to: “Thread 8: EXC_BAD_INSTRUCTION (code=…)”.' 提示: '' - 翻译: '' + 翻译: '由运行时问题导致的崩溃也会在 main 或突出显示 AppDelegate 时停止,并可能出现类似以下的消息: “Thread 8: EXC_BAD_INSTRUCTION (code=…)”。' - 内容: 'A crash that stops at an uncaught or unhandled Swift error displays a fatal error message and indicates a Swift error.' 提示: '' - 翻译: '' + 翻译: '在未捕获或未处理的 Swift 错误处停止的崩溃会显示致命错误消息并指向 Swift 错误。' - 内容: 'Add a breakpoint to your code in a location based on problem characteristics, then when your app stops at the breakpoint, check the state of the code execution. For more information on setting breakpoints and identifying crashes, see Setting breakpoints to pause your running app and Identifying the cause of common crashes.' 提示: '' - 翻译: '' + 翻译: '根据问题特征在代码中的特定位置添加断点,然后当应用在断点处停止时,检查代码执行的状态。有关设置断点和识别崩溃的更多信息,请参阅设置断点以暂停正在运行的应用和识别常见崩溃的原因。' - 内容: 'Note' 提示: '' - 翻译: '' + 翻译: '注意' - 内容: 'Your Swift code can receive an Objective-C exception when it uses code from a module that uses Objective-C.' 提示: '' - 翻译: '' + 翻译: '当你的 Swift 代码使用来自使用 Objective-C 的模块代码时,可能会接收到 Objective-C 异常。' - 内容: 'Inspect variables and execution sequence without pausing' 提示: '' - 翻译: '' + 翻译: '在不暂停的情况下检查变量和执行顺序' - 内容: 'When you develop code, it’s helpful to log actions and variable values so you understand how your code runs and what values your variables have at different points in your app. This is especially true when you develop concurrent code, or code that executes simultaneously across multiple queues or threads, because bugs can be intermittent and difficult to reproduce. Often, you reproduce a bug in normal execution, but not when stepping through the debugger, because the timing is different between normal execution and debugging. The debugger provides tools to inspect variables without pausing and disturbing the timing of your concurrent code.' 提示: '' - 翻译: '' + 翻译: '在开发代码时,记录操作和变量值很有帮助,这样你就能了解代码的运行方式以及变量在应用中不同点的值。当你开发并行代码(即在多个队列或线程中同时执行的代码)时尤其如此,因为错误可能是间歇性的,很难重现。通常情况下,你在正常执行时会重现错误,但在调试器中却不会,因为正常执行和调试之间的时序不同。调试器提供了在不暂停和干扰并行代码时序的情况下检查变量的工具。' - 内容: 'Developers commonly add print or NSLog statements to see variable values. While this technique works, it adds extra code that isn’t useful after you finish development, and leaves your app with a noisy console that makes diagnosing subsequent bugs more difficult. Instead, use breakpoint actions to know when events in your app take place, and inspect variable values without pausing.' 提示: '' - 翻译: '' + 翻译: '开发人员通常会添加 print 或 NSLog 语句来查看变量值。这种方法虽然有效,但会增加额外的代码,且这些代码在开发完成后并无用处,还会给应用留下一个嘈杂的控制台,使诊断后续错误变得更加困难。相反,我们可以使用断点操作来了解应用中事件的发生时间,并在不暂停的情况下检查变量值。' - 内容: 'To determine whether your code executes with minimal effect to timing, use a breakpoint action to play a sound and continue executing. If the debugger reaches the breakpoint when you run the app, it plays the sound and confirms execution.' 提示: '' - 翻译: '' + 翻译: '想要在对时序影响最小的情况下确认代码是否执行,请使用断点操作播放声音并继续执行。如果调试器在运行应用时到达了断点,它就会播放声音并确认执行。' - 内容: 'To log a variable value to the console without pausing, add a breakpoint with a Debugger Command action using po to print out the evaluation of an object, or v to print the value of a variable to the console. Select the Automatically continue after evaluating actions option for the breakpoint to prevent pausing.' 提示: '' - 翻译: '' + 翻译: '要在不暂停的情况下将变量值记录到控制台,可通过“调试器命令”操作添加一个断点,使用 po 将对象的评估结果打印出来,或使用 v 将变量值打印到控制台。为断点选择“评估操作后自动继续”选项以防止暂停。' - 内容: 'To log custom text to the console and add context to variable values, add a breakpoint with a Log Message action. Specify your custom text, and include expressions, the breakpoint name, or the breakpoint hit count to provide more information.' 提示: '' - 翻译: '' + 翻译: '要将自定义文本记录到控制台并为变量值添加上下文,可添加带“日志信息”操作的断点。指定自定义文本,并包含表达式、断点名称或断点命中计数,以提供更多信息。' - 内容: 'Note' 提示: '' - 翻译: '' + 翻译: '注意' - 内容: 'Because po compiles code dynamically to evaluate expressions, it takes more time to evaluate your variable and log it to the console. To reduce timing issues, use v to log variable values instead.' 提示: '' - 翻译: '' + 翻译: '由于 po 会动态编译代码以评估表达式,因此评估变量并将其记录到控制台需要更多时间。为减少时序问题,可使用 v 来记录变量值。' - 内容: 'Use other breakpoint actions to execute an AppleScript or a shell script, or to capture a GPU frame.' 提示: '' - 翻译: '' + 翻译: '使用其他断点操作可执行 AppleScript 或 shell 脚本,或捕获 GPU 帧。' - 内容: 'For more information on inspecting variables, see Setting breakpoints to pause your running app and Stepping through code and inspecting variables to isolate bugs.' 提示: '' - 翻译: '' + 翻译: '有关检查变量的更多信息,请参阅设置断点以暂停正在运行的应用,以及逐步检查代码和变量以隔离错误。' - 内容: 'Identify potential overuse of CPU and memory' 提示: '' - 翻译: '' + 翻译: '识别潜在的 CPU 和内存过度使用' - 内容: 'An easily overlooked and common problem in development and testing is the overuse of CPU and memory. Xcode’s debugger provides gauges in the Debug navigator to help investigate potential problems. Monitor the gauges while you’re testing your app to uncover unusual usage. Click a gauge for a more detailed view.' 提示: '' - 翻译: '' + 翻译: '在开发和测试过程中,CPU 和内存的过度使用是一个经常容易被忽视的问题。Xcode 的调试器在调试导航器中提供了仪表盘,以帮助调查潜在问题。在测试应用时监控仪表盘,以发现异常使用情况。点击仪表盘可查看更详细的信息。' - 内容: 'The CPU gauge shows the amount of CPU the app requires to process instructions over time. When your app is drawing the user interface, processing data it retrieves from the network, or performing calculations, it‘s normal to see CPU usage increase to fairly high numbers for a short period of time. When those tasks are complete and your app is idle and waiting for the user to perform an action, CPU usage should be zero or very low. Do additional analysis if CPU usage is:' 提示: '' - 翻译: '' + 翻译: 'CPU 测量值显示应用在一段时间内处理指令所需的 CPU 占用率。当应用正在绘制用户界面、处理从网络获取的数据或执行计算时,CPU 使用率会在短时间内上升到相当高的水平,这是正常现象。当这些任务完成后,应用处于闲置状态,等待用户执行操作时,CPU 使用率应为零或非常低。如果出现以下情况,请进行额外分析:' - 内容: 'Persistent at a level above zero when the app appears to be idle.' 提示: '' - 翻译: '' + 翻译: '当应用看似闲置时,CPU 使用率持续高于零。' - 内容: 'Over 100% for more than very short periods of time.' 提示: '' - 翻译: '' + 翻译: '使用率多次超过100%。' - 内容: 'Very high and you see hitches in your user interface.' 提示: '' - 翻译: '' + 翻译: '非常高且用户界面出现卡顿。' - 内容: 'For more information on improving performance, see Improving your app’s performance.' 提示: '' - 翻译: '' + 翻译: '有关提高性能的更多信息,请参阅提高应用的性能。' - 内容: 'The Memory gauge shows how much memory your app uses over time. It starts at a fairly small number, less than 10 MB, when you first launch your app, and then increases as people navigate through your user interface. It may also increase if you fetch, process, and store data from the network, or perform complex calculations. It then decreases when processing is complete. Watch the gauge as you navigate through your app, and note when memory usage goes up and down. Memory usage increases when you present modal views or add a view to a navigation controller, and decreases when you dismiss or navigate away from those views. If your usage continues to increase and doesn’t ever decrease, investigate whether you have a memory leak or abandoned memory. For more information on reducing memory use and resolving memory leaks, see the section below Visualize and diagnose increasing memory usage and Reducing your app’s memory use.' 提示: '' - 翻译: '' + 翻译: '内存量表显示应用在一段时间内使用的内存量。第一次启动应用时,内存使用量很小,不到 10 MB,随着用户浏览用户界面,内存使用量会逐渐增加。如果你从网络中获取、处理和存储数据,或执行复杂的计算,它也会增加。当处理完成后,它就会降低。在你浏览应用时,请注意观察仪表盘,并注意内存使用量何时上升,何时下降。当你显示模态视图或向将视图添加到导航控制器时,内存使用量会增加;而当你取消或从这些视图返回时,内存使用量会减少。如果内存使用量持续增加而不减少,请调查是否存在内存泄漏或内存弃用的情况。有关减少内存使用和解决内存泄漏问题的更多信息,请参阅下面的章节可视化并诊断内存使用量的增加和减少应用的内存使用量。' - 内容: 'Detect high disk access and network use' 提示: '' - 翻译: '' + 翻译: '检测高磁盘访问和网络使用' - 内容: 'Be aware of issues resulting from frequent access to resources on disk and over the network. You can monitor these resources using the gauges in Xcode’s debugger as well. The Disk I/O gauge shows how much data your app reads and writes from disk over time. The gauge shows if you:' 提示: '' - 翻译: '' + 翻译: '请注意频繁访问磁盘和网络资源导致的问题。你也可以使用 Xcode 调试器中的仪表来监控这些资源。磁盘 I/O 仪表显示应用在一段时间内从磁盘读取和写入的数据量。该仪表显示你是否' - 内容: 'Store data that the user generates in your app.' 提示: '' - 翻译: '' + 翻译: '在应用中存储用户生成的数据。' - 内容: 'Store data in user preferences.' 提示: '' - 翻译: '' + 翻译: '在用户偏好设置中存储数据。' - 内容: 'Fetch data from the network and store it.' 提示: '' - 翻译: '' + 翻译: '从网络获取数据并存储。' - 内容: 'Read data from your app bundle or the app’s directories.' 提示: '' - 翻译: '' + 翻译: '从应用捆绑包或应用目录中读取数据。' - 内容: 'Storing and reading data frequently from disk uses more power than doing so from memory, and it adds wear and tear to the user’s device. To know whether disk usage is unusual, you need to understand the size of data you’re storing and reading, and compare that to what you observe in the gauge. For example, if you download and store a 5 MB graphic file for display in a view that you use frequently and it writes over 50 MB of data, investigate whether the remote image changes frequently, or whether you need to configure networking to prevent redownloading the same image. If you’re reading more data from disk than you expect, investigate whether a memory-caching solution might help, or whether you’re initiating a data read from the wrong point in your app or view life cycle, and reading it too often. For more information on reducing disk writes, see Reducing disk writes.' 提示: '' - 翻译: '' + 翻译: '频繁从磁盘存储和读取数据比从内存存储和读取数据耗电更多,而且会增加用户设备的损耗。要知道磁盘使用是否异常,需要了解存储和读取数据的大小,并将其与仪表中观察到的数据进行比较。例如,如果你下载并存储了一个 5 MB 的图片文件用于在经常使用的视图中显示,但却写入了超过 50 MB 的数据,那么请调查云端图像是否经常变化,或者你是否需要配置网络以防止重新下载相同的图像。如果从磁盘读取的数据比预期的要多,请调查内存缓存解决方案是否有帮助,或者你是否从应用或视图生命周期中的错误点启动了数据读取,且读取频率过高。有关减少磁盘写入的更多信息,请参阅减少磁盘写入。' - 内容: 'The Network I/O gauge shows how much data your app reads from and writes to the network over time. If your app only uses local resources, your app may not read or write any data from the network. Communicating data over the network uses energy and reduces the device’s battery life, so minimize data transfer wherever possible. To understand your app’s network usage, watch the Network I/O gauge when your app is sending or receiving data from the network. For example, if you implement a cache system for downloaded images and your network usage increases when accessing them, confirm that your cache settings are correct in the app and on the server. If you’re uploading user-generated content and frequent upload failures during poor networking conditions lead to high network usage, implement a system to recover and restart failed uploads at the point of failure, rather than reuploading the entire file.' 提示: '' - 翻译: '' + 翻译: '网络 I/O 仪表显示了一段时间内应用从网络读取和写入的数据量。如果应用只使用本地资源,则可能不会从网络读取或写入任何数据。通过网络通信数据会消耗能源并缩短设备的电池寿命,因此应尽可能减少数据传输。要了解应用的网络使用情况,请在应用从网络发送或接收数据时观察网络 I/O 测量值。例如,如果你对下载的图片添加了缓存系统,而网络使用量在访问图片时增加,请确认应用和服务器中的缓存设置是否正确。如果你正在上传用户生成的内容,而在网络状况不佳的情况下频繁上传失败会导致网络使用量增加,那么请构建一个在上传失败时恢复并重新启动,而不是重新上传整个文件的系统。' - 内容: 'Visualize and diagnose increasing memory usage' 提示: '' - 翻译: '' + 翻译: '可视化并诊断内存使用量的增加' - 内容: 'Diagnose the cause of memory leaks and abandoned memory with the memory graph. The observable symptom of a memory leak is memory usage that continues to increase over time, even when conditions in the app indicate that memory usage is decreasing. A memory leak can occur in a retain cycle, which is when objects maintain strong references to each other, but the app no longer references them. These objects remain in memory and the app can’t remove them. Abandoned memory occurs when you create objects and your code still references them, but your app no longer needs them or uses them.' 提示: '' - 翻译: '' + 翻译: '利用内存图诊断内存泄漏和内存弃用的原因。内存泄漏的明显症状是尽管应用的使用情况表明内存使用正在减少,实际上内存使用量却随着时间的推移持续增加。内存泄漏可能发生在循环引用中,即对象之间保持强引用,但应用不再引用它们。这些对象保留在内存中,应用无法删除它们。当你创建了对象且代码仍在引用它们,但应用不再需要或使用它们时,就会发生内存弃用。' - 内容: 'To see the memory graph in the debugger, pause your app at a breakpoint and click the Debug Memory Graph button in the debug bar. Alternatively, click the Debug Memory Graph button when the app is running to pause the app and show the memory graph.' 提示: '' - 翻译: '' + 翻译: '要在调试器中查看内存图,请在断点处暂停应用,然后单击调试栏中的“调试内存图(Debug Memory Graph)”按钮。或者,在应用运行时单击“调试内存图”按钮,暂停应用并显示内存图。' - 内容: 'The memory graph view replaces the stack trace in the Debug navigator with a list of types, organized by library, each with a list of instances called nodes. Select a node to view its memory graph.' 提示: '' - 翻译: '' + 翻译: '内存图视图将调试导航器中的堆栈跟踪替换为按库排列的类型列表,每个类型都有一个称为节点的实例列表。选择一个节点即可查看其内存图。' - 内容: 'A node’s memory graph shows all the memory references to that node, and highlights strong references. Control-click any node in the graph to perform more actions, such as accessing Quick Look or printing the description to the console. Choose Focus on Node to show the graph for the selected node. Click a reference to see its details, including the name of the variable, the type of reference, and the source and destination objects in memory.' 提示: '' - 翻译: '' + 翻译: '节点的内存图显示该节点的所有内存引用,并突出显示强引用。按住 Control 键单击内存图中的任意节点,可执行更多操作,如“快速查看(Quick Look)”或将说明打印到控制台。选择“聚焦节点(Focus on Node)”以显示所选节点的图表。单击引用可查看其详细信息,包括变量名称、引用类型以及内存中的源对象和目标对象。' - 内容: 'To resolve a memory leak for a retain cycle:' 提示: '' - 翻译: '' + 翻译: '要解决循环引用的内存泄漏问题:' - 内容: 'Observe the Memory gauge while you navigate the app.' 提示: '' - 翻译: '' + 翻译: '在浏览应用时观察内存仪表。' - 内容: 'Note when memory usage increases when your app instantiates an object, but doesn’t decrease when you expect the system to deallocate the object.' 提示: '' - 翻译: '' + 翻译: '注意当应用实例化对象时,内存使用量会增加,而当你期望系统取消分配对象时,内存使用量却不减少。' - 内容: 'Examine the memory graph to see if there are an unexpected number of instances of the object or inappropriate strong references to it.' 提示: '' - 翻译: '' + 翻译: '检查内存图,查看对象实例的数量是否出乎意料,或者是否存在不恰当的强引用。' - 内容: 'If there is a strong reference to the object, Control-click the node with the strong reference and choose Focus on Node to view its graph. If the node also has a strong reference from the object, this is a retain cycle.' 提示: '' - 翻译: '' + 翻译: '如果存在对某个对象的强引用,请按住 Control 键并单击强引用的节点,然后选择“聚焦节点”查看其图表。如果此节点也有来自对象的强引用,则这是一个循环引用。' - 内容: 'Resolve the retain cycle by changing one side of the relationship to use a weak declaration for the reference to the other object, or remove the reference altogether by removing any dependencies on the other object. Retest to confirm that the change fixes the issue.' 提示: '' - 翻译: '' + 翻译: '解决循环引用的方法是令引用关系的一方使用弱声明来引用另一个对象,或者通过删除对其他对象的所有依赖关系来完全删除引用。重新测试以确认更改是否修复了问题。' - 内容: 'To resolve abandoned memory issues, identify the time in your app’s life cycle that it no longer needs the abandoned object and remove any references to it.' 提示: '' - 翻译: '' + 翻译: '要解决内存弃用问题,请确定应用生命周期中不再需要废弃对象的时间,并删除对该对象的所有引用。' - 内容: 'Inspect and resolve appearance and layout issues' 提示: '' - 翻译: '' + 翻译: '检查并解决外观和布局问题' - 内容: 'Some issues in the appearance or layout of your app only appear when you configure the system with a particular interface style, dynamic text size or when your app uses particular accessibility features. Use environmental overrides when targeting iOS, macOS, and tvOS apps to test your interface in these environments. To understand issues that involve the position or size of your view, you might need to inspect them within the context of views in other layers. Use the view debugger when targeting iOS, macOS, tvOS, and watchOS apps, which displays a 3D representation of the view hierarchy in layers, to help diagnose these issue. Entities within a visionOS app and their surroundings sometimes interact with each other in ways you don’t expect. Enable visualizations to represent coordinate axes, bounding boxes, and other information that is normally invisible, to help understand these interactions.' - 提示: '' - 翻译: '' + 提示: '视图调试器(Debug View Hierarchy)按钮也在调试栏上,位于“调试内存图”按钮左侧。' + 翻译: '某些应用外观或布局方面的问题,只有当你将系统配置为特定界面风格、动态文本大小或当你的应用使用特定辅助功能时才会出现。在以 iOS、macOS 和 tvOS 应用为目标时,请使用环境覆盖在这些环境中测试你的界面。要了解涉及视图位置或大小的问题,可能需要在其他图层的视图上下文中进行检查。在面向 iOS、macOS、tvOS 和 watchOS 应用时,可使用视图调试器显示视图层次结构的 3D 表示形式,来帮助诊断这些问题。visionOS 应用中的实体与其周围环境有时会以你意想不到的方式进行交互。启用可视化来表示坐标轴、边界框和其他通常不可见的信息,这有助于理解这些交互。' - 内容: 'For information on using these features to debug the appearance of your app, see Diagnosing issues in the appearance of a running app.' 提示: '' - 翻译: '' + 翻译: '有关使用这些功能调试应用外观的信息,请参阅诊断运行中应用的外观问题。'