Python: get ram data


Is there a way to get the ram data printed which needs the GE for the materials and textures?

something like print (

Thanks in advance

Thai Recipes

you’d have to use an external module i guess. i’ll have a look

Yeah, I don’t think that’s not a built-in feature. You’ll have to do it yourself.

As far as I’m aware there’s nothing in Python’s standard library that’ll do that. There are a few modules written by others that can do it, however most seem to fall into one of two categories: Not cross platform or no longer being actively developed. Here’s a few that might help:

Python System Information - PSI (about a year old, think there’s also cross-platform issues)
PyStatGrab (hasn’t been updated since 2007)
Psutil (Up-to-date, good cross platform support, I’ve used this before, not in Blender though)
SIGAR (looks fairly recent, supports a number of platforms)

You can also use Microsoft’s WMI interface for accessing system data on windows machines, just look for a python wrapper version. Finally there are a number of custom scripts floating about on Stack Overflow as well.

Hope this Helps!

I’m at work tonight, I’ve got tomorrow off so I’ll have a play in the morning and see what I can put together for you.

I should point out that I’m still using Blender 2.49b.

Hey that would be really kind of you. Yeah I am also still using 2.49b:yes:

Expert insurance

No worries, it’s good for me to go over bits of python I rarely use otherwise. Is there anything about the RAM usage or system specs in particular you wanted to know? Like how much memory or CPU everything or just blender is using or how much free RAM is remaining? Also is there any specific way you’d like to represent this data or variable types you want it stored in? I’ll create an example that covers as much as possible, but it’s handy to know what bits I can’t miss (it also helps decide which module to use).

Yeah the reason for this is to find out what needs most ram, materials, textures etc.
So it would also be nice to see how many materials and textures are in game. Yeah I think it is enough only the memory blender uses and how much is left. And do whatelse could be of advantage to know. You have more experience in this than I :slight_smile:

Hey and really thanks for doing this.

Online Xxx Videos

Sorry had a frozen pipe today that’s caused a leak so I didn’t get a huge amount of time to look at your problem.

psutil works perfectly in the python interpreter but for some reason wont import in Blender, so I’ve been looking at other methods.

So far I’ve managed to get the a few memory details in Windows. So if you’re using Windows you can use this code (just attach it to an always sensor):

import ctypes

class MEMORYSTATUSEX(ctypes.Structure):
    _fields_ = [("dwLength", ctypes.c_uint),
                ("dwMemoryLoad", ctypes.c_uint),
                ("ullTotalPhys", ctypes.c_ulonglong),
                ("ullAvailPhys", ctypes.c_ulonglong),
                ("ullTotalPageFile", ctypes.c_ulonglong),
                ("ullAvailPageFile", ctypes.c_ulonglong),
                ("ullTotalVirtual", ctypes.c_ulonglong),
                ("ullAvailVirtual", ctypes.c_ulonglong),
                ("sullAvailExtendedVirtual", ctypes.c_ulonglong),]

    def __init__(self):
        # have to initialize this to the size of MEMORYSTATUSEX
        self.dwLength = 2*4 + 7*8     # size = 2 ints, 7 longs
        return super(MEMORYSTATUSEX, self).__init__()


print 'total physical', stat.ullTotalPhys
print 'total available',stat.ullAvailPhys

To get the running processes in Windows (such as Blender) and their memory usage is trickier and is going to require a few external modules making distributing the final product a little more difficult. This isn’t really problem if you’re using it for your own performance profiling needs.

UNIX based systems and mac are a bit more straight forward, as I don’t have either system I can’t test them, but once I get a full memory profiler for Windows working I’ll move onto them.

I’ll let you know when I get more working.

Hey Battery that is awesome. Many many thanks for your hard work and time spended on this.

This is exactly what I needed.:eyebrowlift: Thanks again.


Right, had time today to focus on a Windows solution.

The attached .blend contains a module that has functions for getting the total physical memory, available physical memory and the amount of memory Blender is using and a simple script that demonstrates it’s usage. Keep tapping space bar to flood the scene with cubes covered in the Hoff to see Blender’s memory usage increase. You can see the system stats printed to the screen as debug properties. Note that getting system performance uses a lot of resources (the actual code in the functions is pretty minimal, the WMI module can be slow at grabbing data, even in the python interpreter).

MemUsage1.2.blend (317 KB)

To get the .blend working you need the WMI and win32 modules. you can get the WMI module here (get the windows installer). For the WMI module to work you need the win32 module, which can be found here (select the version the corresponds to your python version, should be 2.6). In order to get them importing right I had to restart after installing them.

I don’t think there is a way to specifically get how much memory textures/materials are using but hopefully blender’s overall memory usage should give you a good idea about how much is being used. Maybe experiment with how much adding a texture alters the value to get a rough idea.

Let us know how you get on (do you want a cross platform version?). Hope this helps!

Hey battery I don’t know what to say. You are my christmas man.:smiley:

Thanks so much for that.

I have downloaded the modules and it works perfect. For me it’s fine this win32 version.

I will tell you all what I did find out about object and texture optimation in a new thread.

Thanks a lot again and mary christmas.

Ship sale

:smiley: No worries! Look forwarding to seeing what you do with it.

Have a good Christmas, happy to help!

Hi, I need to get data present in RAM memory using python can someone help me.

Sigh, this sound like a weird use case, but why not.

What kind of data are you hoping to fetch? Is it from a Blender Game Engine script?

I have to save my RAM data and check for some useful information in that is there any packages in python for this

I have used Volatility for this but it does not work for me, here i did manually using DumpIt file, but i need in script.

There is psutil, it can fetch all the data, tho i did not try it myself, it’s on the long list of things to try out.

You still don’t say what kind of “useful information” you are after.

Most use cases for this kind of things is for malwares.

Since most people here will gladly just execute your game if you upload it, I’m a bit concerned about what exactly you are looking for in the RAM.

1 Like

I would use it for a check system:

  • vram: low or high textures
  • ram: level size/lod
  • cpu: how many npc’s

this is just an example, but most games do this.

but this sounds a bit strange to me as well.