Skip to content

Commit 82c8cda

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Add run all button to image processing test." into jb-mr1-dev
2 parents 7546b5f + b94d69a commit 82c8cda

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

tests/RenderScriptTests/ImageProcessing/res/layout/main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
android:layout_marginRight="10sp"
125125
android:layout_width="match_parent"
126126
android:layout_height="wrap_content"/>
127+
<Button
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:text="@string/benchmark_all"
131+
android:onClick="benchmark_all"/>
127132
</LinearLayout>
128133
</ScrollView>
129134
</LinearLayout>

tests/RenderScriptTests/ImageProcessing/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<string name="gamma">Gamma</string>
3030
<string name="saturation">Saturation</string>
3131
<string name="benchmark">Benchmark</string>
32+
<string name="benchmark_all">Benchmark All</string>
3233

3334
</resources>

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@
3939
import android.util.Log;
4040
import java.lang.Math;
4141

42+
import android.os.Environment;
43+
import android.app.Instrumentation;
44+
import android.content.Context;
45+
import android.content.Intent;
46+
import android.net.Uri;
47+
import java.io.BufferedWriter;
48+
import java.io.File;
49+
import java.io.FileWriter;
50+
import java.io.IOException;
51+
4252
public class ImageProcessingActivity extends Activity
4353
implements SeekBar.OnSeekBarChangeListener {
4454
private final String TAG = "Img";
55+
private final String RESULT_FILE = "image_processing_result.csv";
56+
4557
Bitmap mBitmapIn;
4658
Bitmap mBitmapOut;
4759
String mTestNames[];
@@ -325,6 +337,33 @@ public void benchmark(View v) {
325337
//long javaTime = javaFilter();
326338
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
327339
mBenchmarkResult.setText("Result: " + t + " ms");
340+
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
341+
}
342+
343+
public void benchmark_all(View v) {
344+
// write result into a file
345+
File externalStorage = Environment.getExternalStorageDirectory();
346+
if (!externalStorage.canWrite()) {
347+
Log.v(TAG, "sdcard is not writable");
348+
return;
349+
}
350+
File resultFile = new File(externalStorage, RESULT_FILE);
351+
resultFile.setWritable(true, false);
352+
try {
353+
BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
354+
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
355+
for (int i = 0; i < mTestNames.length; i++ ) {
356+
changeTest(i);
357+
float t = getBenchmark();
358+
String s = new String("" + mTestNames[i] + ", " + t);
359+
rsWriter.write(s + "\n");
360+
Log.v(TAG, "Test " + s + "ms\n");
361+
}
362+
rsWriter.close();
363+
} catch (IOException e) {
364+
Log.v(TAG, "Unable to write result file " + e.getMessage());
365+
}
366+
changeTest(0);
328367
}
329368

330369
// For benchmark test
@@ -334,25 +373,26 @@ public float getBenchmark() {
334373
mTest.setupBenchmark();
335374
long result = 0;
336375

337-
Log.v(TAG, "Warming");
376+
//Log.v(TAG, "Warming");
338377
long t = java.lang.System.currentTimeMillis() + 2000;
339378
do {
340379
mTest.runTest();
341380
mTest.finish();
342381
} while (t > java.lang.System.currentTimeMillis());
343382

344383

345-
Log.v(TAG, "Benchmarking");
384+
//Log.v(TAG, "Benchmarking");
385+
int ct = 0;
346386
t = java.lang.System.currentTimeMillis();
347-
for (int i=0; i<10; i++) {
387+
do {
348388
mTest.runTest();
349-
}
350-
mTest.finish();
389+
mTest.finish();
390+
ct++;
391+
} while ((t+5000) > java.lang.System.currentTimeMillis());
351392
t = java.lang.System.currentTimeMillis() - t;
352393
float ft = (float)t;
353-
ft /= 10;
394+
ft /= ct;
354395

355-
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + ft);
356396
mTest.exitBenchmark();
357397
mDoingBenchmark = false;
358398

0 commit comments

Comments
 (0)