1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-04-21 10:10:46 +01:00

Add basic instrumentation for call times

- Also, extend UxPerfUiAutomation instead of BaseUiAutomation
This commit is contained in:
muendelezaji 2016-05-03 16:59:46 +01:00
parent 055da519d2
commit 915023dfd7
3 changed files with 84 additions and 19 deletions
wlauto/workloads/skypeecho

@ -13,6 +13,8 @@
# limitations under the License.
#
import os
import re
import time
from wlauto import AndroidUiAutoBenchmark, Parameter
@ -33,6 +35,8 @@ class SkypeEcho(AndroidUiAutoBenchmark):
# Skype has no default 'main' activity
launch_main = False # overrides extended class
instrumentation_log = '{}_instrumentation.log'.format(name)
parameters = [
# Workload parameters go here e.g.
# Parameter('example_parameter', kind=int, allowed_values=[1,2,3], default=1, override=True, mandatory=False,
@ -57,6 +61,8 @@ class SkypeEcho(AndroidUiAutoBenchmark):
def __init__(self, device, **kwargs):
super(SkypeEcho, self).__init__(device, **kwargs)
self.output_file = os.path.join(self.device.working_directory, self.instrumentation_log)
self.uiauto_params['results_file'] = self.output_file
if self.use_gui:
self.uiauto_params['my_id'] = self.login_name
self.uiauto_params['my_pwd'] = self.login_pass
@ -89,12 +95,33 @@ class SkypeEcho(AndroidUiAutoBenchmark):
self.device.execute('am force-stop {}'.format(self.package))
def update_result(self, context):
pass
# super(SkypeEcho, self).update_result(context)
self.logger.info('===== update_result() ======')
super(SkypeEcho, self).update_result(context)
# if not self.dumpsys_enabled:
# return
self.device.pull_file(self.output_file, context.output_directory)
results_file = os.path.join(context.output_directory, self.instrumentation_log)
# process results and add them using
# context.result.add_metric
with open(results_file, 'r') as lines:
pattern = r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)'
regex = re.compile(pattern)
for line in lines:
match = regex.search(line)
if match:
context.result.add_metric((match.group('key') + "_start"), match.group('value1'))
context.result.add_metric((match.group('key') + "_finish"), match.group('value2'))
context.result.add_metric((match.group('key') + "_duration"), match.group('value3'))
def teardown(self, context):
self.logger.info('===== teardown() ======')
super(SkypeEcho, self).teardown(context)
# Pull log files
for entry in self.device.listdir(self.device.working_directory):
if entry.startswith(self.name) and entry.endswith(".log"):
self.device.pull_file(os.path.join(self.device.working_directory, entry),
context.output_directory)
self.device.delete_file(os.path.join(self.device.working_directory, entry))
# self.device.execute('am force-stop {}'.format(self.package))

@ -1,6 +1,11 @@
package com.arm.wlauto.uiauto.skypeecho;
import java.lang.Runnable;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import android.app.Activity;
import android.os.Bundle;
@ -16,9 +21,9 @@ import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.arm.wlauto.uiauto.BaseUiAutomation;
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
public class UiAutomation extends BaseUiAutomation {
public class UiAutomation extends UxPerfUiAutomation {
public static String TAG = "uxperf_skypeecho";
@ -30,7 +35,10 @@ public class UiAutomation extends BaseUiAutomation {
public static String endCallButtonResourceId = "com.skype.raider:id/call_end_button";
public static String noContactMessage = "Could not find contact \"%s\" in the contacts list.";
private Map<String, Timer> results = new HashMap<String, Timer>();
public void runUiAutomation() throws Exception {
// Get Params
Bundle parameters = getParams();
String loginName = parameters.getString("my_id");
String loginPass = parameters.getString("my_pwd");
@ -38,10 +46,36 @@ public class UiAutomation extends BaseUiAutomation {
String contactName = parameters.getString("name").replace("_", " ");
int callDuration = Integer.parseInt(parameters.getString("duration"));
boolean isVideo = "video".equals(parameters.getString("action"));
String resultsFile = parameters.getString("results_file");
// Run tests
Timer overallTimer = new Timer();
Timer callTimer = new Timer();
overallTimer.start();
handleLoginScreen(loginName, loginPass);
selectContact(contactName, contactSkypeid);
callTimer.start();
makeCall(callDuration, isVideo);
callTimer.end();
overallTimer.end();
// Save results
results.put("call_test", callTimer);
results.put("overall_test", overallTimer);
saveResults(results, resultsFile);
}
private void saveResults(Map<String, Timer> results, String file) throws Exception {
BufferedWriter out = new BufferedWriter(new FileWriter(file));
long start, finish, duration;
for (Map.Entry<String, Timer> entry : results.entrySet()) {
Timer timer = entry.getValue();
start = timer.getStart();
finish = timer.getFinish();
duration = timer.getDuration();
out.write(entry.getKey() + " " + start + " " + finish + " " + duration + "\n");
}
out.close();
}
public void selectContact(String name, String id) throws Exception {
@ -68,22 +102,26 @@ public class UiAutomation extends BaseUiAutomation {
UiObject callButton = new UiObject(new UiSelector().descriptionContains(description));
callButton.click();
sleep(duration);
// TODO Needs to be run on UI thread after sleep
/*
final UiObject endButton = getUiObjectByResourceId(endCallButtonResourceId, "android.widget.ImageView");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
try {
endButton.click();
} catch (UiObjectNotFoundException e) {
// Do nothing
}
}
}, 10000);
*/
// endCall();g
}
/*
// TODO Needs to be run on UI thread after sleep
public void endCall() {
final UiObject endButton = getUiObjectByResourceId(endCallButtonResourceId, "android.widget.ImageView");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
try {
endButton.click();
} catch (UiObjectNotFoundException e) {
// Do nothing
}
}
}, 10000);
}
*/
public void handleLoginScreen(String username, String password) throws Exception {
String useridResoureId = "com.skype.raider:id/sign_in_userid";
String nextButtonResourceId = "com.skype.raider:id/sign_in_next_btn";