mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00: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:
parent
d67668621c
commit
817d98ed72
@ -19,7 +19,7 @@ import csv
|
||||
import os
|
||||
import re
|
||||
|
||||
from devlib.trace.perf import PerfCollector
|
||||
from devlib.collector.perf import PerfCollector
|
||||
|
||||
from wa import Instrument, Parameter
|
||||
from wa.utils.types import list_or_string, list_of_strs, numeric
|
||||
@ -109,6 +109,7 @@ class PerfInstrument(Instrument):
|
||||
def __init__(self, target, **kwargs):
|
||||
super(PerfInstrument, self).__init__(target, **kwargs)
|
||||
self.collector = None
|
||||
self.outdir = None
|
||||
|
||||
def initialize(self, context):
|
||||
self.collector = PerfCollector(self.target,
|
||||
@ -121,6 +122,8 @@ class PerfInstrument(Instrument):
|
||||
self.force_install)
|
||||
|
||||
def setup(self, context):
|
||||
self.outdir = os.path.join(context.output_directory, self.perf_type)
|
||||
self.collector.set_output(outdir)
|
||||
self.collector.reset()
|
||||
|
||||
def start(self, context):
|
||||
@ -131,33 +134,32 @@ class PerfInstrument(Instrument):
|
||||
|
||||
def update_output(self, context):
|
||||
self.logger.info('Extracting reports from target...')
|
||||
outdir = os.path.join(context.output_directory, self.perf_type)
|
||||
self.collector.get_trace(outdir)
|
||||
self.collector.get_data()
|
||||
|
||||
if self.perf_type == 'perf':
|
||||
self._process_perf_output(context, outdir)
|
||||
self._process_perf_output(context)
|
||||
else:
|
||||
self._process_simpleperf_output(context, outdir)
|
||||
self._process_simpleperf_output(context)
|
||||
|
||||
def teardown(self, context):
|
||||
self.collector.reset()
|
||||
|
||||
def _process_perf_output(self, context, outdir):
|
||||
def _process_perf_output(self, context):
|
||||
if self.command == 'stat':
|
||||
self._process_perf_stat_output(context, outdir)
|
||||
self._process_perf_stat_output(context)
|
||||
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':
|
||||
self._process_simpleperf_stat_output(context, outdir)
|
||||
self._process_simpleperf_stat_output(context)
|
||||
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):
|
||||
for host_file in os.listdir(outdir):
|
||||
def _process_perf_stat_output(self, context):
|
||||
for host_file in os.listdir(self.outdir):
|
||||
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')
|
||||
with open(host_file_path) as fh:
|
||||
in_results_section = False
|
||||
@ -187,15 +189,15 @@ class PerfInstrument(Instrument):
|
||||
metric = '{}_{}'.format(label, match.group(3))
|
||||
context.add_metric(metric, count, classifiers=classifiers)
|
||||
|
||||
def _process_perf_record_output(self, context, outdir):
|
||||
for host_file in os.listdir(outdir):
|
||||
def _process_perf_record_output(self, context):
|
||||
for host_file in os.listdir(self.outdir):
|
||||
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_header_indeces = []
|
||||
event_type = ''
|
||||
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:
|
||||
words = line.split()
|
||||
if not words:
|
||||
@ -221,12 +223,12 @@ class PerfInstrument(Instrument):
|
||||
event_type = event_type.strip("'")
|
||||
return event_type
|
||||
|
||||
def _process_simpleperf_stat_output(self, context, outdir):
|
||||
def _process_simpleperf_stat_output(self, context):
|
||||
labels = []
|
||||
for host_file in os.listdir(outdir):
|
||||
for host_file in os.listdir(self.outdir):
|
||||
labels.append(host_file.split('.out')[0])
|
||||
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:
|
||||
self._process_simpleperf_stat_from_csv(stat_file, context, label)
|
||||
else:
|
||||
@ -257,16 +259,16 @@ class PerfInstrument(Instrument):
|
||||
metric = '{}_{}'.format(label, metric)
|
||||
context.add_metric(metric, count, 'count', classifiers={'scaled from(%)': scaled_percentage})
|
||||
|
||||
def _process_simpleperf_record_output(self, context, outdir):
|
||||
for host_file in os.listdir(outdir):
|
||||
def _process_simpleperf_record_output(self, context):
|
||||
for host_file in os.listdir(self.outdir):
|
||||
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':
|
||||
continue
|
||||
column_headers = []
|
||||
column_header_indeces = []
|
||||
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:
|
||||
words = line.split()
|
||||
if not words:
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from devlib.trace.screencapture import ScreenCaptureCollector
|
||||
from devlib.collector.screencapture import ScreenCaptureCollector
|
||||
|
||||
from wa import Instrument, Parameter
|
||||
|
||||
@ -47,8 +47,9 @@ class ScreenCaptureInstrument(Instrument):
|
||||
output_path = os.path.join(context.output_directory, "screen-capture")
|
||||
os.mkdir(output_path)
|
||||
self.collector = ScreenCaptureCollector(self.target,
|
||||
output_path,
|
||||
self.period)
|
||||
self.collector.set_output(output_path)
|
||||
self.collector.reset()
|
||||
|
||||
def start(self, context): # pylint: disable=unused-argument
|
||||
self.collector.start()
|
||||
|
@ -47,35 +47,36 @@ class SerialMon(Instrument):
|
||||
def __init__(self, target, **kwargs):
|
||||
super(SerialMon, self).__init__(target, **kwargs)
|
||||
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))
|
||||
if self._collector.collecting:
|
||||
self.stop_logging(context)
|
||||
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))
|
||||
if self._collector.collecting:
|
||||
self._collector.stop()
|
||||
|
||||
outpath = os.path.join(context.output_directory, filename)
|
||||
self._collector.get_trace(outpath)
|
||||
context.add_artifact("{}_serial_log".format(identifier),
|
||||
outpath, kind="log")
|
||||
data = self._collector.get_data()
|
||||
for l in data:
|
||||
context.add_artifact("{}_serial_log".format(identifier),
|
||||
l.path, kind="log")
|
||||
|
||||
def on_run_start(self, context):
|
||||
self.start_logging(context)
|
||||
self.start_logging(context, "preamble_serial.log")
|
||||
|
||||
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):
|
||||
self.start_logging(context)
|
||||
self.start_logging(context, "postamble_serial.log")
|
||||
|
||||
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):
|
||||
self.start_logging(context)
|
||||
|
@ -203,7 +203,8 @@ class TraceCmdInstrument(Instrument):
|
||||
def update_output(self, context): # NOQA pylint: disable=R0912
|
||||
self.logger.info('Extracting trace from target...')
|
||||
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')
|
||||
if self.report:
|
||||
textfile = os.path.join(context.output_directory, 'trace.txt')
|
||||
|
@ -17,7 +17,7 @@ import re
|
||||
import logging
|
||||
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.types import numeric
|
||||
|
Loading…
Reference in New Issue
Block a user