Merge "Implement issue #10550827: watching gpu memory for occam_svelte" into klp-dev

This commit is contained in:
Dianne Hackborn
2013-09-06 22:25:56 +00:00
committed by Android (Google) Code Review
2 changed files with 102 additions and 27 deletions

View File

@@ -158,7 +158,7 @@ public final class Debug
public int otherSharedClean;
/** @hide */
public static final int NUM_OTHER_STATS = 13;
public static final int NUM_OTHER_STATS = 14;
/** @hide */
public static final int NUM_DVK_STATS = 5;
@@ -285,11 +285,12 @@ public final class Debug
case 10: return "code mmap";
case 11: return "image mmap";
case 12: return "Other mmap";
case 13: return ".Heap";
case 14: return ".LOS";
case 15: return ".LinearAlloc";
case 16: return ".GC";
case 17: return ".JITCache";
case 13: return "GPU";
case 14: return ".Heap";
case 15: return ".LOS";
case 16: return ".LinearAlloc";
case 17: return ".GC";
case 18: return ".JITCache";
default: return "????";
}
}

View File

@@ -56,6 +56,7 @@ enum {
HEAP_OAT,
HEAP_ART,
HEAP_UNKNOWN_MAP,
HEAP_GPU,
HEAP_DALVIK_NORMAL,
HEAP_DALVIK_LARGE,
@@ -64,7 +65,7 @@ enum {
HEAP_DALVIK_CODE_CACHE,
_NUM_HEAP,
_NUM_EXCLUSIVE_HEAP = HEAP_UNKNOWN_MAP+1,
_NUM_EXCLUSIVE_HEAP = HEAP_GPU+1,
_NUM_CORE_HEAP = HEAP_NATIVE+1
};
@@ -137,6 +138,72 @@ static jlong android_os_Debug_getNativeHeapFreeSize(JNIEnv *env, jobject clazz)
#endif
}
// XXX Qualcom-specific!
static jlong read_gpu_mem(int pid)
{
char line[1024];
jlong uss = 0;
unsigned temp;
char tmp[128];
FILE *fp;
sprintf(tmp, "/d/kgsl/proc/%d/mem", pid);
fp = fopen(tmp, "r");
if (fp == 0) {
//ALOGI("Unable to open: %s", tmp);
return 0;
}
while (true) {
if (fgets(line, 1024, fp) == NULL) {
break;
}
//ALOGI("Read: %s", line);
// Format is:
// gpuaddr useraddr size id flags type usage sglen
// 54676000 54676000 4096 1 ----p gpumem arraybuffer 1
//
// If useraddr is 0, this is gpu mem not otherwise accounted
// against the process.
// Make sure line is long enough.
int i = 0;
while (i < 9) {
if (line[i] == 0) {
break;
}
i++;
}
if (i < 9) {
//ALOGI("Early line term!");
continue;
}
// Look to see if useraddr is 00000000.
while (i < 17) {
if (line[i] != '0') {
break;
}
i++;
}
if (i < 17) {
//ALOGI("useraddr not 0!");
continue;
}
uss += atoi(line + i);
//ALOGI("Uss now: %ld", uss);
}
fclose(fp);
// Convert from bytes to KB.
return uss / 1024;
}
static void read_mapinfo(FILE *fp, stats_t* stats)
{
char line[1024];
@@ -340,6 +407,10 @@ static void android_os_Debug_getDirtyPagesPid(JNIEnv *env, jobject clazz,
load_maps(pid, stats);
jlong gpu = read_gpu_mem(pid);
stats[HEAP_GPU].pss += gpu;
stats[HEAP_GPU].privateDirty += gpu;
for (int i=_NUM_CORE_HEAP; i<_NUM_EXCLUSIVE_HEAP; i++) {
stats[HEAP_UNKNOWN].pss += stats[i].pss;
stats[HEAP_UNKNOWN].swappablePss += stats[i].swappablePss;
@@ -394,34 +465,37 @@ static jlong android_os_Debug_getPssPid(JNIEnv *env, jobject clazz, jint pid, jl
char tmp[128];
FILE *fp;
pss = uss = read_gpu_mem(pid);
sprintf(tmp, "/proc/%d/smaps", pid);
fp = fopen(tmp, "r");
if (fp == 0) return 0;
while (true) {
if (fgets(line, 1024, fp) == NULL) {
break;
}
if (fp != 0) {
while (true) {
if (fgets(line, 1024, fp) == NULL) {
break;
}
if (line[0] == 'P') {
if (strncmp(line, "Pss:", 4) == 0) {
char* c = line + 4;
while (*c != 0 && (*c < '0' || *c > '9')) {
c++;
if (line[0] == 'P') {
if (strncmp(line, "Pss:", 4) == 0) {
char* c = line + 4;
while (*c != 0 && (*c < '0' || *c > '9')) {
c++;
}
pss += atoi(c);
} else if (strncmp(line, "Private_Clean:", 14)
|| strncmp(line, "Private_Dirty:", 14)) {
char* c = line + 14;
while (*c != 0 && (*c < '0' || *c > '9')) {
c++;
}
uss += atoi(c);
}
pss += atoi(c);
} else if (strncmp(line, "Private_Clean:", 14)
|| strncmp(line, "Private_Dirty:", 14)) {
char* c = line + 14;
while (*c != 0 && (*c < '0' || *c > '9')) {
c++;
}
uss += atoi(c);
}
}
}
fclose(fp);
fclose(fp);
}
if (outUss != NULL) {
if (env->GetArrayLength(outUss) >= 1) {