FileDocCategorySizeDatePackage
MediaTestUtil.javaAPI DocAndroid 5.1 API4855Thu Mar 12 22:22:30 GMT 2015com.android.mediaframeworktest

MediaTestUtil

public class MediaTestUtil extends Object
Utilities for media framework test.

Fields Summary
private static String
TAG
private static final String
STORAGE_PATH
private int
mStartMemory
private int
mStartPid
private Writer
mOutput
private String
mTestName
private String
mProcessName
Constructors Summary
public MediaTestUtil(String memoryOutFileName, String testName, String processName)


          
              
        File memoryOut = new File(memoryOutFileName);
        mOutput = new BufferedWriter(new FileWriter(memoryOut, true));
        mProcessName = processName;
        mTestName = testName;
        mStartPid = getPid();
        mStartMemory = getVsize();
    
Methods Summary
private java.lang.StringcaptureMemInfo()

        String cm = "ps ";
        cm += mProcessName;
        Log.v(TAG, cm);
        String memoryUsage = null;

        int ch;
        try {
            Process p = Runtime.getRuntime().exec(cm);
            InputStream in = p.getInputStream();
            StringBuffer sb = new StringBuffer(512);
            while ((ch = in.read()) != -1) {
                sb.append((char) ch);
            }
            memoryUsage = sb.toString();
        } catch (IOException e) {
            Log.v(TAG, e.toString());
        }
        String[] poList = memoryUsage.split("\r|\n|\r\n");
        // Skip the first two lines since there
        // is a new media.log introudced recently.
        String memusage = poList[2].concat("\n");
        return memusage;
    
public voidgetMemoryLog()

        String memusage = null;
        memusage = captureMemInfo();
        mOutput.write(memusage);
        mOutput.flush();
    
public voidgetMemorySummary()

        int endMemory = 0;
        int memDiff = 0;

        endMemory = getVsize();
        memDiff = endMemory - mStartMemory;

        mOutput.write("End Memory :" + endMemory + "\n");
        if (memDiff < 0) {
            memDiff = 0;
        }
        mOutput.write(mTestName + " total diff = " + memDiff);
        mOutput.write("\n\n");
        validateProcessStatus();
        mOutput.flush();
        mOutput.close();
    
public static voidgetNativeHeapDump(java.lang.String name)

        System.gc();
        System.runFinalization();
        Thread.sleep(1000);
        FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/" + name + ".dump");
        Debug.dumpNativeHeap(o.getFD());
        o.close();
    
private intgetPid()

        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;
    
public voidgetStartMemoryLog()

        String memusage = null;
        mStartMemory = getVsize();
        mOutput.write(mTestName + '\n");
        mOutput.write("Start memory : " + mStartMemory + "\n");
        memusage = captureMemInfo();
        mOutput.write(memusage);
    
private intgetVsize()

        String memoryUsage = captureMemInfo();
        String[] poList2 = memoryUsage.split("\t|\\s+");
        String vsize = poList2[3];
        int vsizevalue = Integer.parseInt(vsize);
        Log.v(TAG, "VSIZE = " + vsizevalue);
        return vsizevalue;
    
private voidvalidateProcessStatus()

        int currentPid = getPid();
        //Process crash
        if (mStartPid != currentPid) {
            mOutput.write(mProcessName + " died. Test failed\n");
        }