summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2015-09-03 16:34:16 -0700
committerJason Sams <jsams@google.com>2015-09-03 16:34:16 -0700
commitaa735abcfb4112c305accf69ba507a739165a960 (patch)
treef4edaec54926ac662834ee8f812b515981f952f2 /app/src/main/java
parent6d1c42ca370661825bdb575378e8decae99ca678 (diff)
downloadBenchmark-aa735abcfb4112c305accf69ba507a739165a960.tar.gz
Initial upload of benchmark prototype
Change-Id: Id3e1d2b427cb39b8a65d5ad65aad1257c929a88d
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/android/benchmark/BenchmarkFrame.java91
-rw-r--r--app/src/main/java/com/android/benchmark/BenchmarkFrameFragment.java42
-rw-r--r--app/src/main/java/com/android/benchmark/CpuSynthetic.java81
-rw-r--r--app/src/main/java/com/android/benchmark/MemoryActivity.java128
-rw-r--r--app/src/main/java/com/android/benchmark/MemoryAvailable.java149
-rw-r--r--app/src/main/java/com/android/benchmark/MemoryAvailableLoad1.java233
-rw-r--r--app/src/main/java/com/android/benchmark/MemoryAvailableLoad2.java233
-rw-r--r--app/src/main/java/com/android/benchmark/PerfTimeline.java226
-rw-r--r--app/src/main/java/com/android/benchmark/TestInterface.java383
-rw-r--r--app/src/main/java/com/android/benchmark/UI2D.java54
-rw-r--r--app/src/main/java/com/android/benchmark/UI2DTestTiles.java54
11 files changed, 1674 insertions, 0 deletions
diff --git a/app/src/main/java/com/android/benchmark/BenchmarkFrame.java b/app/src/main/java/com/android/benchmark/BenchmarkFrame.java
new file mode 100644
index 0000000..3eb2bd9
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/BenchmarkFrame.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.content.Intent;
+import android.widget.EditText;
+
+
+public class BenchmarkFrame extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_benchmark_frame);
+ }
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_benchmark_frame, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onClickedRunGames(View view) {
+
+ android.util.Log.e("bench", "1");
+
+ }
+
+ public void onClickedRunSynthetic(View view) {
+ //Intent intent = new Intent(this, MemoryActivity.class);
+ Intent intent = new Intent(this, CpuSynthetic.class);
+
+ //EditText editText = (EditText) findViewById(R.id.edit_message);
+ //String message = editText.getText().toString();
+ //intent.putExtra(EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+
+ public void onClickedRunUI(View view) {
+ Intent intent = new Intent(this, UI2D.class);
+ startActivity(intent);
+ }
+
+ public void onClickedRunCamera(View view) {
+
+ }
+
+ public void onClickedFreeMemory(View view) {
+ Intent intent = new Intent(this, MemoryAvailable.class);
+ intent.putExtra("reset", true);
+ startActivity(intent);
+ }
+
+}
diff --git a/app/src/main/java/com/android/benchmark/BenchmarkFrameFragment.java b/app/src/main/java/com/android/benchmark/BenchmarkFrameFragment.java
new file mode 100644
index 0000000..19a0713
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/BenchmarkFrameFragment.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+
+/**
+ * A placeholder fragment containing a simple view.
+ */
+public class BenchmarkFrameFragment extends Fragment {
+
+ public BenchmarkFrameFragment() {
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_benchmark_frame, container, false);
+ }
+
+
+
+}
diff --git a/app/src/main/java/com/android/benchmark/CpuSynthetic.java b/app/src/main/java/com/android/benchmark/CpuSynthetic.java
new file mode 100644
index 0000000..8c6d3d3
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/CpuSynthetic.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+
+
+public class CpuSynthetic extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_cpu_synthetic);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_cpu_synthetic, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onClickedCpuSyntheticTestMemoryBandwidth(View view) {
+ Intent intent = new Intent(this, MemoryActivity.class);
+ intent.putExtra("test", 0);
+ startActivity(intent);
+ }
+
+ public void onClickedCpuSyntheticTestMemoryLatency(View view) {
+ Intent intent = new Intent(this, MemoryActivity.class);
+ intent.putExtra("test", 1);
+ startActivity(intent);
+ }
+
+ public void onClickedCpuSyntheticTestPowerManagement(View view) {
+ Intent intent = new Intent(this, MemoryActivity.class);
+ intent.putExtra("test", 2);
+ startActivity(intent);
+ }
+
+ public void onClickedCpuSyntheticTestHeatSoak(View view) {
+ Intent intent = new Intent(this, MemoryActivity.class);
+ intent.putExtra("test", 3);
+ startActivity(intent);
+ }
+
+}
diff --git a/app/src/main/java/com/android/benchmark/MemoryActivity.java b/app/src/main/java/com/android/benchmark/MemoryActivity.java
new file mode 100644
index 0000000..6b17e3c
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/MemoryActivity.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+
+public class MemoryActivity extends Activity {
+ private TextView mTextStatus;
+ private TextView mTextMin;
+ private TextView mTextMax;
+ private TextView mTextTypical;
+ private PerfTimeline mTimeline;
+
+ TestInterface mTI;
+ int mActiveTest;
+
+ static {
+ System.loadLibrary("nativeMemory");
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_memory);
+
+ mTextStatus = (TextView) findViewById(R.id.textView_status);
+ mTextMin = (TextView) findViewById(R.id.textView_min);
+ mTextMax = (TextView) findViewById(R.id.textView_max);
+ mTextTypical = (TextView) findViewById(R.id.textView_typical);
+
+ mTimeline = (PerfTimeline) findViewById(R.id.mem_timeline);
+
+ android.util.Log.e("bench", "oc 1");
+ mTI = new TestInterface(mTimeline, 2);
+ mTI.mTextMax = mTextMax;
+ mTI.mTextMin = mTextMin;
+ mTI.mTextStatus = mTextStatus;
+ mTI.mTextTypical = mTextTypical;
+
+ mTimeline.mLinesLow = mTI.mLinesLow;
+ mTimeline.mLinesHigh = mTI.mLinesHigh;
+ mTimeline.mLinesValue = mTI.mLinesValue;
+
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Intent i = getIntent();
+ mActiveTest = i.getIntExtra("test", 0);
+
+
+ android.util.Log.e("bench", "oc 2");
+ switch (mActiveTest) {
+ case 0:
+ mTI.runMemoryBandwidth();
+ break;
+ case 1:
+ mTI.runMemoryLatency();
+ break;
+ case 2:
+ mTI.runPowerManagement();
+ break;
+ case 3:
+ mTI.runCPUHeatSoak();
+ break;
+ default:
+ break;
+
+ }
+
+ android.util.Log.e("bench", "oc 3");
+ }
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_memory, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onCpuBandwidth(View v) {
+
+
+ }
+
+
+
+
+}
diff --git a/app/src/main/java/com/android/benchmark/MemoryAvailable.java b/app/src/main/java/com/android/benchmark/MemoryAvailable.java
new file mode 100644
index 0000000..d457d33
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/MemoryAvailable.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.TextView;
+
+
+public class MemoryAvailable extends Activity {
+ private int mTargetPlainMemory;
+ private int mTargetBitmaps;
+ private int mTargetTextures;
+ private int mTargetCompute;
+ private int mTestLoadNumber = 0;
+ private boolean mDoReset = true;
+
+ private TextView mTextResult1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_memory_available);
+ android.util.Log.e("bench", "ma onCreate");
+ mDoReset = true;
+
+ mTextResult1 = (TextView) findViewById(R.id.memory_available_test_result1);
+ }
+
+ protected void onResume() {
+ super.onResume();
+ android.util.Log.e("bench", "ma onResume");
+
+ Intent i = getIntent();
+ android.util.Log.e("bench", "intent " + i);
+ if (mDoReset) {
+ mTargetPlainMemory = 10;
+ mTargetBitmaps = 0;
+ mTargetTextures = 0;
+ mTargetCompute = 0;
+ }
+ android.util.Log.e("bench", "doReset " + mDoReset);
+
+
+ if (mDoReset) {
+ startSubActivity(MemoryAvailableLoad1.class, 5, 1);
+ }
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_memory_available, menu);
+ return true;
+ }
+
+ private void startSubActivity(final Class c, final int delay, final int doInit) {
+ final MemoryAvailable ma = this;
+ final Handler handler = new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Intent intent = new Intent(ma, c);
+ intent.putExtra("reset", doInit);
+ intent.putExtra("plain", mTargetPlainMemory);
+ intent.putExtra("bitmaps", mTargetBitmaps);
+ intent.putExtra("textures", mTargetTextures);
+ intent.putExtra("compute", mTargetCompute);
+ startActivityForResult(intent, 0);
+ }
+ }, (1000 * delay));
+ }
+
+ private void postTextToView(TextView v, String s) {
+ final TextView tv = v;
+ final String ts = s;
+
+ v.post(new Runnable() {
+ public void run() {
+ tv.setText(ts);
+ }
+ });
+
+ }
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ android.util.Log.e("bench", "ma onActivityResult");
+
+ if (requestCode == 0) {
+ android.util.Log.e("bench", "ma result " + resultCode);
+
+ if (resultCode == RESULT_OK) {
+ mDoReset = false;
+
+ mTargetPlainMemory = data.getIntExtra("plain", 0);
+ mTargetBitmaps = data.getIntExtra("bitmaps", 0);
+ mTargetTextures = data.getIntExtra("textures", 0);
+ mTargetCompute = data.getIntExtra("compute", 0);
+
+ postTextToView(mTextResult1, "Passed at " + mTargetPlainMemory + " MB");
+ mTargetPlainMemory += 100;
+ mTestLoadNumber ++;
+
+ if ((mTestLoadNumber & 1) != 0) {
+ startSubActivity(MemoryAvailableLoad2.class, 5, 0);
+ } else {
+ startSubActivity(MemoryAvailableLoad1.class, 5, 0);
+ }
+ } else {
+ postTextToView(mTextResult1, "Failed at " + mTargetPlainMemory + " MB");
+ }
+ }
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/android/benchmark/MemoryAvailableLoad1.java b/app/src/main/java/com/android/benchmark/MemoryAvailableLoad1.java
new file mode 100644
index 0000000..6966d6e
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/MemoryAvailableLoad1.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+
+public class MemoryAvailableLoad1 extends Activity {
+ int mTargetPlainMemory;
+ int mTargetBitmaps;
+ int mTargetTextures;
+ int mTargetCompute;
+
+ native long nMemTestMalloc(int size);
+ native void nMemTestFree(long p);
+
+ static {
+ System.loadLibrary("nativeMemory");
+ }
+
+ long mLoadPtr = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_memory_available_load1);
+ android.util.Log.e("bench", "mal1 onCreate");
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ android.util.Log.e("bench", "mal1 onPause");
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ android.util.Log.e("bench", "mal1 onStart");
+ }
+
+ protected void onResume() {
+ String checkFilename = "MemoryAvailableLoad1.check";
+ super.onResume();
+ android.util.Log.e("bench", "mal1 onResume ");
+
+ Intent i = getIntent();
+ int reset = i.getIntExtra("reset", 0);
+ mTargetPlainMemory = i.getIntExtra("plain", 0);
+ mTargetBitmaps = i.getIntExtra("bitmaps", 0);
+ mTargetTextures = i.getIntExtra("textures", 0);
+ mTargetCompute = i.getIntExtra("compute", 0);
+
+ android.util.Log.e("bench", "mal1 plain " + mTargetPlainMemory);
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+
+ if ((reset == 0) && checkFileCheck(checkFilename)) {
+ // Failed to delete the file, assume crashed during alloc
+ finishTest(false);
+ } else {
+ if (checkFileCreate(checkFilename)) {
+ mLoadPtr = nMemTestMalloc(mTargetPlainMemory * 1024 * 1024);
+ }
+ }
+ checkFileDelete(checkFilename);
+
+ android.util.Log.e("bench", "mal1 alloc " );
+
+
+ final MemoryAvailableLoad1 mal = this;
+ final Handler handler = new Handler();
+ int delay = 5;
+
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ finishTest(true);
+ }
+ }, (1000 * delay));
+
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ android.util.Log.e("bench", "mal1 onRestart");
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ android.util.Log.e("bench", "mal1 onStop");
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ android.util.Log.e("bench", "mal1 onDestroy");
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+ }
+
+ @Override
+ public void onTrimMemory(int level) {
+
+ android.util.Log.e("bench", "mal1 on trim " + level);
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+ finishTest(false);
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+
+ android.util.Log.e("bench", "mal1 onSaveInstanceState");
+ //savedInstanceState.putBoolean("wasKilled", mFinished);
+
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ android.util.Log.e("bench", "mal1 onRestoreInstanceState");
+ //mFinished = savedInstanceState.getBoolean("wasKilled");
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_memory_available_load1, menu);
+ return true;
+ }
+
+ private void finishTest(boolean ok) {
+ android.util.Log.e("bench", "mal1 finishTest ok = " + ok);
+ if (ok) {
+ Intent intent = new Intent();
+ intent.putExtra("plain", mTargetPlainMemory);
+ intent.putExtra("bitmaps", mTargetBitmaps);
+ intent.putExtra("textures", mTargetTextures);
+ intent.putExtra("compute", mTargetCompute);
+ setResult(RESULT_OK, intent);
+ } else {
+ setResult(RESULT_CANCELED);
+ }
+ finish();
+ }
+
+ private boolean checkFileCreate(String filename) {
+ String string = "file ok";
+ FileOutputStream outputStream;
+
+ try {
+ outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
+ outputStream.write(string.getBytes());
+ outputStream.flush();
+ outputStream.close();
+ return true;
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean checkFileCheck(String filename) {
+ FileInputStream stream;
+
+ try {
+ stream = openFileInput(filename);
+ stream.close();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean checkFileDelete(String filename) {
+ return deleteFile(filename);
+ }
+
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/android/benchmark/MemoryAvailableLoad2.java b/app/src/main/java/com/android/benchmark/MemoryAvailableLoad2.java
new file mode 100644
index 0000000..6bcba36
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/MemoryAvailableLoad2.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+
+public class MemoryAvailableLoad2 extends Activity {
+ int mTargetPlainMemory;
+ int mTargetBitmaps;
+ int mTargetTextures;
+ int mTargetCompute;
+
+ native long nMemTestMalloc(int size);
+ native void nMemTestFree(long p);
+
+ static {
+ System.loadLibrary("nativeMemory");
+ }
+
+ long mLoadPtr = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_memory_available_load1);
+ android.util.Log.e("bench", "mal2 onCreate");
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ android.util.Log.e("bench", "mal2 onPause");
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ android.util.Log.e("bench", "mal2 onStart");
+ }
+
+ protected void onResume() {
+ String checkFilename = "MemoryAvailableLoad2.check";
+ super.onResume();
+ android.util.Log.e("bench", "mal2 onResume ");
+
+ Intent i = getIntent();
+ int reset = i.getIntExtra("reset", 0);
+ mTargetPlainMemory = i.getIntExtra("plain", 0);
+ mTargetBitmaps = i.getIntExtra("bitmaps", 0);
+ mTargetTextures = i.getIntExtra("textures", 0);
+ mTargetCompute = i.getIntExtra("compute", 0);
+
+ android.util.Log.e("bench", "mal2 plain " + mTargetPlainMemory);
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+
+ if ((reset == 0) && checkFileCheck(checkFilename)) {
+ // Failed to delete the file, assume crashed during alloc
+ finishTest(false);
+ } else {
+ if (checkFileCreate(checkFilename)) {
+ mLoadPtr = nMemTestMalloc(mTargetPlainMemory * 1024 * 1024);
+ }
+ }
+ checkFileDelete(checkFilename);
+
+ android.util.Log.e("bench", "mal2 alloc " );
+
+
+ final MemoryAvailableLoad2 mal = this;
+ final Handler handler = new Handler();
+ int delay = 5;
+
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ finishTest(true);
+ }
+ }, (1000 * delay));
+
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ android.util.Log.e("bench", "mal2 onRestart");
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ android.util.Log.e("bench", "mal2 onStop");
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ android.util.Log.e("bench", "mal2 onDestroy");
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+ }
+
+ @Override
+ public void onTrimMemory(int level) {
+
+ android.util.Log.e("bench", "mal2 on trim " + level);
+
+ if (mLoadPtr != 0) {
+ nMemTestFree(mLoadPtr);
+ mLoadPtr = 0;
+ }
+ finishTest(false);
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+
+ android.util.Log.e("bench", "mal2 onSaveInstanceState");
+ //savedInstanceState.putBoolean("wasKilled", mFinished);
+
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ android.util.Log.e("bench", "mal2 onRestoreInstanceState");
+ //mFinished = savedInstanceState.getBoolean("wasKilled");
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_memory_available_load1, menu);
+ return true;
+ }
+
+ private void finishTest(boolean ok) {
+ android.util.Log.e("bench", "mal2 finishTest ok = " + ok);
+ if (ok) {
+ Intent intent = new Intent();
+ intent.putExtra("plain", mTargetPlainMemory);
+ intent.putExtra("bitmaps", mTargetBitmaps);
+ intent.putExtra("textures", mTargetTextures);
+ intent.putExtra("compute", mTargetCompute);
+ setResult(RESULT_OK, intent);
+ } else {
+ setResult(RESULT_CANCELED);
+ }
+ finish();
+ }
+
+ private boolean checkFileCreate(String filename) {
+ String string = "file ok";
+ FileOutputStream outputStream;
+
+ try {
+ outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
+ outputStream.write(string.getBytes());
+ outputStream.flush();
+ outputStream.close();
+ return true;
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean checkFileCheck(String filename) {
+ FileInputStream stream;
+
+ try {
+ stream = openFileInput(filename);
+ stream.close();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean checkFileDelete(String filename) {
+ return deleteFile(filename);
+ }
+
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/android/benchmark/PerfTimeline.java b/app/src/main/java/com/android/benchmark/PerfTimeline.java
new file mode 100644
index 0000000..dd24ae1
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/PerfTimeline.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.*;
+import android.text.TextPaint;
+import android.util.AttributeSet;
+import android.view.View;
+
+
+/**
+ * TODO: document your custom view class.
+ */
+public class PerfTimeline extends View {
+ private String mExampleString; // TODO: use a default from R.string...
+ private int mExampleColor = Color.RED; // TODO: use a default from R.color...
+ private float mExampleDimension = 300; // TODO: use a default from R.dimen...
+
+ private TextPaint mTextPaint;
+ private float mTextWidth;
+ private float mTextHeight;
+
+ private Paint mPaintBaseLow;
+ private Paint mPaintBaseHigh;
+ private Paint mPaintValue;
+
+
+ public float[] mLinesLow;
+ public float[] mLinesHigh;
+ public float[] mLinesValue;
+
+ public PerfTimeline(Context context) {
+ super(context);
+ init(null, 0);
+ }
+
+ public PerfTimeline(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs, 0);
+ }
+
+ public PerfTimeline(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs, defStyle);
+ }
+
+ private void init(AttributeSet attrs, int defStyle) {
+ // Load attributes
+ final TypedArray a = getContext().obtainStyledAttributes(
+ attrs, R.styleable.PerfTimeline, defStyle, 0);
+
+ mExampleString = "xx";//a.getString(R.styleable.PerfTimeline_exampleString, "xx");
+ mExampleColor = a.getColor(R.styleable.PerfTimeline_exampleColor, mExampleColor);
+ // Use getDimensionPixelSize or getDimensionPixelOffset when dealing with
+ // values that should fall on pixel boundaries.
+ mExampleDimension = a.getDimension(
+ R.styleable.PerfTimeline_exampleDimension,
+ mExampleDimension);
+
+ a.recycle();
+
+ // Set up a default TextPaint object
+ mTextPaint = new TextPaint();
+ mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
+ mTextPaint.setTextAlign(Paint.Align.LEFT);
+
+ // Update TextPaint and text measurements from attributes
+ invalidateTextPaintAndMeasurements();
+
+
+
+
+
+ mPaintBaseLow = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaintBaseLow.setStyle(Paint.Style.FILL);
+ mPaintBaseLow.setColor(0xff000000);
+
+ mPaintBaseHigh = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaintBaseHigh.setStyle(Paint.Style.FILL);
+ mPaintBaseHigh.setColor(0x7f7f7f7f);
+
+ mPaintValue = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaintValue.setStyle(Paint.Style.FILL);
+ mPaintValue.setColor(0x7fff0000);
+
+ }
+
+ private void invalidateTextPaintAndMeasurements() {
+ mTextPaint.setTextSize(mExampleDimension);
+ mTextPaint.setColor(mExampleColor);
+ mTextWidth = mTextPaint.measureText(mExampleString);
+
+ Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
+ mTextHeight = fontMetrics.bottom;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ // TODO: consider storing these as member variables to reduce
+ // allocations per draw cycle.
+ int paddingLeft = getPaddingLeft();
+ int paddingTop = getPaddingTop();
+ int paddingRight = getPaddingRight();
+ int paddingBottom = getPaddingBottom();
+
+ int contentWidth = getWidth() - paddingLeft - paddingRight;
+ int contentHeight = getHeight() - paddingTop - paddingBottom;
+
+ // Draw the text.
+ //canvas.drawText(mExampleString,
+ // paddingLeft + (contentWidth - mTextWidth) / 2,
+ // paddingTop + (contentHeight + mTextHeight) / 2,
+ // mTextPaint);
+
+
+
+
+ // Draw the shadow
+ //RectF rf = new RectF(10.f, 10.f, 100.f, 100.f);
+ //canvas.drawOval(rf, mShadowPaint);
+
+ if (mLinesLow != null) {
+ canvas.drawLines(mLinesLow, mPaintBaseLow);
+ }
+ if (mLinesHigh != null) {
+ canvas.drawLines(mLinesHigh, mPaintBaseHigh);
+ }
+ if (mLinesValue != null) {
+ canvas.drawLines(mLinesValue, mPaintValue);
+ }
+
+
+/*
+ // Draw the pie slices
+ for (int i = 0; i < mData.size(); ++i) {
+ Item it = mData.get(i);
+ mPiePaint.setShader(it.mShader);
+ canvas.drawArc(mBounds,
+ 360 - it.mEndAngle,
+ it.mEndAngle - it.mStartAngle,
+ true, mPiePaint);
+ }
+*/
+ // Draw the pointer
+ //canvas.drawLine(mTextX, mPointerY, mPointerX, mPointerY, mTextPaint);
+ //canvas.drawCircle(mPointerX, mPointerY, mPointerSize, mTextPaint);
+ }
+
+ /**
+ * Gets the example string attribute value.
+ *
+ * @return The example string attribute value.
+ */
+ public String getExampleString() {
+ return mExampleString;
+ }
+
+ /**
+ * Sets the view's example string attribute value. In the example view, this string
+ * is the text to draw.
+ *
+ * @param exampleString The example string attribute value to use.
+ */
+ public void setExampleString(String exampleString) {
+ mExampleString = exampleString;
+ invalidateTextPaintAndMeasurements();
+ }
+
+ /**
+ * Gets the example color attribute value.
+ *
+ * @return The example color attribute value.
+ */
+ public int getExampleColor() {
+ return mExampleColor;
+ }
+
+ /**
+ * Sets the view's example color attribute value. In the example view, this color
+ * is the font color.
+ *
+ * @param exampleColor The example color attribute value to use.
+ */
+ public void setExampleColor(int exampleColor) {
+ mExampleColor = exampleColor;
+ invalidateTextPaintAndMeasurements();
+ }
+
+ /**
+ * Gets the example dimension attribute value.
+ *
+ * @return The example dimension attribute value.
+ */
+ public float getExampleDimension() {
+ return mExampleDimension;
+ }
+
+ /**
+ * Sets the view's example dimension attribute value. In the example view, this dimension
+ * is the font size.
+ *
+ * @param exampleDimension The example dimension attribute value to use.
+ */
+ public void setExampleDimension(float exampleDimension) {
+ mExampleDimension = exampleDimension;
+ invalidateTextPaintAndMeasurements();
+ }
+}
diff --git a/app/src/main/java/com/android/benchmark/TestInterface.java b/app/src/main/java/com/android/benchmark/TestInterface.java
new file mode 100644
index 0000000..b144d05
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/TestInterface.java
@@ -0,0 +1,383 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import java.util.Formatter;
+import java.util.LinkedList;
+import java.util.Queue;
+import android.os.Message;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.*;
+import android.os.Looper;
+import android.text.TextPaint;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+
+
+public class TestInterface {
+ native long nInit(long options);
+ native long nDestroy(long b);
+ native float nGetData(long b, float[] data);
+ native boolean nRunPowerManagementTest(long b, long options);
+ native boolean nRunCPUHeatSoakTest(long b, long options);
+
+ native boolean nMemTestStart(long b);
+ native float nMemTestBandwidth(long b, long size);
+ native float nMemTestLatency(long b, long size);
+ native void nMemTestEnd(long b);
+
+ float[] mLinesLow;
+ float[] mLinesHigh;
+ float[] mLinesValue;
+ TextView mTextStatus;
+ TextView mTextMin;
+ TextView mTextMax;
+ TextView mTextTypical;
+
+ private View mViewToUpdate;
+
+ private LooperThread mLT;
+
+
+
+ TestInterface(View v, int runtimeSeconds) {
+ int buckets = runtimeSeconds * 1000;
+ mLinesLow = new float[buckets * 4];
+ mLinesHigh = new float[buckets * 4];
+ mLinesValue = new float[buckets * 4];
+ mViewToUpdate = v;
+
+ mLT = new LooperThread(this);
+ mLT.start();
+ }
+
+
+ static class LooperThread extends Thread {
+ public static final int CommandExit = 1;
+ public static final int TestPowerManagement = 2;
+ public static final int TestMemoryBandwidth = 3;
+ public static final int TestMemoryLatency = 4;
+ public static final int TestHeatSoak = 5;
+
+ private boolean mRun = true;
+ private TestInterface mTI;
+
+ Queue<Integer> mCommandQueue = new LinkedList<Integer>();
+
+
+ LooperThread(TestInterface ti) {
+ super("BenchmarkTestThread");
+ mTI = ti;
+ }
+
+ void runCommand(int command) {
+ Integer i = new Integer(command);
+
+ synchronized (this) {
+ mCommandQueue.add(i);
+ notifyAll();
+ }
+ }
+
+ public void run() {
+ android.util.Log.e("bench", "run 0");
+ long b = mTI.nInit(0);
+ android.util.Log.e("bench", "run 0.1 " + b);
+ if (b == 0) {
+ return;
+ }
+
+ android.util.Log.e("bench", "run 1");
+ while (mRun) {
+ android.util.Log.e("bench", "run 2");
+ int command = 0;
+ synchronized (this) {
+ if (mCommandQueue.isEmpty()) {
+ try {
+ wait();
+ } catch (java.lang.InterruptedException e) {
+ }
+ }
+
+ if (!mCommandQueue.isEmpty()) {
+ command = mCommandQueue.remove();
+ }
+ }
+
+ android.util.Log.e("bench", "run 3 " + command);
+ switch (command) {
+ case CommandExit:
+ mRun = false;
+ break;
+ case TestPowerManagement:
+ mTI.testPowerManagement(b);
+ break;
+ case TestMemoryBandwidth:
+ mTI.testCPUMemoryBandwidth(b);
+ break;
+ case TestMemoryLatency:
+ mTI.testCPUMemoryLatency(b);
+ break;
+ case TestHeatSoak:
+ mTI.testCPUHeatSoak(b);
+ break;
+
+ }
+
+ android.util.Log.e("bench", "run 4");
+ //mViewToUpdate.post(new Runnable() {
+ // public void run() {
+ // mViewToUpdate.invalidate();
+ //}
+ //});
+
+
+ android.util.Log.e("bench", "run 5");
+
+ }
+
+
+
+ mTI.nDestroy(b);
+ }
+
+
+
+ }
+
+
+ void postTextToView(TextView v, String s) {
+ final TextView tv = v;
+ final String ts = s;
+
+ v.post(new Runnable() {
+ public void run() {
+ tv.setText(ts);
+ }
+ });
+
+ }
+
+ float calcAverage(float[] data) {
+ float total = 0.f;
+ for (int ct=0; ct < data.length; ct++) {
+ total += data[ct];
+ }
+ return total / data.length;
+ }
+
+ void makeGraph(float[] data, float[] lines) {
+ for (int ct = 0; ct < data.length; ct++) {
+ lines[ct * 4 + 0] = (float)ct;
+ lines[ct * 4 + 1] = 500.f - data[ct];
+ lines[ct * 4 + 2] = (float)ct;
+ lines[ct * 4 + 3] = 500.f;
+ }
+ }
+
+ void testPowerManagement(long b) {
+ float[] dat = new float[mLinesLow.length / 4];
+ postTextToView(mTextStatus, new String("Running single-threaded"));
+ nRunPowerManagementTest(b, 1);
+ nGetData(b, dat);
+ makeGraph(dat, mLinesLow);
+ mViewToUpdate.postInvalidate();
+ float avgMin = calcAverage(dat);
+ postTextToView(mTextMin, new String("Single threaded ") + avgMin + " per second");
+
+ postTextToView(mTextStatus, new String("Running multi-threaded"));
+ nRunPowerManagementTest(b, 4);
+ nGetData(b, dat);
+ makeGraph(dat, mLinesHigh);
+ mViewToUpdate.postInvalidate();
+ float avgMax = calcAverage(dat);
+ postTextToView(mTextMax, new String("Multi threaded ") + avgMax + " per second");
+
+ postTextToView(mTextStatus, new String("Running typical"));
+ nRunPowerManagementTest(b, 0);
+ nGetData(b, dat);
+ makeGraph(dat, mLinesValue);
+ mViewToUpdate.postInvalidate();
+ float avgTypical = calcAverage(dat);
+
+ float ofIdeal = avgTypical / (avgMax + avgMin) * 200.f;
+ postTextToView(mTextTypical, String.format("Typical mix (50/50) %%%2.0f of ideal", ofIdeal));
+
+ postTextToView(mTextStatus, new String("Done"));
+ }
+
+ void testCPUHeatSoak(long b) {
+ float[] dat = new float[1000];
+ postTextToView(mTextStatus, new String("Running heat soak test"));
+ for (int t = 0; t < 1000; t++) {
+ mLinesLow[t * 4 + 0] = (float)t;
+ mLinesLow[t * 4 + 1] = 498.f;
+ mLinesLow[t * 4 + 2] = (float)t;
+ mLinesLow[t * 4 + 3] = 500.f;
+ }
+
+ float peak = 0.f;
+ float total = 0.f;
+ for (int t = 0; t < 1000; t++) {
+ nRunCPUHeatSoakTest(b, 1);
+ nGetData(b, dat);
+
+ float p = calcAverage(dat);
+ mLinesLow[t * 4 + 1] = 499.f - p;
+ if (peak < p) {
+ peak = p;
+ }
+ total += p;
+
+ mViewToUpdate.postInvalidate();
+ postTextToView(mTextMin, new String("Peak ") + peak + " per second");
+ postTextToView(mTextMax, new String("Current ") + p + " per second");
+ postTextToView(mTextTypical, new String("Average ") + (total / (t + 1)) + " per second");
+ }
+
+ postTextToView(mTextStatus, new String("Done"));
+ }
+
+ void testCPUMemoryBandwidth(long b) {
+ int[] sizeK = {1, 2, 3, 4, 5, 6, 7,
+ 8, 10, 12, 14, 16, 20, 24, 28,
+ 32, 40, 48, 56, 64, 80, 96, 112,
+ 128, 160, 192, 224, 256, 320, 384, 448,
+ 512, 640, 768, 896, 1024, 1280, 1536, 1792,
+ 2048, 2560, 3584, 4096, 5120, 6144, 7168,
+ 8192, 10240, 12288, 14336, 16384
+ };
+ final int subSteps = 15;
+ float[] results = new float[sizeK.length * subSteps];
+
+ nMemTestStart(b);
+
+ float[] dat = new float[1000];
+ postTextToView(mTextStatus, new String("Running Memory Bandwidth test"));
+ for (int t = 0; t < 1000; t++) {
+ mLinesLow[t * 4 + 0] = (float)t;
+ mLinesLow[t * 4 + 1] = 498.f;
+ mLinesLow[t * 4 + 2] = (float)t;
+ mLinesLow[t * 4 + 3] = 500.f;
+ }
+
+ for (int i = 0; i < sizeK.length; i++) {
+ postTextToView(mTextStatus, new String("Running ") + sizeK[i] + " K");
+
+ float rtot = 0.f;
+ for (int j = 0; j < subSteps; j++) {
+ float ret = nMemTestBandwidth(b, sizeK[i] * 1024);
+ rtot += ret;
+ results[i * subSteps + j] = ret;
+ mLinesLow[(i * subSteps + j) * 4 + 1] = 499.f - (results[i*15+j] * 20.f);
+ //android.util.Log.e("bench", "test bw " + sizeK[i] + " - " + ret);
+ mViewToUpdate.postInvalidate();
+ }
+ rtot /= subSteps;
+
+ if (sizeK[i] == 2) {
+ postTextToView(mTextMin, new String("2K ") + rtot + " GB/s");
+ }
+ if (sizeK[i] == 128) {
+ postTextToView(mTextMax, new String("128K ") + rtot + " GB/s");
+ }
+ if (sizeK[i] == 8192) {
+ postTextToView(mTextTypical, new String("8M ") + rtot + " GB/s");
+ }
+
+ }
+
+ nMemTestEnd(b);
+ postTextToView(mTextStatus, new String("Done"));
+ }
+
+ void testCPUMemoryLatency(long b) {
+ int[] sizeK = {1, 2, 3, 4, 5, 6, 7,
+ 8, 10, 12, 14, 16, 20, 24, 28,
+ 32, 40, 48, 56, 64, 80, 96, 112,
+ 128, 160, 192, 224, 256, 320, 384, 448,
+ 512, 640, 768, 896, 1024, 1280, 1536, 1792,
+ 2048, 2560, 3584, 4096, 5120, 6144, 7168,
+ 8192, 10240, 12288, 14336, 16384
+ };
+ final int subSteps = 15;
+ float[] results = new float[sizeK.length * subSteps];
+
+ nMemTestStart(b);
+
+ float[] dat = new float[1000];
+ postTextToView(mTextStatus, new String("Running Memory Latency test"));
+ for (int t = 0; t < 1000; t++) {
+ mLinesLow[t * 4 + 0] = (float)t;
+ mLinesLow[t * 4 + 1] = 498.f;
+ mLinesLow[t * 4 + 2] = (float)t;
+ mLinesLow[t * 4 + 3] = 500.f;
+ }
+
+ for (int i = 0; i < sizeK.length; i++) {
+ postTextToView(mTextStatus, new String("Running ") + sizeK[i] + " K");
+
+ float rtot = 0.f;
+ for (int j = 0; j < subSteps; j++) {
+ float ret = nMemTestLatency(b, sizeK[i] * 1024);
+ rtot += ret;
+ results[i * subSteps + j] = ret;
+
+ if (ret > 400.f) ret = 400.f;
+ if (ret < 0.f) ret = 0.f;
+ mLinesLow[(i * subSteps + j) * 4 + 1] = 499.f - ret;
+ //android.util.Log.e("bench", "test bw " + sizeK[i] + " - " + ret);
+ mViewToUpdate.postInvalidate();
+ }
+ rtot /= subSteps;
+
+ if (sizeK[i] == 2) {
+ postTextToView(mTextMin, new String("2K ") + rtot + " ns");
+ }
+ if (sizeK[i] == 128) {
+ postTextToView(mTextMax, new String("128K ") + rtot + " ns");
+ }
+ if (sizeK[i] == 8192) {
+ postTextToView(mTextTypical, new String("8M ") + rtot + " ns");
+ }
+
+ }
+
+ nMemTestEnd(b);
+ postTextToView(mTextStatus, new String("Done"));
+ }
+
+
+ public void runPowerManagement() {
+ mLT.runCommand(mLT.TestPowerManagement);
+ }
+
+ public void runMemoryBandwidth() {
+ mLT.runCommand(mLT.TestMemoryBandwidth);
+ }
+
+ public void runMemoryLatency() {
+ mLT.runCommand(mLT.TestMemoryLatency);
+ }
+
+ public void runCPUHeatSoak() {
+ mLT.runCommand(mLT.TestHeatSoak);
+ }
+
+} \ No newline at end of file
diff --git a/app/src/main/java/com/android/benchmark/UI2D.java b/app/src/main/java/com/android/benchmark/UI2D.java
new file mode 100644
index 0000000..ca67c27
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/UI2D.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+
+public class UI2D extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_2d_ui);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_2d_ui, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/android/benchmark/UI2DTestTiles.java b/app/src/main/java/com/android/benchmark/UI2DTestTiles.java
new file mode 100644
index 0000000..5d91e28
--- /dev/null
+++ b/app/src/main/java/com/android/benchmark/UI2DTestTiles.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.benchmark;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+
+public class UI2DTestTiles extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_ui2_dtest_tiles);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_ui2_dtest_tiles, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}