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

wa/instruments: Refactor collectors to use Collector Inferface

Update the WA instruments which rely on the refactored devlib collectors
to reflect the new API.
This commit is contained in:
Marc Bonnici 2019-12-03 16:46:26 +00:00
parent d67668621c
commit 817d98ed72
5 changed files with 46 additions and 41 deletions

View File

@ -19,7 +19,7 @@ import csv
import os import os
import re import re
from devlib.trace.perf import PerfCollector from devlib.collector.perf import PerfCollector
from wa import Instrument, Parameter from wa import Instrument, Parameter
from wa.utils.types import list_or_string, list_of_strs, numeric from wa.utils.types import list_or_string, list_of_strs, numeric
@ -109,6 +109,7 @@ class PerfInstrument(Instrument):
def __init__(self, target, **kwargs): def __init__(self, target, **kwargs):
super(PerfInstrument, self).__init__(target, **kwargs) super(PerfInstrument, self).__init__(target, **kwargs)
self.collector = None self.collector = None
self.outdir = None
def initialize(self, context): def initialize(self, context):
self.collector = PerfCollector(self.target, self.collector = PerfCollector(self.target,
@ -121,6 +122,8 @@ class PerfInstrument(Instrument):
self.force_install) self.force_install)
def setup(self, context): def setup(self, context):
self.outdir = os.path.join(context.output_directory, self.perf_type)
self.collector.set_output(outdir)
self.collector.reset() self.collector.reset()
def start(self, context): def start(self, context):
@ -131,33 +134,32 @@ class PerfInstrument(Instrument):
def update_output(self, context): def update_output(self, context):
self.logger.info('Extracting reports from target...') self.logger.info('Extracting reports from target...')
outdir = os.path.join(context.output_directory, self.perf_type) self.collector.get_data()
self.collector.get_trace(outdir)
if self.perf_type == 'perf': if self.perf_type == 'perf':
self._process_perf_output(context, outdir) self._process_perf_output(context)
else: else:
self._process_simpleperf_output(context, outdir) self._process_simpleperf_output(context)
def teardown(self, context): def teardown(self, context):
self.collector.reset() self.collector.reset()
def _process_perf_output(self, context, outdir): def _process_perf_output(self, context):
if self.command == 'stat': if self.command == 'stat':
self._process_perf_stat_output(context, outdir) self._process_perf_stat_output(context)
elif self.command == 'record': elif self.command == 'record':
self._process_perf_record_output(context, outdir) self._process_perf_record_output(context)
def _process_simpleperf_output(self, context, outdir): def _process_simpleperf_output(self, context):
if self.command == 'stat': if self.command == 'stat':
self._process_simpleperf_stat_output(context, outdir) self._process_simpleperf_stat_output(context)
elif self.command == 'record': elif self.command == 'record':
self._process_simpleperf_record_output(context, outdir) self._process_simpleperf_record_output(context)
def _process_perf_stat_output(self, context, outdir): def _process_perf_stat_output(self, context):
for host_file in os.listdir(outdir): for host_file in os.listdir(self.outdir):
label = host_file.split('.out')[0] label = host_file.split('.out')[0]
host_file_path = os.path.join(outdir, host_file) host_file_path = os.path.join(self.outdir, host_file)
context.add_artifact(label, host_file_path, 'raw') context.add_artifact(label, host_file_path, 'raw')
with open(host_file_path) as fh: with open(host_file_path) as fh:
in_results_section = False in_results_section = False
@ -187,15 +189,15 @@ class PerfInstrument(Instrument):
metric = '{}_{}'.format(label, match.group(3)) metric = '{}_{}'.format(label, match.group(3))
context.add_metric(metric, count, classifiers=classifiers) context.add_metric(metric, count, classifiers=classifiers)
def _process_perf_record_output(self, context, outdir): def _process_perf_record_output(self, context):
for host_file in os.listdir(outdir): for host_file in os.listdir(self.outdir):
label, ext = os.path.splitext(host_file) label, ext = os.path.splitext(host_file)
context.add_artifact(label, os.path.join(outdir, host_file), 'raw') context.add_artifact(label, os.path.join(self.outdir, host_file), 'raw')
column_headers = [] column_headers = []
column_header_indeces = [] column_header_indeces = []
event_type = '' event_type = ''
if ext == '.rpt': if ext == '.rpt':
with open(os.path.join(outdir, host_file)) as fh: with open(os.path.join(self.outdir, host_file)) as fh:
for line in fh: for line in fh:
words = line.split() words = line.split()
if not words: if not words:
@ -221,12 +223,12 @@ class PerfInstrument(Instrument):
event_type = event_type.strip("'") event_type = event_type.strip("'")
return event_type return event_type
def _process_simpleperf_stat_output(self, context, outdir): def _process_simpleperf_stat_output(self, context):
labels = [] labels = []
for host_file in os.listdir(outdir): for host_file in os.listdir(self.outdir):
labels.append(host_file.split('.out')[0]) labels.append(host_file.split('.out')[0])
for opts, label in zip(self.optionstring, labels): for opts, label in zip(self.optionstring, labels):
stat_file = os.path.join(outdir, '{}{}'.format(label, '.out')) stat_file = os.path.join(self.outdir, '{}{}'.format(label, '.out'))
if '--csv' in opts: if '--csv' in opts:
self._process_simpleperf_stat_from_csv(stat_file, context, label) self._process_simpleperf_stat_from_csv(stat_file, context, label)
else: else:
@ -257,16 +259,16 @@ class PerfInstrument(Instrument):
metric = '{}_{}'.format(label, metric) metric = '{}_{}'.format(label, metric)
context.add_metric(metric, count, 'count', classifiers={'scaled from(%)': scaled_percentage}) context.add_metric(metric, count, 'count', classifiers={'scaled from(%)': scaled_percentage})
def _process_simpleperf_record_output(self, context, outdir): def _process_simpleperf_record_output(self, context):
for host_file in os.listdir(outdir): for host_file in os.listdir(self.outdir):
label, ext = os.path.splitext(host_file) label, ext = os.path.splitext(host_file)
context.add_artifact(label, os.path.join(outdir, host_file), 'raw') context.add_artifact(label, os.path.join(self.outdir, host_file), 'raw')
if ext != '.rpt': if ext != '.rpt':
continue continue
column_headers = [] column_headers = []
column_header_indeces = [] column_header_indeces = []
event_type = '' event_type = ''
with open(os.path.join(outdir, host_file)) as fh: with open(os.path.join(self.outdir, host_file)) as fh:
for line in fh: for line in fh:
words = line.split() words = line.split()
if not words: if not words:

