根据分析方法在仪器中获取不同的数据 [英] Getting different data in Instruments based on method of profiling

查看:91
本文介绍了根据分析方法在仪器中获取不同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是对该问题的回答的后续问题: instruments-leaks-and-分配-tvos

This question is a follow up question to the answer of this: instruments-leaks-and-allocations-tvos

最初的问题与我在tvOS应用程序中发生的内存泄漏有关,但我认为该问题的答案通常与iOS/Xcode/Instruments开发有关.

The initial question relates to a memory leak I had in a tvOS app, but I think the answer to this question is relevant to iOS/Xcode/Instruments development in general.

此问题已解决,方法是删除另一个闭包内的闭包,并在第一个闭包中保留对变量的引用.这导致了保留周期.

The issue was solved by removing a closure inside another closure keeping a reference to a variable in the first closure. This caused a retain cycle.

我真的很想了解为什么我没有更早发现问题,让我解释一下.

I really want to understand why I didn't find the issue earlier, let me explain.

结果是,我以错误的方式使用了Instruments.我进行概要分析时的工作流程如下:

How it turned out, I used Instruments the wrong way. My workflow while profiling was the following:

  • 从Xcode中,我运行在Apple TV设备上运行该应用
  • 启动仪器
  • 将Instruments附加到启动的应用程序中
  • From Xcode, I Run the app on the Apple TV device
  • Start up Instruments
  • Attach Instruments it to the launched app

以下内容在工具"中可见:

The following was visible in Instruments:

有一些泄漏,但没有什么特别的.该图并没有真正增加,甚至一个小时后也没有.我使用这种方法已经很长时间了,从没想到这里可能出了什么问题.

There were some leaks, but nothing that special. The graph didn’t really increase, not even after an hour. I used this method for a long time, and never thought something could be wrong here.

在阅读有关泄漏,配置文件等的内容时,我偶然发现了一篇随机的文章,其中有人在使用Xcode的 Profile 按钮(而不是 Run ).我只是认为这与我所做的相同:运行应用程序,启动Instruments并附加流程.但是,神奇的是,这张图出现了:

While reading about leaks, profiling etc. I came across some random article where someone was using the Profile button from Xcode (instead of Run). I just thought this was doing the same I was doing: Running the app, starting Instruments and attaching the process. But, magically, this graph appeared:

很明显这里有内存泄漏,使用这些数据,发现泄漏很容易做到.

Clearly there is a memory leak here and using this data, finding the leak was pretty easy to do.

所以我真的很想知道这两种方法之间的区别,但是我不能从中做任何事情.有人:)吗?

So I really want to know what is the difference between these 2 approaches, but I can't make anything out of it. Anyone :) ?

PS:截屏后的2分钟是使用完全相同的代码库截取的,只是将Instruments连接到进程的一种不同方式.

PS: The screenshots were made 2 minutes after each other with exactly the same codebase, just a different way of connecting Instruments to the process.

推荐答案

两种方法之间的区别是,当您从Xcode中选择Profile时,Instruments从一开始就记录所有内存分配.当您在Xcode中运行该应用程序,启动Instruments并附加该应用程序时,您将错过将该应用程序附加到Instruments之前发生的所有内存分配.如果您想记录应用程序进行的每个内存分配,则从Xcode选择配置文件是更好的选择,因为它是从应用程序启动时开始记录的.

The difference between the two approaches is when you choose Profile from Xcode, Instruments records all the memory allocations from the start. When you run the app in Xcode, launch Instruments, and attach the app, you're going to miss all the memory allocations that occurred before you attached the app to Instruments. Choosing Profile from Xcode is the better option if you want to record every memory allocation your app makes because it starts recording from app launch.

要回答有关在Xcode中选择运行"和配置文件"时,为什么Instruments数据不同的问题,我怀疑这是因为它们运行的​​应用程序版本不同.选择在Xcode中运行"时,Xcode最初设置为使用调试"构建配置,而选择配置文件"时,则设置为使用发布"构建配置.仪器可以显示不同的内存使用情况,以进行调试和发布.您可以编辑方案以查看用于运行和分析的构建配置.

To answer your question about why Instruments has different data when you choose Run and Profile in Xcode, I suspect it's because they run different builds of your app. Xcode is initially set to use the Debug build configuration when you choose Run in Xcode and set to use the Release build configuration when you choose Profile. Instruments can show different memory usage for debug and release builds. You can edit your scheme to see the build configurations used for running and profiling.

这篇关于根据分析方法在仪器中获取不同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