2

There are a couple of questions in SO similar to this one, but none of them seem to explain a definitive approach for getting the actual OpenGL texture memory used by an iOS app, on the device.

I know how to manually calculate how much memory my textures will use when uploaded to OpenGL. I want to know if I can get the exact OpenGL used memory amount from the device.

I would like to avoid looking at the Real Memory and Virtual Memory columns in the Memory Monitor widget on Instruments (my understanding is that these aggregate texture memory and app's regular memory). I presume this is similar to the approach shown here or here.

I don't mind whether the texture memory is obtained using any external tool or programmatically. But I want just the real OpenGL memory as reported by the device, not an aggregate.


Also, can somebody explain what the 'Virtual Memory' column exactly means on iOS? I think I understand the concept of Virtual Memory, but I'm trying to figure out if the Virtual Memory column is also related to iOS low-memory warnings, or only the Real Memory column is.

Community
  • 1
  • 1
Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92

1 Answers1

4

My answer is imperfect, but...

With your device attached and with the project open, ensure you have the actual device selected as the execution target and not the simulator. Select Product -> Profile.

Instruments will come up. Pick the 'OpenGL ES Analysis' template. Instruments should open with two instruments active — 'OpenGL ES Analyzer' and 'OpenGL ES Driver'.

Click the 'i' for the analyser and tick 'Uploaded Texture Bytes'. You'll get a graph of the number of bytes uploaded.

Just after the dividing line between the top and bottom panels in Instruments you should see the text 'OpenGL ES Analyzer' in an arrow-shaped box, probably pointing over to the word 'Expert'. Click on 'Expert' and select 'Frame Statistics'. You'll get a table in which one of the columns is 'Uploaded Texture Bytes'.

Here's the annoying part: that lists the number of bytes uploaded in every frame. As of yet I've not found a way to get the current resident cost or otherwise to do any automatic calculation with that column. But it display only what's in the Instruments inspection range — set by the clock buttons on the window's toolbar — so you can restrict your inspection to a certain time period and then add up the results yourself.

EDIT: I can't be 100% definitive on the exact implications of the 'Virtual Memory' column (you're referring to the Memory Monitor tool, presumably?) but iOS has a fully functioning virtual memory system. The only thing it won't do is page data out to disk. You can however memory map a file and it's likely that the OS uses the usual virtual approach to allocating memory. What malloc and co. create is a ticket that reserves a block of address space. Actual memory isn't put into that address space unless or until you use it. Since it's essentially free, you may be allocated quite a lot more virtual memory than you're actually using; no doubt all of the foundation objects are optimised for the memory management system at play.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • This answer provides very useful info, so I just upvoted it. However, it doesn't answer the original question so I'll keep it unaccepted just in case somebody else chimes in. I'm guessing there is no way of deterministically knowing total OpenGL-used memory (apart from the total app memory). – Ricardo Sanchez-Saez Nov 11 '14 at 16:47
  • 2
    Agreed; I wasn't able to nominate a tool or a call that could answer the question set: how much memory is currently (or, if it were in Instruments, probably at a given time) occupied by OpenGL textures? That's because I'm unaware of an answer, sadly. Sorry I couldn't be more help. – Tommy Nov 11 '14 at 17:42