Skip to content

Commit b94d69a

Browse files
author
Jason Sams
committed
Add run all button to image processing test.
Change-Id: I11b4f803151ee7dc1e4b86f402196c1b856bd950
1 parent 36fa5a4 commit b94d69a

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[];
@@ -320,6 +332,33 @@ public void benchmark(View v) {
320332
//long javaTime = javaFilter();
321333
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
322334
mBenchmarkResult.setText("Result: " + t + " ms");
335+
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
336+
}
337+
338+
public void benchmark_all(View v) {
339+
// write result into a file
340+
File externalStorage = Environment.getExternalStorageDirectory();
341+
if (!externalStorage.canWrite()) {
342+
Log.v(TAG, "sdcard is not writable");
343+
return;
344+
}
345+
File resultFile = new File(externalStorage, RESULT_FILE);
346+
resultFile.setWritable(true, false);
347+
try {
348+
BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
349+
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
350+
for (int i = 0; i < mTestNames.length; i++ ) {
351+
changeTest(i);
352+
float t = getBenchmark();
353+
String s = new String("" + mTestNames[i] + ", " + t);
354+
rsWriter.write(s + "\n");
355+
Log.v(TAG, "Test " + s + "ms\n");
356+
}
357+
rsWriter.close();
358+
} catch (IOException e) {
359+
Log.v(TAG, "Unable to write result file " + e.getMessage());
360+
}
361+
changeTest(0);
323362
}
324363

325364
// For benchmark test
@@ -329,25 +368,26 @@ public float getBenchmark() {
329368
mTest.setupBenchmark();
330369
long result = 0;
331370

332-
Log.v(TAG, "Warming");
371+
//Log.v(TAG, "Warming");
333372
long t = java.lang.System.currentTimeMillis() + 2000;
334373
do {
335374
mTest.runTest();
336375
mTest.finish();
337376
} while (t > java.lang.System.currentTimeMillis());
338377

339378

340-
Log.v(TAG, "Benchmarking");
379+
//Log.v(TAG, "Benchmarking");
380+
int ct = 0;
341381
t = java.lang.System.currentTimeMillis();
342-
for (int i=0; i<10; i++) {
382+
do {
343383
mTest.runTest();
344-
}
345-
mTest.finish();
384+
mTest.finish();
385+
ct++;
386+
} while ((t+5000) > java.lang.System.currentTimeMillis());
346387
t = java.lang.System.currentTimeMillis() - t;
347388
float ft = (float)t;
348-
ft /= 10;
389+
ft /= ct;
349390

350-
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + ft);
351391
mTest.exitBenchmark();
352392
mDoingBenchmark = false;
353393

0 commit comments

Comments
 (0)