blob: 723c46089d51adb800f75f058bf0441d7ae78a96 [file] [log] [blame]
Dianne Hackbornd4c4b762011-10-27 12:58:16 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.frameworkperf;
18
19import android.app.Activity;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080020import android.content.ComponentName;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070021import android.content.Intent;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080022import android.content.ServiceConnection;
Mohamad Ayyashc508d032014-08-25 19:27:57 -070023import android.graphics.Color;
Dianne Hackborndd137932011-11-08 10:59:28 -080024import android.os.Binder;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070025import android.os.Bundle;
26import android.os.Handler;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080027import android.os.IBinder;
28import android.os.Message;
29import android.os.Messenger;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070030import android.os.PowerManager;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080031import android.os.RemoteException;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070032import android.util.Log;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070033import android.view.View;
34import android.view.WindowManager;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070035import android.widget.AdapterView;
36import android.widget.ArrayAdapter;
Dianne Hackborn28695e02011-11-02 21:59:51 -070037import android.widget.Button;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080038import android.widget.CheckBox;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070039import android.widget.Spinner;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070040import android.widget.TextView;
41
42import java.util.ArrayList;
43
44/**
45 * So you thought sync used up your battery life.
46 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070047public class FrameworkPerfActivity extends Activity
48 implements AdapterView.OnItemSelectedListener {
Dianne Hackborn2e9562a2011-10-28 17:12:12 -070049 static final String TAG = "Perf";
Dianne Hackborndd137932011-11-08 10:59:28 -080050 static final boolean DEBUG = false;
Dianne Hackborn2e9562a2011-10-28 17:12:12 -070051
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070052 Spinner mFgSpinner;
53 Spinner mBgSpinner;
Christopher Tate80a682b2011-11-18 17:14:14 -080054 Spinner mLimitSpinner;
55 TextView mLimitLabel;
Dianne Hackborn0500b3c2011-11-01 15:28:43 -070056 TextView mTestTime;
Dianne Hackborn28695e02011-11-02 21:59:51 -070057 Button mStartButton;
58 Button mStopButton;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080059 CheckBox mLocalCheckBox;
Dianne Hackborn28695e02011-11-02 21:59:51 -070060 TextView mLog;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070061 PowerManager.WakeLock mPartialWakeLock;
62
63 long mMaxRunTime = 5000;
Christopher Tate80a682b2011-11-18 17:14:14 -080064 boolean mLimitIsIterations;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070065 boolean mStarted;
66
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070067 final String[] mAvailOpLabels;
68 final String[] mAvailOpDescriptions;
Christopher Tate80a682b2011-11-18 17:14:14 -080069 final String[] mLimitLabels = { "Time", "Iterations" };
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070070
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080071 int mFgTestIndex = -1;
72 int mBgTestIndex = -1;
73 TestService.Op mFgTest;
74 TestService.Op mBgTest;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070075 int mCurOpIndex = 0;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080076 TestConnection mCurConnection;
Dianne Hackborndd137932011-11-08 10:59:28 -080077 boolean mConnectionBound;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -070078
79 final ArrayList<RunResult> mResults = new ArrayList<RunResult>();
80
Guang Zhu5eefd772011-11-17 14:32:41 -080081 Object mResultNotifier = new Object();
82
Dianne Hackborndd137932011-11-08 10:59:28 -080083 class TestConnection implements ServiceConnection, IBinder.DeathRecipient {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080084 Messenger mService;
Dianne Hackborndd137932011-11-08 10:59:28 -080085 boolean mLinked;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -080086
87 @Override public void onServiceConnected(ComponentName name, IBinder service) {
Dianne Hackborndd137932011-11-08 10:59:28 -080088 try {
89 if (!(service instanceof Binder)) {
90 // If remote, we'll be killing ye.
91 service.linkToDeath(this, 0);
92 mLinked = true;
93 }
94 mService = new Messenger(service);
95 dispatchCurOp(this);
96 } catch (RemoteException e) {
97 // Whoops, service has disappeared... try starting again.
98 Log.w(TAG, "Test service died, starting again");
99 startCurOp();
100 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800101 }
102
103 @Override public void onServiceDisconnected(ComponentName name) {
104 }
Dianne Hackborndd137932011-11-08 10:59:28 -0800105
106 @Override public void binderDied() {
107 cleanup();
108 connectionDied(this);
109 }
110
111 void cleanup() {
112 if (mLinked) {
113 mLinked = false;
114 mService.getBinder().unlinkToDeath(this, 0);
115 }
116 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800117 }
118
Dianne Hackborndd137932011-11-08 10:59:28 -0800119 static final int MSG_DO_NEXT_TEST = 1000;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800120
121 final Handler mHandler = new Handler() {
122 @Override public void handleMessage(Message msg) {
123 switch (msg.what) {
124 case TestService.RES_TEST_FINISHED: {
125 Bundle bundle = (Bundle)msg.obj;
126 bundle.setClassLoader(getClassLoader());
127 RunResult res = (RunResult)bundle.getParcelable("res");
128 completeCurOp(res);
129 } break;
Dianne Hackborndd137932011-11-08 10:59:28 -0800130 case MSG_DO_NEXT_TEST: {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800131 startCurOp();
132 } break;
133 }
134 }
135 };
136
137 final Messenger mMessenger = new Messenger(mHandler);
138
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700139 public FrameworkPerfActivity() {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800140 mAvailOpLabels = new String[TestService.mAvailOps.length];
141 mAvailOpDescriptions = new String[TestService.mAvailOps.length];
142 for (int i=0; i<TestService.mAvailOps.length; i++) {
143 TestService.Op op = TestService.mAvailOps[i];
Dianne Hackborn0500b3c2011-11-01 15:28:43 -0700144 if (op == null) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700145 mAvailOpLabels[i] = "All";
146 mAvailOpDescriptions[i] = "All tests";
147 } else {
148 mAvailOpLabels[i] = op.getName();
Dianne Hackborn0500b3c2011-11-01 15:28:43 -0700149 if (mAvailOpLabels[i] == null) {
150 mAvailOpLabels[i] = "Nothing";
151 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700152 mAvailOpDescriptions[i] = op.getLongName();
153 }
154 }
155 }
156
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700157 @Override
158 public void onCreate(Bundle savedInstanceState) {
159 super.onCreate(savedInstanceState);
160
161 // Set the layout for this activity. You can find it
162 // in res/layout/hello_activity.xml
163 setContentView(R.layout.main);
164
Alan Viverette51efddb2017-04-05 10:00:01 -0400165 mFgSpinner = findViewById(R.id.fgspinner);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700166 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
167 android.R.layout.simple_spinner_item, mAvailOpLabels);
168 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
169 mFgSpinner.setAdapter(adapter);
170 mFgSpinner.setOnItemSelectedListener(this);
Alan Viverette51efddb2017-04-05 10:00:01 -0400171 mBgSpinner = findViewById(R.id.bgspinner);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700172 adapter = new ArrayAdapter<String>(this,
173 android.R.layout.simple_spinner_item, mAvailOpLabels);
174 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
175 mBgSpinner.setAdapter(adapter);
176 mBgSpinner.setOnItemSelectedListener(this);
Alan Viverette51efddb2017-04-05 10:00:01 -0400177 mLimitSpinner = findViewById(R.id.limitspinner);
Christopher Tate80a682b2011-11-18 17:14:14 -0800178 adapter = new ArrayAdapter<String>(this,
179 android.R.layout.simple_spinner_item, mLimitLabels);
180 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
181 mLimitSpinner.setAdapter(adapter);
182 mLimitSpinner.setOnItemSelectedListener(this);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700183
Dianne Hackborn28695e02011-11-02 21:59:51 -0700184 mTestTime = (TextView)findViewById(R.id.testtime);
Christopher Tate80a682b2011-11-18 17:14:14 -0800185 mLimitLabel = (TextView)findViewById(R.id.limitlabel);
Dianne Hackborn28695e02011-11-02 21:59:51 -0700186
187 mStartButton = (Button)findViewById(R.id.start);
188 mStartButton.setOnClickListener(new View.OnClickListener() {
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700189 @Override public void onClick(View v) {
190 startRunning();
191 }
192 });
Dianne Hackborn28695e02011-11-02 21:59:51 -0700193 mStopButton = (Button)findViewById(R.id.stop);
194 mStopButton.setOnClickListener(new View.OnClickListener() {
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700195 @Override public void onClick(View v) {
196 stopRunning();
197 }
198 });
Dianne Hackborn28695e02011-11-02 21:59:51 -0700199 mStopButton.setEnabled(false);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800200 mLocalCheckBox = (CheckBox)findViewById(R.id.local);
Dianne Hackborn28695e02011-11-02 21:59:51 -0700201
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700202 mLog = (TextView)findViewById(R.id.log);
Mohamad Ayyashc508d032014-08-25 19:27:57 -0700203 mLog.setTextColor(Color.RED);
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700204
205 PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
206 mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Scheduler");
207 mPartialWakeLock.setReferenceCounted(false);
208 }
209
210 @Override
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700211 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Christopher Tate80a682b2011-11-18 17:14:14 -0800212 if (parent == mFgSpinner || parent == mBgSpinner || parent == mLimitSpinner) {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800213 TestService.Op op = TestService.mAvailOps[position];
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700214 if (parent == mFgSpinner) {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800215 mFgTestIndex = position;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700216 mFgTest = op;
217 ((TextView)findViewById(R.id.fgtext)).setText(mAvailOpDescriptions[position]);
Christopher Tate80a682b2011-11-18 17:14:14 -0800218 } else if (parent == mBgSpinner) {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800219 mBgTestIndex = position;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700220 mBgTest = op;
221 ((TextView)findViewById(R.id.bgtext)).setText(mAvailOpDescriptions[position]);
Christopher Tate80a682b2011-11-18 17:14:14 -0800222 } else if (parent == mLimitSpinner) {
223 mLimitIsIterations = (position != 0);
224 if (mLimitIsIterations) {
225 mLimitLabel.setText("Iterations: ");
226 } else {
227 mLimitLabel.setText("Test time (ms): ");
228 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700229 }
230 }
231 }
232
233 @Override
234 public void onNothingSelected(AdapterView<?> parent) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700235 }
236
237 @Override
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700238 public void onResume() {
239 super.onResume();
240 }
241
242 @Override
243 public void onDestroy() {
244 super.onDestroy();
245 stopRunning();
246 if (mPartialWakeLock.isHeld()) {
247 mPartialWakeLock.release();
248 }
249 }
250
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800251 void dispatchCurOp(TestConnection conn) {
252 if (mCurConnection != conn) {
253 Log.w(TAG, "Dispatching on invalid connection: " + conn);
254 return;
255 }
256 TestArgs args = new TestArgs();
Christopher Tate80a682b2011-11-18 17:14:14 -0800257 if (mLimitIsIterations) {
258 args.maxOps = mMaxRunTime;
259 } else {
260 args.maxTime = mMaxRunTime;
261 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800262 if (mFgTestIndex == 0 && mBgTestIndex == 0) {
263 args.combOp = mCurOpIndex;
264 } else if (mFgTestIndex != 0 && mBgTestIndex != 0) {
265 args.fgOp = mFgTestIndex;
266 args.bgOp = mBgTestIndex;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700267 } else {
Dianne Hackborn28695e02011-11-02 21:59:51 -0700268 // Skip null test.
269 if (mCurOpIndex == 0) {
270 mCurOpIndex = 1;
271 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800272 if (mFgTestIndex != 0) {
273 args.fgOp = mFgTestIndex;
274 args.bgOp = mCurOpIndex;
275 } else {
276 args.fgOp = mCurOpIndex;
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800277 args.bgOp = mBgTestIndex;
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700278 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800279 }
280 Bundle bundle = new Bundle();
281 bundle.putParcelable("args", args);
282 Message msg = Message.obtain(null, TestService.CMD_START_TEST, bundle);
283 msg.replyTo = mMessenger;
284 try {
285 conn.mService.send(msg);
286 } catch (RemoteException e) {
Dianne Hackborndd137932011-11-08 10:59:28 -0800287 Log.w(TAG, "Failure communicating with service", e);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800288 }
289 }
290
291 void completeCurOp(RunResult result) {
292 log(String.format("%s: fg=%d*%gms/op (%dms) / bg=%d*%gms/op (%dms)",
293 result.name, result.fgOps, result.getFgMsPerOp(), result.fgTime,
294 result.bgOps, result.getBgMsPerOp(), result.bgTime));
Guang Zhu5eefd772011-11-17 14:32:41 -0800295 synchronized (mResults) {
296 mResults.add(result);
297 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800298 if (!mStarted) {
299 log("Stop");
300 stopRunning();
301 return;
302 }
303 if (mFgTest != null && mBgTest != null) {
304 log("Finished");
305 stopRunning();
306 return;
307 }
308 if (mFgTest == null && mBgTest == null) {
309 mCurOpIndex+=2;
310 if (mCurOpIndex >= TestService.mOpPairs.length) {
311 log("Finished");
312 stopRunning();
313 return;
314 }
315 } else {
316 mCurOpIndex++;
317 if (mCurOpIndex >= TestService.mAvailOps.length) {
318 log("Finished");
319 stopRunning();
320 return;
321 }
322 }
323 startCurOp();
324 }
325
326 void disconnect() {
Dianne Hackborndd137932011-11-08 10:59:28 -0800327 final TestConnection conn = mCurConnection;
328 if (conn != null) {
329 if (DEBUG) {
330 RuntimeException here = new RuntimeException("here");
331 here.fillInStackTrace();
332 Log.i(TAG, "Unbinding " + conn, here);
333 }
334 if (mConnectionBound) {
335 unbindService(conn);
336 mConnectionBound = false;
337 }
338 if (conn.mLinked) {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800339 Message msg = Message.obtain(null, TestService.CMD_TERMINATE);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800340 try {
Dianne Hackborndd137932011-11-08 10:59:28 -0800341 conn.mService.send(msg);
342 return;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800343 } catch (RemoteException e) {
Dianne Hackborndd137932011-11-08 10:59:28 -0800344 Log.w(TAG, "Test service aleady died when terminating");
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800345 }
346 }
Dianne Hackborndd137932011-11-08 10:59:28 -0800347 conn.cleanup();
348 }
349 connectionDied(conn);
350 }
351
352 void connectionDied(TestConnection conn) {
353 if (mCurConnection == conn) {
354 // Now that we know the test process has died, we can commence
355 // the next test. Just give a little delay to allow the activity
356 // manager to know it has died as well (not a disaster if it hasn't
357 // yet, though).
358 if (mConnectionBound) {
359 unbindService(conn);
360 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800361 mCurConnection = null;
Dianne Hackborndd137932011-11-08 10:59:28 -0800362 mHandler.sendMessageDelayed(Message.obtain(null, MSG_DO_NEXT_TEST), 100);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800363 }
364 }
365
366 void startCurOp() {
Dianne Hackborndd137932011-11-08 10:59:28 -0800367 if (DEBUG) Log.i(TAG, "startCurOp: mCurConnection=" + mCurConnection);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800368 if (mCurConnection != null) {
369 disconnect();
Dianne Hackborndd137932011-11-08 10:59:28 -0800370 return;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800371 }
372 if (mStarted) {
373 mHandler.removeMessages(TestService.RES_TEST_FINISHED);
374 mHandler.removeMessages(TestService.RES_TERMINATED);
Dianne Hackborndd137932011-11-08 10:59:28 -0800375 mHandler.removeMessages(MSG_DO_NEXT_TEST);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800376 mCurConnection = new TestConnection();
377 Intent intent;
378 if (mLocalCheckBox.isChecked()) {
379 intent = new Intent(this, LocalTestService.class);
380 } else {
381 intent = new Intent(this, TestService.class);
382 }
Dianne Hackborndd137932011-11-08 10:59:28 -0800383 if (DEBUG) {
384 RuntimeException here = new RuntimeException("here");
385 here.fillInStackTrace();
386 Log.i(TAG, "Binding " + mCurConnection, here);
387 }
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800388 bindService(intent, mCurConnection, BIND_AUTO_CREATE|BIND_IMPORTANT);
Dianne Hackborndd137932011-11-08 10:59:28 -0800389 mConnectionBound = true;
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800390 }
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700391 }
392
393 void startRunning() {
394 if (!mStarted) {
395 log("Start");
396 mStarted = true;
Dianne Hackborn28695e02011-11-02 21:59:51 -0700397 mStartButton.setEnabled(false);
398 mStopButton.setEnabled(true);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800399 mLocalCheckBox.setEnabled(false);
Dianne Hackborn28695e02011-11-02 21:59:51 -0700400 mTestTime.setEnabled(false);
401 mFgSpinner.setEnabled(false);
402 mBgSpinner.setEnabled(false);
Christopher Tate80a682b2011-11-18 17:14:14 -0800403 mLimitSpinner.setEnabled(false);
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700404 updateWakeLock();
405 startService(new Intent(this, SchedulerService.class));
406 mCurOpIndex = 0;
Dianne Hackborn0500b3c2011-11-01 15:28:43 -0700407 mMaxRunTime = Integer.parseInt(mTestTime.getText().toString());
Guang Zhu5eefd772011-11-17 14:32:41 -0800408 synchronized (mResults) {
409 mResults.clear();
410 }
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700411 startCurOp();
412 }
413 }
414
415 void stopRunning() {
416 if (mStarted) {
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800417 disconnect();
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700418 mStarted = false;
Dianne Hackborn28695e02011-11-02 21:59:51 -0700419 mStartButton.setEnabled(true);
420 mStopButton.setEnabled(false);
Dianne Hackborn6b57b7e2011-11-07 14:45:49 -0800421 mLocalCheckBox.setEnabled(true);
Dianne Hackborn28695e02011-11-02 21:59:51 -0700422 mTestTime.setEnabled(true);
423 mFgSpinner.setEnabled(true);
424 mBgSpinner.setEnabled(true);
Christopher Tate80a682b2011-11-18 17:14:14 -0800425 mLimitSpinner.setEnabled(true);
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700426 updateWakeLock();
427 stopService(new Intent(this, SchedulerService.class));
Guang Zhu5eefd772011-11-17 14:32:41 -0800428 synchronized (mResults) {
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800429 Log.i("PerfRes", "\tTEST\tFgOps\tFgMsPerOp\tFgTime\tFgName\tBgOps\tBgMsPerOp\t"
430 + "BgTime\tBgName");
Guang Zhu5eefd772011-11-17 14:32:41 -0800431 for (int i=0; i<mResults.size(); i++) {
432 RunResult result = mResults.get(i);
433 float fgMsPerOp = result.getFgMsPerOp();
434 float bgMsPerOp = result.getBgMsPerOp();
435 String fgMsPerOpStr = fgMsPerOp != 0 ? Float.toString(fgMsPerOp) : "";
436 String bgMsPerOpStr = bgMsPerOp != 0 ? Float.toString(bgMsPerOp) : "";
437 Log.i("PerfRes", "\t" + result.name + "\t" + result.fgOps
438 + "\t" + result.getFgMsPerOp() + "\t" + result.fgTime
439 + "\t" + result.fgLongName + "\t" + result.bgOps
440 + "\t" + result.getBgMsPerOp() + "\t" + result.bgTime
441 + "\t" + result.bgLongName);
442 }
443 }
444 synchronized (mResultNotifier) {
445 mResultNotifier.notifyAll();
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700446 }
447 }
448 }
449
450 void updateWakeLock() {
451 if (mStarted) {
452 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
453 if (!mPartialWakeLock.isHeld()) {
454 mPartialWakeLock.acquire();
455 }
456 } else {
457 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
458 if (mPartialWakeLock.isHeld()) {
459 mPartialWakeLock.release();
460 }
461 }
462 }
463
464 void log(String s) {
465 mLog.setText(mLog.getText() + "\n" + s);
Dianne Hackborn2e9562a2011-10-28 17:12:12 -0700466 Log.i(TAG, s);
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700467 }
Dianne Hackbornd4c4b762011-10-27 12:58:16 -0700468}