How to find the memory usage of my Android application in C ++ using NDK

I port a game written in C ++ to Android using the NDK. I need to know how much memory it consumes during operation. I am looking for a programmatic way to find the memory usage of an Android application written in C ++.

+6
source share
3 answers

In Java, you can check the source memory allocated / used with:

Debug.getNativeHeapAllocatedSize() Debug.getNativeHeapSize() 

Cm:

http://developer.android.com/reference/android/os/Debug.html#getNativeHeapAllocatedSize%28%29

http://developer.android.com/reference/android/os/Debug.html#getNativeHeapSize%28%29

+5
source

Two features based on JonnyBoy answer.

 static long getNativeHeapAllocatedSize(JNIEnv *env) { jclass clazz = (*env)->FindClass(env, "android/os/Debug"); if (clazz) { jmethodID mid = (*env)->GetStaticMethodID(env, clazz, "getNativeHeapAllocatedSize", "()J"); if (mid) { return (*env)->CallStaticLongMethod(env, clazz, mid); } } return -1L; } static long getNativeHeapSize(JNIEnv *env) { jclass clazz = (*env)->FindClass(env, "android/os/Debug"); if (clazz) { jmethodID mid = (*env)->GetStaticMethodID(env, clazz, "getNativeHeapSize", "()J"); if (mid) { return (*env)->CallStaticLongMethod(env, clazz, mid); } } return -1L; } 
+6
source

Debug.getNativeHeapAllocatedSize() and Debug.getNativeHeapSize() return information about the memory allocations executed by malloc() and its related functions only . You can easily /proc/self/statm from C ++ and get the VmRSS label.

See here for more details.

0
source

Source: https://habr.com/ru/post/947300/


All Articles