Skip to content

Commit 2ffd207

Browse files
author
Yu Shan Emily Lau
committed
Instead of collecting the procmem output in
the test, change it as optional. This is to avoid the tool breakage will block the whole memory test sutie. Change-Id: Ia7425531ca2151230d7fd98eb710f282e166b4f7
1 parent ebf7e28 commit 2ffd207

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkPerfTestRunner.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public class MediaFrameworkPerfTestRunner extends InstrumentationTestRunner {
3939

4040
public static boolean mGetNativeHeapDump = false;
41-
41+
public static boolean mGetProcmem = false;
4242

4343
@Override
4444
public TestSuite getAllTests() {
@@ -61,6 +61,12 @@ public void onCreate(Bundle icicle) {
6161
if (get_heap_dump != null) {
6262
mGetNativeHeapDump = true;
6363
}
64+
65+
String get_procmem = (String) icicle.get("get_procmem");
66+
if (get_procmem != null) {
67+
mGetProcmem = true;
68+
}
69+
6470
}
6571
}
6672

media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright (C) 2008 The Android Open Source Project
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
66
* the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1212
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -53,7 +53,7 @@
5353
import com.android.mediaframeworktest.MediaProfileReader;
5454

5555
/**
56-
* Junit / Instrumentation - performance measurement for media player and
56+
* Junit / Instrumentation - performance measurement for media player and
5757
* recorder
5858
*
5959
* FIXME:
@@ -100,6 +100,7 @@ public MediaPlayerPerformance() {
100100
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
101101
}
102102

103+
@Override
103104
protected void setUp() throws Exception {
104105
super.setUp();
105106
//Insert a 2 second before launching the test activity. This is
@@ -109,19 +110,26 @@ protected void setUp() throws Exception {
109110
if (MediaFrameworkPerfTestRunner.mGetNativeHeapDump)
110111
MediaTestUtil.getNativeHeapDump(this.getName() + "_before");
111112

112-
mProcMemWriter = new BufferedWriter(new FileWriter
113-
(new File(MEDIA_PROCMEM_OUTPUT), true));
114-
mProcMemWriter.write(this.getName() + "\n");
115-
mMemWriter = new BufferedWriter(new FileWriter
116-
(new File(MEDIA_MEMORY_OUTPUT), true));
113+
if (MediaFrameworkPerfTestRunner.mGetProcmem) {
114+
mProcMemWriter = new BufferedWriter(new FileWriter
115+
(new File(MEDIA_PROCMEM_OUTPUT), true));
116+
mProcMemWriter.write(this.getName() + "\n");
117+
mMemWriter = new BufferedWriter(new FileWriter
118+
(new File(MEDIA_MEMORY_OUTPUT), true));
119+
}
117120

118121
}
119122

123+
@Override
120124
protected void tearDown() throws Exception {
121125
if (MediaFrameworkPerfTestRunner.mGetNativeHeapDump)
122126
MediaTestUtil.getNativeHeapDump(this.getName() + "_after");
123-
mProcMemWriter.close();
124-
mMemWriter.close();
127+
128+
if (MediaFrameworkPerfTestRunner.mGetProcmem) {
129+
mMemWriter.write("\n");
130+
mProcMemWriter.close();
131+
mMemWriter.close();
132+
}
125133
super.tearDown();
126134
}
127135

@@ -157,6 +165,7 @@ private void terminateMessageLooper() throws Exception {
157165
}
158166

159167
private final class RawPreviewCallback implements PreviewCallback {
168+
@Override
160169
public void onPreviewFrame(byte[] rawData, Camera camera) {
161170
mPreviewDone.open();
162171
}
@@ -285,19 +294,21 @@ public void getMemoryWriteToLog(int writeCount) {
285294
}
286295
}
287296

288-
public void writeProcmemInfo() throws Exception{
289-
String cmd = "procmem " + getMediaserverPid();
290-
Process p = Runtime.getRuntime().exec(cmd);
291-
292-
InputStream inStream = p.getInputStream();
293-
InputStreamReader inReader = new InputStreamReader(inStream);
294-
BufferedReader inBuffer = new BufferedReader(inReader);
295-
String s;
296-
while ((s = inBuffer.readLine()) != null) {
297-
mProcMemWriter.write(s);
298-
mProcMemWriter.write("\n");
297+
public void writeProcmemInfo() throws Exception {
298+
if (MediaFrameworkPerfTestRunner.mGetProcmem) {
299+
String cmd = "procmem " + getMediaserverPid();
300+
Process p = Runtime.getRuntime().exec(cmd);
301+
302+
InputStream inStream = p.getInputStream();
303+
InputStreamReader inReader = new InputStreamReader(inStream);
304+
BufferedReader inBuffer = new BufferedReader(inReader);
305+
String s;
306+
while ((s = inBuffer.readLine()) != null) {
307+
mProcMemWriter.write(s);
308+
mProcMemWriter.write("\n");
309+
}
310+
mProcMemWriter.write("\n\n");
299311
}
300-
mProcMemWriter.write("\n\n");
301312
}
302313

303314
public String captureMediaserverInfo() {
@@ -368,13 +379,11 @@ public void testH263VideoPlaybackMemoryUsage() throws Exception {
368379
boolean memoryResult = false;
369380

370381
mStartPid = getMediaserverPid();
371-
mMemWriter.write("H263 Video Playback Only\n");
372382
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
373383
mediaStressPlayback(MediaNames.VIDEO_HIGHRES_H263);
374384
getMemoryWriteToLog(i);
375385
writeProcmemInfo();
376386
}
377-
mMemWriter.write("\n");
378387
memoryResult = validateMemoryResult(mStartPid, mStartMemory, DECODER_LIMIT);
379388
assertTrue("H263 playback memory test", memoryResult);
380389
}
@@ -385,13 +394,11 @@ public void testH264VideoPlaybackMemoryUsage() throws Exception {
385394
boolean memoryResult = false;
386395

387396
mStartPid = getMediaserverPid();
388-
mMemWriter.write("H264 Video Playback only\n");
389397
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
390398
mediaStressPlayback(MediaNames.VIDEO_H264_AMR);
391399
getMemoryWriteToLog(i);
392400
writeProcmemInfo();
393401
}
394-
mMemWriter.write("\n");
395402
memoryResult = validateMemoryResult(mStartPid, mStartMemory, DECODER_LIMIT);
396403
assertTrue("H264 playback memory test", memoryResult);
397404
}
@@ -402,7 +409,6 @@ public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
402409
boolean memoryResult = false;
403410

404411
mStartPid = getMediaserverPid();
405-
mMemWriter.write("H263 video record only\n");
406412
int frameRate = MediaProfileReader.getMaxFrameRateForCodec(MediaRecorder.VideoEncoder.H263);
407413
assertTrue("H263 video recording frame rate", frameRate != -1);
408414
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
@@ -411,7 +417,6 @@ public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
411417
getMemoryWriteToLog(i);
412418
writeProcmemInfo();
413419
}
414-
mMemWriter.write("\n");
415420
memoryResult = validateMemoryResult(mStartPid, mStartMemory, ENCODER_LIMIT);
416421
assertTrue("H263 record only memory test", memoryResult);
417422
}
@@ -422,7 +427,6 @@ public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception {
422427
boolean memoryResult = false;
423428

424429
mStartPid = getMediaserverPid();
425-
mMemWriter.write("MPEG4 video record only\n");
426430
int frameRate = MediaProfileReader.getMaxFrameRateForCodec(MediaRecorder.VideoEncoder.MPEG_4_SP);
427431
assertTrue("MPEG4 video recording frame rate", frameRate != -1);
428432
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
@@ -431,7 +435,6 @@ public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception {
431435
getMemoryWriteToLog(i);
432436
writeProcmemInfo();
433437
}
434-
mMemWriter.write("\n");
435438
memoryResult = validateMemoryResult(mStartPid, mStartMemory, ENCODER_LIMIT);
436439
assertTrue("mpeg4 record only memory test", memoryResult);
437440
}
@@ -445,14 +448,12 @@ public void testRecordVideoAudioMemoryUsage() throws Exception {
445448
mStartPid = getMediaserverPid();
446449
int frameRate = MediaProfileReader.getMaxFrameRateForCodec(MediaRecorder.VideoEncoder.H263);
447450
assertTrue("H263 video recording frame rate", frameRate != -1);
448-
mMemWriter.write("Audio and h263 video record\n");
449451
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
450452
assertTrue(stressVideoRecord(frameRate, 352, 288, MediaRecorder.VideoEncoder.H263,
451453
MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, false));
452454
getMemoryWriteToLog(i);
453455
writeProcmemInfo();
454456
}
455-
mMemWriter.write("\n");
456457
memoryResult = validateMemoryResult(mStartPid, mStartMemory, ENCODER_LIMIT);
457458
assertTrue("H263 audio video record memory test", memoryResult);
458459
}
@@ -463,13 +464,11 @@ public void testRecordAudioOnlyMemoryUsage() throws Exception {
463464
boolean memoryResult = false;
464465

465466
mStartPid = getMediaserverPid();
466-
mMemWriter.write("Audio record only\n");
467467
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
468468
stressAudioRecord(MediaNames.RECORDER_OUTPUT);
469469
getMemoryWriteToLog(i);
470470
writeProcmemInfo();
471471
}
472-
mMemWriter.write("\n");
473472
memoryResult = validateMemoryResult(mStartPid, mStartMemory, ENCODER_LIMIT);
474473
assertTrue("audio record only memory test", memoryResult);
475474
}
@@ -480,13 +479,11 @@ public void testCameraPreviewMemoryUsage() throws Exception {
480479
boolean memoryResult = false;
481480

482481
mStartPid = getMediaserverPid();
483-
mMemWriter.write("Camera Preview Only\n");
484482
for (int i = 0; i < NUM_STRESS_LOOP; i++) {
485483
stressCameraPreview();
486484
getMemoryWriteToLog(i);
487485
writeProcmemInfo();
488486
}
489-
mMemWriter.write("\n");
490487
memoryResult = validateMemoryResult(mStartPid, mStartMemory, CAMERA_LIMIT);
491488
assertTrue("camera preview memory test", memoryResult);
492489
}

0 commit comments

Comments
 (0)