am 112852b5: am 02109972: Merge "Add the mem logging into test utility. Bug# 4108259" into honeycomb-mr1

* commit '112852b5770300a81d82f0ec06ad0553f286ed01':
  Add the mem logging into test utility. Bug# 4108259
This commit is contained in:
Yu Shan Emily Lau
2011-03-21 18:14:12 -07:00
committed by Android Git Automerger

View File

@@ -16,7 +16,10 @@
package com.android.mediaframeworktest; package com.android.mediaframeworktest;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Writer; import java.io.Writer;
@@ -31,28 +34,58 @@ import android.util.Log;
* *
*/ */
public class MediaTestUtil { public class MediaTestUtil {
private MediaTestUtil(){
}
private static String TAG = "MediaTestUtil"; private static String TAG = "MediaTestUtil";
private static final String STORAGE_PATH = private static final String STORAGE_PATH = Environment.getExternalStorageDirectory().toString();
Environment.getExternalStorageDirectory().toString(); private int mStartMemory = 0;
private static int mMediaStartMemory = 0; private int mStartPid = 0;
private static int mDrmStartMemory = 0; private Writer mOutput = null;
private String mTestName = null;
private String mProcessName = null;
//Catpure the heapdump for memory leaksage analysis public MediaTestUtil(String memoryOutFileName, String testName, String processName)
public static void getNativeHeapDump (String name) throws Exception { throws Exception {
File memoryOut = new File(memoryOutFileName);
mOutput = new BufferedWriter(new FileWriter(memoryOut, true));
mProcessName = processName;
mTestName = testName;
mStartPid = getPid();
mStartMemory = getVsize();
}
// Catpure the heapdump for memory leaksage analysis
public static void getNativeHeapDump(String name) throws Exception {
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
Thread.sleep(1000); Thread.sleep(1000);
FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' +name + ".dump"); FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' + name + ".dump");
Debug.dumpNativeHeap(o.getFD()); Debug.dumpNativeHeap(o.getFD());
o.close(); o.close();
} }
public static String captureMemInfo(String type) { private void validateProcessStatus() throws Exception {
int currentPid = getPid();
//Process crash
if (mStartPid != currentPid) {
mOutput.write(mProcessName + " died. Test failed\n");
}
}
private int getPid() {
String memoryUsage = null;
int pidvalue = 0;
memoryUsage = captureMemInfo();
String[] poList2 = memoryUsage.split("\t|\\s+");
String pid = poList2[1];
pidvalue = Integer.parseInt(pid);
Log.v(TAG, "PID = " + pidvalue);
return pidvalue;
}
private String captureMemInfo() {
String cm = "ps "; String cm = "ps ";
cm += type; cm += mProcessName;
Log.v(TAG, cm);
String memoryUsage = null; String memoryUsage = null;
int ch; int ch;
@@ -72,8 +105,8 @@ public class MediaTestUtil {
return memusage; return memusage;
} }
public static int getMediaServerVsize() { private int getVsize() {
String memoryUsage = captureMemInfo("mediaserver"); String memoryUsage = captureMemInfo();
String[] poList2 = memoryUsage.split("\t|\\s+"); String[] poList2 = memoryUsage.split("\t|\\s+");
String vsize = poList2[3]; String vsize = poList2[3];
int vsizevalue = Integer.parseInt(vsize); int vsizevalue = Integer.parseInt(vsize);
@@ -81,71 +114,39 @@ public class MediaTestUtil {
return vsizevalue; return vsizevalue;
} }
public static int getDrmServerVsize() { // Write the startup media memory mOutput to the file
String memoryUsage = captureMemInfo("drmserver"); public void getStartMemoryLog() throws Exception {
String[] poList2 = memoryUsage.split("\t|\\s+");
String vsize = poList2[3];
int vsizevalue = Integer.parseInt(vsize);
Log.v(TAG, "VSIZE = " + vsizevalue);
return vsizevalue;
}
// Write the ps mediaserver output to the file
public static void getMediaServerMemoryLog(Writer output, int writeCount, int totalCount)
throws Exception {
String memusage = null; String memusage = null;
mStartMemory = getVsize();
if (writeCount == 0) { mOutput.write(mTestName + '\n');
mMediaStartMemory = getMediaServerVsize(); mOutput.write("Start memory : " + mStartMemory + "\n");
output.write("Start memory : " + mMediaStartMemory + "\n"); memusage = captureMemInfo();
} mOutput.write(memusage);
memusage = captureMemInfo("mediaserver");
output.write(memusage);
} }
// Write the ps drmserver output to the file // Write the ps mediaserver mOutput to the file
public static void getDrmServerMemoryLog(Writer output, int writeCount, int totalCount) public void getMemoryLog() throws Exception {
throws Exception {
String memusage = null; String memusage = null;
memusage = captureMemInfo();
if (writeCount == 0) { mOutput.write(memusage);
mDrmStartMemory = getDrmServerVsize(); mOutput.flush();
output.write("Start memory : " + mDrmStartMemory + "\n");
}
memusage = captureMemInfo("drmserver");
output.write(memusage);
} }
// Write the ps drmserver output to the file public void getMemorySummary() throws Exception {
public static void getDrmServerMemorySummary(Writer output, String tag) throws Exception {
getTestMemorySummary(output, tag, "drmMem");
}
// Write the ps drmserver output to the file
public static void getMediaServerMemorySummary(Writer output, String tag) throws Exception {
getTestMemorySummary(output, tag, "mediaMem");
}
public static void getTestMemorySummary(Writer output, String tag, String type)
throws Exception {
int endMemory = 0; int endMemory = 0;
int memDiff = 0; int memDiff = 0;
if (type == "mediaMem") { endMemory = getVsize();
endMemory = getMediaServerVsize(); memDiff = endMemory - mStartMemory;
memDiff = endMemory - mMediaStartMemory;
} else if (type == "drmMem") { mOutput.write("End Memory :" + endMemory + "\n");
endMemory = getDrmServerVsize();
memDiff = endMemory - mDrmStartMemory;
}
output.write("End Memory :" + endMemory + "\n");
if (memDiff < 0) { if (memDiff < 0) {
memDiff = 0; memDiff = 0;
} }
output.write(tag + " total diff = " + memDiff); mOutput.write(mTestName + " total diff = " + memDiff);
output.write("\n\n"); mOutput.write("\n\n");
validateProcessStatus();
mOutput.flush();
mOutput.close();
} }
} }