2018-03-23 15:01:56 +00:00
|
|
|
# Copyright 2014-2018 ARM Limited
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from wa import Command
|
|
|
|
from wa import discover_wa_outputs
|
2020-01-17 09:54:10 +00:00
|
|
|
from wa.framework.configuration.core import Status
|
2018-03-23 15:01:56 +00:00
|
|
|
from wa.framework.exception import CommandError
|
|
|
|
from wa.framework.output import RunOutput
|
|
|
|
from wa.framework.output_processor import ProcessorManager
|
2018-05-11 15:19:17 +01:00
|
|
|
from wa.utils import log
|
2018-03-23 15:01:56 +00:00
|
|
|
|
2018-05-11 15:34:08 +01:00
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
class ProcessContext(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.run_output = None
|
|
|
|
self.target_info = None
|
|
|
|
self.job_output = None
|
|
|
|
|
2018-07-25 11:25:44 +01:00
|
|
|
def add_augmentation(self, aug):
|
|
|
|
pass
|
|
|
|
|
2018-05-11 15:34:08 +01:00
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
class ProcessCommand(Command):
|
|
|
|
|
|
|
|
name = 'process'
|
|
|
|
description = 'Process the output from previously run workloads.'
|
|
|
|
|
|
|
|
def initialize(self, context):
|
|
|
|
self.parser.add_argument('directory', metavar='DIR',
|
|
|
|
help="""
|
|
|
|
Specify a directory containing the data
|
|
|
|
from a previous run to be processed.
|
|
|
|
""")
|
|
|
|
self.parser.add_argument('-p', '--processor', action='append',
|
|
|
|
dest='additional_processors', metavar='OutputProcessor',
|
|
|
|
help="""
|
|
|
|
Specify an output processor to add from the
|
|
|
|
command line. This can be used to run a
|
|
|
|
processor that is not normally used without
|
2018-07-03 14:30:04 +01:00
|
|
|
introducing permanent change to the config
|
2018-03-23 15:01:56 +00:00
|
|
|
(which one might then forget to revert). This
|
|
|
|
option may be specified multiple times.
|
|
|
|
""")
|
|
|
|
self.parser.add_argument('-f', '--force', action='store_true',
|
|
|
|
help="""
|
2020-01-17 09:54:10 +00:00
|
|
|
Run processors that have already been run. By
|
|
|
|
default these will be skipped. Also, forces
|
|
|
|
processing of in-progress runs.
|
2018-03-23 15:01:56 +00:00
|
|
|
""")
|
|
|
|
self.parser.add_argument('-r', '--recursive', action='store_true',
|
|
|
|
help="""
|
|
|
|
Walk the specified directory to process
|
|
|
|
all of the previous runs contained within
|
|
|
|
instead of just processing the root.
|
|
|
|
""")
|
|
|
|
|
2018-07-09 15:28:22 +01:00
|
|
|
def execute(self, config, args): # pylint: disable=arguments-differ,too-many-branches,too-many-statements
|
2018-03-23 15:01:56 +00:00
|
|
|
process_directory = os.path.expandvars(args.directory)
|
|
|
|
self.logger.debug('Using process directory: {}'.format(process_directory))
|
|
|
|
if not os.path.exists(process_directory):
|
|
|
|
msg = 'Path `{}` does not exist, please specify a valid path.'
|
|
|
|
raise CommandError(msg.format(process_directory))
|
|
|
|
if not args.recursive:
|
|
|
|
output_list = [RunOutput(process_directory)]
|
|
|
|
else:
|
|
|
|
output_list = [output for output in discover_wa_outputs(process_directory)]
|
2018-05-11 15:19:17 +01:00
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
pc = ProcessContext()
|
|
|
|
for run_output in output_list:
|
2020-01-17 09:54:10 +00:00
|
|
|
if run_output.status < Status.OK and not args.force:
|
|
|
|
msg = 'Skipping {} as it has not completed -- {}'
|
|
|
|
self.logger.info(msg.format(run_output.basepath, run_output.status))
|
|
|
|
continue
|
|
|
|
|
2018-11-19 09:59:13 +00:00
|
|
|
pc.run_output = run_output
|
|
|
|
pc.target_info = run_output.target_info
|
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
if not args.recursive:
|
|
|
|
self.logger.info('Installing output processors')
|
|
|
|
else:
|
|
|
|
self.logger.info('Install output processors for run in path `{}`'
|
|
|
|
.format(run_output.basepath))
|
2018-05-11 15:19:17 +01:00
|
|
|
|
|
|
|
logfile = os.path.join(run_output.basepath, 'process.log')
|
|
|
|
i = 0
|
|
|
|
while os.path.exists(logfile):
|
|
|
|
i += 1
|
|
|
|
logfile = os.path.join(run_output.basepath, 'process-{}.log'.format(i))
|
|
|
|
log.add_file(logfile)
|
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
pm = ProcessorManager(loader=config.plugin_cache)
|
|
|
|
for proc in config.get_processors():
|
2018-07-25 11:25:44 +01:00
|
|
|
pm.install(proc, pc)
|
2018-03-23 15:01:56 +00:00
|
|
|
if args.additional_processors:
|
|
|
|
for proc in args.additional_processors:
|
|
|
|
# Do not add any processors that are already present since
|
|
|
|
# duplicate entries do not get disabled.
|
|
|
|
try:
|
|
|
|
pm.get_output_processor(proc)
|
|
|
|
except ValueError:
|
2018-07-25 11:25:44 +01:00
|
|
|
pm.install(proc, pc)
|
2018-05-11 15:19:17 +01:00
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
pm.validate()
|
2018-09-04 17:18:25 +01:00
|
|
|
pm.initialize(pc)
|
2018-05-11 15:19:17 +01:00
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
for job_output in run_output.jobs:
|
2020-01-17 09:54:10 +00:00
|
|
|
if job_output.status < Status.OK or job_output.status in [Status.SKIPPED, Status.ABORTED]:
|
|
|
|
msg = 'Skipping job {} {} iteration {} -- {}'
|
|
|
|
self.logger.info(msg.format(job_output.id, job_output.label,
|
|
|
|
job_output.iteration, job_output.status))
|
|
|
|
continue
|
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
pc.job_output = job_output
|
|
|
|
pm.enable_all()
|
|
|
|
if not args.force:
|
|
|
|
for augmentation in job_output.spec.augmentations:
|
|
|
|
try:
|
|
|
|
pm.disable(augmentation)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2018-05-11 15:19:17 +01:00
|
|
|
|
|
|
|
msg = 'Processing job {} {} iteration {}'
|
|
|
|
self.logger.info(msg.format(job_output.id, job_output.label,
|
|
|
|
job_output.iteration))
|
2018-03-23 15:01:56 +00:00
|
|
|
pm.process_job_output(pc)
|
|
|
|
pm.export_job_output(pc)
|
2018-05-11 15:19:17 +01:00
|
|
|
|
2018-06-14 17:38:03 +01:00
|
|
|
job_output.write_result()
|
|
|
|
|
2018-03-23 15:01:56 +00:00
|
|
|
pm.enable_all()
|
|
|
|
if not args.force:
|
|
|
|
for augmentation in run_output.augmentations:
|
|
|
|
try:
|
|
|
|
pm.disable(augmentation)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2018-05-11 15:19:17 +01:00
|
|
|
|
|
|
|
self.logger.info('Processing run')
|
2018-03-23 15:01:56 +00:00
|
|
|
pm.process_run_output(pc)
|
|
|
|
pm.export_run_output(pc)
|
2018-09-04 17:18:25 +01:00
|
|
|
pm.finalize(pc)
|
2018-05-11 15:19:17 +01:00
|
|
|
|
2020-01-17 09:54:10 +00:00
|
|
|
run_output.write_info()
|
2018-05-11 15:34:08 +01:00
|
|
|
run_output.write_result()
|
2018-05-11 15:19:17 +01:00
|
|
|
self.logger.info('Done.')
|