View File

@ -15,7 +15,7 @@
import os import os
from devlib.trace.screencapture import ScreenCaptureCollector from devlib.collector.screencapture import ScreenCaptureCollector
from wa import Instrument, Parameter from wa import Instrument, Parameter
@ -47,8 +47,9 @@ class ScreenCaptureInstrument(Instrument):
output_path = os.path.join(context.output_directory, "screen-capture") output_path = os.path.join(context.output_directory, "screen-capture")
os.mkdir(output_path) os.mkdir(output_path)
self.collector = ScreenCaptureCollector(self.target, self.collector = ScreenCaptureCollector(self.target,
output_path,
self.period) self.period)
self.collector.set_output(output_path)
self.collector.reset()
def start(self, context): # pylint: disable=unused-argument def start(self, context): # pylint: disable=unused-argument
self.collector.start() self.collector.start()

View File

@ -47,35 +47,36 @@ class SerialMon(Instrument):
def __init__(self, target, **kwargs): def __init__(self, target, **kwargs):
super(SerialMon, self).__init__(target, **kwargs) super(SerialMon, self).__init__(target, **kwargs)
self._collector = SerialTraceCollector(target, self.serial_port, self.baudrate) self._collector = SerialTraceCollector(target, self.serial_port, self.baudrate)
self._collector.reset()
def start_logging(self, context): def start_logging(self, context, filename="serial.log"):
outpath = os.path.join(context.output_directory, filename)
self._collector.set_output(outpath)
self._collector.reset()
self.logger.debug("Acquiring serial port ({})".format(self.serial_port)) self.logger.debug("Acquiring serial port ({})".format(self.serial_port))
if self._collector.collecting: if self._collector.collecting:
self.stop_logging(context) self.stop_logging(context)
self._collector.start() self._collector.start()
def stop_logging(self, context, filename="serial.log", identifier="job"): def stop_logging(self, context, identifier="job"):
self.logger.debug("Releasing serial port ({})".format(self.serial_port)) self.logger.debug("Releasing serial port ({})".format(self.serial_port))
if self._collector.collecting: if self._collector.collecting:
self._collector.stop() self._collector.stop()
data = self._collector.get_data()
outpath = os.path.join(context.output_directory, filename) for l in data:
self._collector.get_trace(outpath) context.add_artifact("{}_serial_log".format(identifier),
context.add_artifact("{}_serial_log".format(identifier), l.path, kind="log")
outpath, kind="log")
def on_run_start(self, context): def on_run_start(self, context):
self.start_logging(context) self.start_logging(context, "preamble_serial.log")
def before_job_queue_execution(self, context): def before_job_queue_execution(self, context):
self.stop_logging(context, "preamble_serial.log", "preamble") self.stop_logging(context, "preamble")
def after_job_queue_execution(self, context): def after_job_queue_execution(self, context):
self.start_logging(context) self.start_logging(context, "postamble_serial.log")
def on_run_end(self, context): def on_run_end(self, context):
self.stop_logging(context, "postamble_serial.log", "postamble") self.stop_logging(context, "postamble")
def on_job_start(self, context): def on_job_start(self, context):
self.start_logging(context) self.start_logging(context)

View File

@ -203,7 +203,8 @@ class TraceCmdInstrument(Instrument):
def update_output(self, context): # NOQA pylint: disable=R0912 def update_output(self, context): # NOQA pylint: disable=R0912
self.logger.info('Extracting trace from target...') self.logger.info('Extracting trace from target...')
outfile = os.path.join(context.output_directory, 'trace.dat') outfile = os.path.join(context.output_directory, 'trace.dat')
self.collector.get_trace(outfile) self.collector.set_output(outfile)
self.collector.get_data()
context.add_artifact('trace-cmd-bin', outfile, 'data') context.add_artifact('trace-cmd-bin', outfile, 'data')
if self.report: if self.report:
textfile = os.path.join(context.output_directory, 'trace.txt') textfile = os.path.join(context.output_directory, 'trace.txt')

View File

@ -17,7 +17,7 @@ import re
import logging import logging
from itertools import chain from itertools import chain
from devlib.trace.ftrace import TRACE_MARKER_START, TRACE_MARKER_STOP from devlib.collector.ftrace import TRACE_MARKER_START, TRACE_MARKER_STOP
from wa.utils.misc import isiterable from wa.utils.misc import isiterable
from wa.utils.types import numeric from wa.utils.types import numeric