- Home /
Can I get the "Total Allocated" memory from script?
It seems like "UnityEngine.Profiler.GetTotalAllocatedMemory()" does not report nearly all allocated memory.
I would like to get a total memory consumption of my app from script.
Please do not suggest using an external profiler such as instruments.
Just for context. This is for automation.
Thanks, Jonas
Answer by JonasNorberg · Sep 20, 2013 at 02:23 AM
Ok, I solved it with by making a native-plugin, like so:
// inspired by: // http://forum.sparrow-framework.org/topic/checking-device-memory-and-current-running-process
import < mach/mach.h >
extern "C" int getMemoryUsage(){ struct task_basic_info info; mach_msg_type_number_t size = sizeof(info); kern_return_t kerr = task_info( mach_task_self(), TASK_BASIC_INFO, (task_info_t)∈fo, &size);
if( kerr == KERN_SUCCESS ) return (int)info.resident_size;
else return 0;
}
for me this doesn't compile, changing #import < mach/mach.h > to #include "mach/mach.h" fixed it