如何分析内存使用情况 &与仪器的性能? [英] How to profile memory usage & performance with Instruments?

查看:29
本文介绍了如何分析内存使用情况 &与仪器的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有仪器跟踪模板中,我喜欢使用:

Of all the Instruments Trace Templates, I love using:

  • 僵尸检测对象在哪里被过度释放,非常适合调试 EXEC_BAD_ACCESS 错误.
  • 泄漏检测内存泄漏.
  • 核心动画 w 颜色混合层来检测帧速率和半透明子视图,非常适合平滑 UITableView 滚动.
  • Zombies to detect where an object is getting over-released, great for debugging EXEC_BAD_ACCESS errors.
  • Leaks to detect memory leaks.
  • Core Animation w Color Blended Layers to detect frame rate & translucent subviews, great for smoothing up UITableView scrolling.

我总是听到人们说要分析我的应用程序的内存使用情况&性能.

I always hear people saying to profile my app's memory usage & performance.

  1. 为什么要分析内存使用情况 &表现?我的应用运行良好.
  2. 我该怎么做?

我使用了分配,看到我的 iPhone 应用程序从 1 MB 的总分配内存开始,在正常使用后增长到​​ 5 MB.iPhone 内存占用过高是怎么回事?iPad?马克?

I've used Allocations and see that my iPhone app starts at 1 MB total allocated memory and grows to 5 MB after normal usage. What is too high amount of memory usage on the iPhone? iPad? Mac?

推荐答案

为了回答原因,分析内存使用情况对于 iOS 应用程序尤其重要,因为 iPhone 和 iPad 的 RAM 比 Mac 少得多.iPhone 4 有 512 MB 的 RAM,但早期版本有 256 或 128 MB.考虑到操作系统使用的 RAM 和多任务处理,您的应用不会浪费太多 RAM,因此了解您的应用使用了多少内存非常重要.

To answer the whys, profiling memory usage is especially important for iOS apps because iPhones and iPads have much less RAM than Macs. The iPhone 4 has 512 MB of RAM, but earlier versions had 256 or 128 MB. Factor in the RAM the OS uses and multitasking, and your app doesn't have much RAM to waste so it's important to be aware of how much memory your app uses.

分析性能是您的应用运行缓慢时通常要做的事情.分析它以找到代码中的慢点,以便您可以使代码运行得更快.如果您的应用运行良好,则您无需对性能进行太多分析.

Profiling performance is something you usually do when your app is running slowly. Profile it to find the slow spots in your code so you can make the code run faster. If your app runs fine, you don't have much need to profile for performance.

要回答方法,请使用分配工具来测量内存使用情况.All Allocations 类别中的 Live Bytes 列会告诉您应用程序当前使用的内存量.Allocations 工具的 heapshot 分析测量应用程序中的内存增长.使用跳转栏左侧的菜单进行heapshot分析.

To answer the hows, use the Allocations instrument to measure memory usage. The Live Bytes column in the All Allocations category tells you the amount of memory your app is currently using. The Allocations instrument's heapshot analysis measures memory growth in your app. Use the menu on the left side of the jump bar to do heapshot analysis.

Time Profiler 工具分析您的应用的性能.使用 Time Profiler 仪器的困难部分是解释结果.Time Profiler 工具不会告诉您您的应用 75% 的时间都花在了 Function X 上.您必须挖掘数据才能找到代码中的慢点.

The Time Profiler instrument profiles your app for performance. The difficult part of using the Time Profiler instrument is interpreting the results. The Time Profiler instrument isn't going to tell you your app spends 75% of its time in Function X. You have to dig through the data to find the slow spots in your code.

关于可接受的内存使用量,这取决于您要支持的设备和应用程序.像 Xcode 这样使用 100 MB RAM 的应用程序是可以的,但是像 TextEdit 这样的应用程序使用 100 MB 的内存来处理一页文档就会有问题.5 MB 对于 iOS 应用来说应该不是问题.

Regarding acceptable memory usage, it depends on the devices you want to support and the app. An app like Xcode using 100 MB of RAM would be OK, but an app like TextEdit using 100 MB for a one page document would be a problem. 5 MB shouldn't be a problem for an iOS app.

这篇关于如何分析内存使用情况 &与仪器的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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