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

Commit 02109972 authored by Yu Shan Emily Lau's avatar Yu Shan Emily Lau Committed by Android (Google) Code Review
Browse files

Merge "Add the mem logging into test utility. Bug# 4108259" into honeycomb-mr1

parents 7abedd0c 75afb97c
Loading
Loading
Loading
Loading
+68 −67
Original line number Original line Diff line number Diff line
@@ -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,14 +34,24 @@ 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;

    public MediaTestUtil(String memoryOutFileName, String testName, String processName)
            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
    // Catpure the heapdump for memory leaksage analysis
    public static void getNativeHeapDump(String name) throws Exception {
    public static void getNativeHeapDump(String name) throws Exception {
@@ -50,9 +63,29 @@ public class MediaTestUtil {
        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,17 +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 vsize = poList2[3];
        int vsizevalue = Integer.parseInt(vsize);
        Log.v(TAG, "VSIZE = " + vsizevalue);
        return vsizevalue;
    }

    public static int getDrmServerVsize() {
        String memoryUsage = captureMemInfo("drmserver");
        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);
@@ -90,62 +114,39 @@ public class MediaTestUtil {
        return vsizevalue;
        return vsizevalue;
    }
    }


    // Write the ps mediaserver output to the file
    // Write the startup media memory mOutput to the file
    public static void getMediaServerMemoryLog(Writer output, int writeCount, int totalCount)
    public void getStartMemoryLog() throws Exception {
            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 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)
    public void getMemorySummary() throws Exception {
            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();
    }
    }
}
}