1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 02:41:11 +01:00

Record Command: Updated record command

Updated the record command to allow revent recordings to be made.
They can be performed in 3 ways; the default is a standard recording
as in WA2, it can start a specified package before starting the
recording or a workload can be specified which launches the workload
and prompts the user to record each stage, naming and storing the recordings
appropriately.
This commit is contained in:
Marc Bonnici 2017-04-12 17:33:58 +01:00
parent 3ad0c67c63
commit 311ac1b803

View File

@ -15,23 +15,24 @@
import os
import sys
from time import sleep
from wa import Command, settings
from wa import Command
from wa.framework import pluginloader
from wa.framework.agenda import Agenda
from wa.framework.resource import Executable, NO_ONE, ResourceResolver
from wa.framework.configuration import RunConfiguration
from wa.framework.workload import ApkUiautoWorkload
from wa.framework.resource import ResourceResolver
from wa.framework.target.manager import TargetManager
from wa.utils.revent import ReventRecorder
class RecordCommand(Command):
name = 'record'
description = '''Performs a revent recording
description = '''
Performs a revent recording
This command helps making revent recordings. It will automatically
deploy revent and even has the option of automatically opening apps.
deploy revent and has options to automatically open apps and record
specified stages of a workload.
Revent allows you to record raw inputs such as screen swipes or button presses.
This can be useful for recording inputs for workloads such as games that don't
@ -45,10 +46,18 @@ class RecordCommand(Command):
it can be automatically determined. On Android device it will be obtained
from ``build.prop``, on Linux devices it is obtained from ``/proc/device-tree/model``.
- suffix is used by WA to determine which part of the app execution the
recording is for, currently these are either ``setup`` or ``run``. This
should be specified with the ``-s`` argument.
recording is for, currently these are either ``setup``, ``run``, ``extract_results``
or ``teardown``. All stages except ``run`` are optional and these should
be specified with the ``-s``, ``-e`` or ``-t`` arguments respectively,
or optionally ``-a`` to indicate all stages should be recorded.
'''
def __init__(self, **kwargs):
super(RecordCommand, self).__init__(**kwargs)
self.tm = None
self.target = None
self.revent_recorder = None
def initialize(self, context):
self.parser.add_argument('-d', '--device', metavar='DEVICE',
help='''
@ -56,39 +65,152 @@ class RecordCommand(Command):
take precedence over the device (if any)
specified in configuration.
''')
self.parser.add_argument('-o', '--output', help='Specify the output file', metavar='FILE')
self.parser.add_argument('-s', '--setup', help='Record a recording for setup stage',
action='store_true')
self.parser.add_argument('-e', '--extract_results', help='Record a recording for extract_results stage',
action='store_true')
self.parser.add_argument('-t', '--teardown', help='Record a recording for teardown stage',
action='store_true')
self.parser.add_argument('-a', '--all', help='Record recordings for available stages',
action='store_true')
def execute(state, args):
# Need validation
self.parser.add_argument('-C', '--clear', help='Clear app cache before launching it',
action='store_true')
group = self.parser.add_mutually_exclusive_group(required=False)
group.add_argument('-p', '--package', help='Package to launch before recording')
group.add_argument('-w', '--workload', help='Name of a revent workload (mostly games)')
def validate_args(self, args):
if args.clear and not (args.package or args.workload):
self.logger.error("Package/Workload must be specified if you want to clear cache")
sys.exit()
if args.workload and args.output:
self.logger.error("Output file cannot be specified with Workload")
sys.exit()
if not args.workload and (args.setup or args.extract_results or
args.teardown or args.all):
self.logger.error("Cannot specify a recording stage without a Workload")
sys.exit()
def execute(self, state, args):
self.validate_args(args)
if args.device:
device = args.device
device = args.device
device_config = {}
else:
device = state.run_config.device
device_config = state.run_config.device_config
target_manager = TargetManager(device, device_config)
device_config = state.run_config.device_config or {}
self.tm = TargetManager(device, device_config)
self.target = self.tm.target
self.revent_recorder = ReventRecorder(self.target)
self.revent_recorder.deploy()
def get_revent_binary(abi):
resolver = ResourceResolver()
resource = Executable(NO_ONE, abi, 'revent')
return resolver.get(resource)
if args.workload:
self.workload_record(args)
elif args.package:
self.package_record(args)
else:
self.manual_record(args)
self.revent_recorder.remove()
class ReventRecorder(object):
def record(self, revent_file, name, output_path):
msg = 'Press Enter when you are ready to record {}...'
self.logger.info(msg.format(name))
raw_input('')
self.revent_recorder.start_record(revent_file)
msg = 'Press Enter when you have finished recording {}...'
self.logger.info(msg.format(name))
raw_input('')
self.revent_recorder.stop_record()
def __init__(self, target):
self.target = target
self.executable = None
self.deploy()
if not os.path.isdir(output_path):
os.makedirs(output_path)
def deploy(self):
host_executable = get_revent_binary(self.target.abi)
self.executable = self.target.install(host_executable)
revent_file_name = self.target.path.basename(revent_file)
host_path = os.path.join(output_path, revent_file_name)
if os.path.exists(host_path):
msg = 'Revent file \'{}\' already exists, overwrite? [y/n]'
self.logger.info(msg.format(revent_file_name))
if raw_input('') == 'y':
os.remove(host_path)
else:
msg = 'Did not pull and overwrite \'{}\''
self.logger.warning(msg.format(revent_file_name))
return
msg = 'Pulling \'{}\' from device'
self.logger.info(msg.format(self.target.path.basename(revent_file)))
self.target.pull(revent_file, output_path, as_root=self.target.is_rooted)
def record(self, path):
name = os.path.basename(path)
target_path = self.target.get_workpath(name)
command = '{} record {}'
def manual_record(self, args):
output_path, file_name = self._split_revent_location(args.output)
revent_file = self.target.get_workpath(file_name)
self.record(revent_file, '', output_path)
msg = 'Recording is available at: \'{}\''
self.logger.info(msg.format(os.path.join(output_path, file_name)))
def remove(self):
if self.executable:
self.target.uninstall('revent')
def package_record(self, args):
if args.clear:
self.target.execute('pm clear {}'.format(args.package))
self.logger.info('Starting {}'.format(args.package))
cmd = 'monkey -p {} -c android.intent.category.LAUNCHER 1'
self.target.execute(cmd.format(args.package))
output_path, file_name = self._split_revent_location(args.output)
revent_file = self.target.get_workpath(file_name)
self.record(revent_file, '', output_path)
msg = 'Recording is available at: \'{}\''
self.logger.info(msg.format(os.path.join(output_path, file_name)))
def workload_record(self, args):
context = LightContext(self.tm)
setup_revent = '{}.setup.revent'.format(self.target.model)
run_revent = '{}.run.revent'.format(self.target.model)
extract_results_revent = '{}.extract_results.revent'.format(self.target.model)
teardown_file_revent = '{}.teardown.revent'.format(self.target.model)
setup_file = self.target.get_workpath(setup_revent)
run_file = self.target.get_workpath(run_revent)
extract_results_file = self.target.get_workpath(extract_results_revent)
teardown_file = self.target.get_workpath(teardown_file_revent)
self.logger.info('Deploying {}'.format(args.workload))
workload = pluginloader.get_workload(args.workload, self.target)
workload.apk.init_resources(context.resolver)
workload.apk.setup(context)
sleep(workload.loading_time)
output_path = os.path.join(workload.dependencies_directory,
'revent_files')
if args.setup or args.all:
self.record(setup_file, 'SETUP', output_path)
self.record(run_file, 'RUN', output_path)
if args.extract_results or args.all:
self.record(extract_results_file, 'EXTRACT_RESULTS', output_path)
if args.teardown or args.all:
self.record(teardown_file, 'TEARDOWN', output_path)
self.logger.info('Tearing down {}'.format(args.workload))
workload.teardown(context)
self.logger.info('Recording(s) are available at: \'{}\''.format(output_path))
def _split_revent_location(self, output):
output_path = None
file_name = None
if output:
output_path, file_name, = os.path.split(output)
if not file_name:
file_name = '{}.revent'.format(self.target.model)
if not output_path:
output_path = os.getcwdu()
return output_path, file_name
# Used to satisfy the workload API
class LightContext(object):
def __init__(self, tm):
self.tm = tm
self.resolver = ResourceResolver()
self.resolver.load()