diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-07-03 11:47:44 +0000 |
---|---|---|
committer | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-07-03 11:47:44 +0000 |
commit | 0a0431e1d7533f60f26e74a4eb3c1eec0e6189d5 (patch) | |
tree | b2f8e53cfe95ae12e85361ee50411874008f5569 | |
parent | dbfaf0539ced4c4ee275d5428ae9440786ec2d76 (diff) | |
download | mmtest-0a0431e1d7533f60f26e74a4eb3c1eec0e6189d5.tar.gz |
Track and report CPU usage
-rw-r--r-- | mmtest/src/org/linaro/mmtest/MultimediaTest.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mmtest/src/org/linaro/mmtest/MultimediaTest.java b/mmtest/src/org/linaro/mmtest/MultimediaTest.java index 6644c2f..6c4c540 100644 --- a/mmtest/src/org/linaro/mmtest/MultimediaTest.java +++ b/mmtest/src/org/linaro/mmtest/MultimediaTest.java @@ -8,8 +8,10 @@ import android.util.Log; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; +import android.os.Process; import android.view.SurfaceView; +import java.io.RandomAccessFile; import java.lang.Math; import java.util.List; @@ -19,6 +21,7 @@ public class MultimediaTest extends Activity implements android.media.MediaPlaye private MediaPlayer mp; private String failure; private long timestamp; + private long cpuTimestamp; private int expectedDuration; private final Test[] tests = { // Audio Codecs @@ -112,6 +115,7 @@ public class MultimediaTest extends Activity implements android.media.MediaPlaye else Log.i(TAG, "FAIL:" + tests[currentTest].name + ":sanityCheck:Test and Player disagree about whether or not the content has a video part"); timestamp = System.currentTimeMillis(); + cpuTimestamp = cpuTime(); expectedDuration = mp.getDuration(); if(expectedDuration <= 0) Log.i(TAG, "WARN:" + tests[currentTest].name + ":Couldn't determine duration"); @@ -121,6 +125,7 @@ public class MultimediaTest extends Activity implements android.media.MediaPlaye @Override public void onCompletion(MediaPlayer mp) { long elapsedTime = System.currentTimeMillis() - timestamp; + long elapsedCpuTime = cpuTime() - cpuTimestamp; if(failure.length() == 0) { if(expectedDuration >= 0 && Math.abs(elapsedTime - expectedDuration) > 10000) { Log.i(TAG, "WARN:" + tests[currentTest].name + ":Actual playing time (" + Long.toString(elapsedTime) + "ms) differs significantly from expected time (" + Integer.toString(expectedDuration) + "ms)"); @@ -128,6 +133,11 @@ public class MultimediaTest extends Activity implements android.media.MediaPlaye Log.i(TAG, "PASS:" + tests[currentTest].name + ":playback"); } else Log.i(TAG, "FAIL:" + tests[currentTest].name + ":playback:" + failure); + // FIXME we should find a reasonable threshold to make + // an educated guess on whether or not a codec is hardware + // accelerated. + // Will require some testing on different hardware... + Log.i(TAG, "PERF:" + tests[currentTest].name + Long.toString(elapsedCpuTime) + " jiffies used"); runNextTest(); } @@ -142,4 +152,23 @@ public class MultimediaTest extends Activity implements android.media.MediaPlaye Log.i(TAG, "NOTE:" + tests[currentTest].name + ":playback:MediaPlayer sent info " + Integer.toString(what) + "/" + Integer.toString(extra)); return true; } + + public long cpuTime() { + long usedTime = 0; + try { + RandomAccessFile reader = new RandomAccessFile("/proc/" + Integer.toString(Process.myPid()) + "/stat", "r"); + String[] toks=reader.readLine().split(" "); + // 13: jiffies in user mode + // 14: jiffies in kernel mode + // 15: jiffies in user mode of child processes (maybe some codecs launch an external decoder...) + // 16: jiffies in kernel mode of child processes + usedTime = Long.parseLong(toks[13]) + Long.parseLong(toks[14]) + Long.parseLong(toks[15]) + Long.parseLong(toks[16]); + reader.close(); + } catch(java.io.FileNotFoundException e) { + Log.e(TAG, "ERR:/proc not mounted?"); + } catch(java.io.IOException e) { + Log.e(TAG, "ERR:I/O error while reading CPU load"); + } + return usedTime; + } } |