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

Commit e4c62c1c authored by Kalesh Singh's avatar Kalesh Singh Committed by Gerrit Code Review
Browse files

Merge "Add VmShmem calculate for getRss" into main

parents f3ebcb03 bc55e00c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -1471,7 +1471,15 @@ public class Process {
    @UnsupportedAppUsage
    public static final native long getPss(int pid);

    /** @hide */
    /**
     * Gets the total Rss value for a given process, in bytes.
     *
     * @param pid the process to the Rss for
     * @return an ordered array containing multiple values, they are:
     *  [total_rss, file, anon, swap, shmem].
     *  or NULL if the value cannot be determined
     * @hide
     */
    public static final native long[] getRss(int pid);

    /**
+6 −6
Original line number Diff line number Diff line
@@ -1165,12 +1165,11 @@ static jlong android_os_Process_getPss(JNIEnv* env, jobject clazz, jint pid)

static jlongArray android_os_Process_getRss(JNIEnv* env, jobject clazz, jint pid)
{
    // total, file, anon, swap
    jlong rss[4] = {0, 0, 0, 0};
    // total, file, anon, swap, shmem
    jlong rss[5] = {0, 0, 0, 0, 0};
    std::string status_path =
            android::base::StringPrintf("/proc/%d/status", pid);
    UniqueFile file = MakeUniqueFile(status_path.c_str(), "re");

    char line[256];
    while (file != nullptr && fgets(line, sizeof(line), file.get())) {
        jlong v;
@@ -1182,17 +1181,18 @@ static jlongArray android_os_Process_getRss(JNIEnv* env, jobject clazz, jint pid
            rss[2] = v;
        } else if ( sscanf(line, "VmSwap: %" SCNd64 " kB", &v) == 1) {
            rss[3] = v;
        } else if ( sscanf(line, "RssShmem: %" SCNd64 " kB", &v) == 1) {
            rss[4] = v;
        }
    }

    jlongArray rssArray = env->NewLongArray(4);
    jlongArray rssArray = env->NewLongArray(5);
    if (rssArray == NULL) {
        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
        return NULL;
    }

    env->SetLongArrayRegion(rssArray, 0, 4, rss);

    env->SetLongArrayRegion(rssArray, 0, 5, rss);
    return rssArray;
}