Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c9b1f8f authored by Suren Baghdasaryan's avatar Suren Baghdasaryan Committed by Android (Google) Code Review
Browse files

Merge "Add JNI API to query sizes of ION heaps, pools and mapped part of the heaps"

parents c5c9e5c2 5bf4706e
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -2567,4 +2567,27 @@ public final class Debug
     * @hide
     * @hide
     */
     */
    public static native long getZramFreeKb();
    public static native long getZramFreeKb();

    /**
     * Return memory size in kilobytes allocated for ION heaps.
     *
     * @hide
     */
    public static native long getIonHeapsSizeKb();

    /**
     * Return memory size in kilobytes allocated for ION pools.
     *
     * @hide
     */
    public static native long getIonPoolsSizeKb();

    /**
     * Return ION memory mapped by processes in kB.
     * Notes:
     *  * Warning: Might impact performance as it reads /proc/<pid>/maps files for each process.
     *
     * @hide
     */
    public static native long getIonMappedSizeKb();
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -207,6 +207,7 @@ cc_library_shared {


            static_libs: [
            static_libs: [
                "libasync_safe",
                "libasync_safe",
                "libdmabufinfo",
                "libgif",
                "libgif",
                "libseccomp_policy",
                "libseccomp_policy",
                "libgrallocusage",
                "libgrallocusage",
+60 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedUtfChars.h>
#include <nativehelper/ScopedUtfChars.h>
#include "jni.h"
#include "jni.h"
#include <dmabufinfo/dmabufinfo.h>
#include <meminfo/procmeminfo.h>
#include <meminfo/procmeminfo.h>
#include <meminfo/sysmeminfo.h>
#include <meminfo/sysmeminfo.h>
#include <memtrack/memtrack.h>
#include <memtrack/memtrack.h>
@@ -781,6 +782,59 @@ static jlong android_os_Debug_getFreeZramKb(JNIEnv* env, jobject clazz) {
    return zramFreeKb;
    return zramFreeKb;
}
}


static jlong android_os_Debug_getIonHeapsSizeKb(JNIEnv* env, jobject clazz) {
    jlong heapsSizeKb = 0;
    uint64_t size;

    if (meminfo::ReadIonHeapsSizeKb(&size)) {
        heapsSizeKb = size;
    }

    return heapsSizeKb;
}

static jlong android_os_Debug_getIonPoolsSizeKb(JNIEnv* env, jobject clazz) {
    jlong poolsSizeKb = 0;
    uint64_t size;

    if (meminfo::ReadIonPoolsSizeKb(&size)) {
        poolsSizeKb = size;
    }

    return poolsSizeKb;
}

static jlong android_os_Debug_getIonMappedSizeKb(JNIEnv* env, jobject clazz) {
    jlong ionPss = 0;
    std::vector<dmabufinfo::DmaBuffer> dmabufs;

    std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir("/proc"), closedir);
    if (!dir) {
        LOG(ERROR) << "Failed to open /proc directory";
        return false;
    }

    struct dirent* dent;
    while ((dent = readdir(dir.get()))) {
        if (dent->d_type != DT_DIR) continue;

        int pid = atoi(dent->d_name);
        if (pid == 0) {
            continue;
        }

        if (!AppendDmaBufInfo(pid, &dmabufs, false)) {
            LOG(ERROR) << "Failed to read maps for pid " << pid;
        }
    }

    for (dmabufinfo::DmaBuffer buf : dmabufs) {
        ionPss += buf.size() / 1024;
    }

    return ionPss;
}

/*
/*
 * JNI registration.
 * JNI registration.
 */
 */
@@ -824,6 +878,12 @@ static const JNINativeMethod gMethods[] = {
            (void*)android_os_Debug_getUnreachableMemory },
            (void*)android_os_Debug_getUnreachableMemory },
    { "getZramFreeKb", "()J",
    { "getZramFreeKb", "()J",
            (void*)android_os_Debug_getFreeZramKb },
            (void*)android_os_Debug_getFreeZramKb },
    { "getIonHeapsSizeKb", "()J",
            (void*)android_os_Debug_getIonHeapsSizeKb },
    { "getIonPoolsSizeKb", "()J",
            (void*)android_os_Debug_getIonPoolsSizeKb },
    { "getIonMappedSizeKb", "()J",
            (void*)android_os_Debug_getIonMappedSizeKb },
};
};


int register_android_os_Debug(JNIEnv *env)
int register_android_os_Debug(JNIEnv *env)