From 19887de71ed0c0a601c72fb6825d0306ea4c3aee Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 7 Nov 2019 11:18:18 +0000 Subject: [PATCH] devlib/trace: Refactor `trace` to be `collector` We now have have multiple `trace` instruments that do not match the description and therefore are moved to have a more suitably named hierarchy. --- devlib/__init__.py | 8 ++++---- devlib/{trace => collector}/__init__.py | 2 +- devlib/{trace => collector}/dmesg.py | 4 ++-- devlib/{trace => collector}/ftrace.py | 4 ++-- devlib/{trace => collector}/logcat.py | 4 ++-- devlib/{trace => collector}/perf.py | 12 ++++++------ devlib/{trace => collector}/screencapture.py | 4 ++-- devlib/{trace => collector}/serial_trace.py | 4 ++-- devlib/{trace => collector}/systrace.py | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) rename devlib/{trace => collector}/__init__.py (97%) rename devlib/{trace => collector}/dmesg.py (98%) rename devlib/{trace => collector}/ftrace.py (99%) rename devlib/{trace => collector}/logcat.py (96%) rename devlib/{trace => collector}/perf.py (98%) rename devlib/{trace => collector}/screencapture.py (97%) rename devlib/{trace => collector}/serial_trace.py (97%) rename devlib/{trace => collector}/systrace.py (98%) diff --git a/devlib/__init__.py b/devlib/__init__.py index ec42a30..b59c42c 100644 --- a/devlib/__init__.py +++ b/devlib/__init__.py @@ -45,10 +45,10 @@ from devlib.derived import DerivedMeasurements, DerivedMetric from devlib.derived.energy import DerivedEnergyMeasurements from devlib.derived.fps import DerivedGfxInfoStats, DerivedSurfaceFlingerStats -from devlib.trace.ftrace import FtraceCollector -from devlib.trace.perf import PerfCollector -from devlib.trace.serial_trace import SerialTraceCollector -from devlib.trace.dmesg import DmesgCollector +from devlib.collector.ftrace import FtraceCollector +from devlib.collector.perf import PerfCollector +from devlib.collector.serial_trace import SerialTraceCollector +from devlib.collector.dmesg import DmesgCollector from devlib.host import LocalConnection from devlib.utils.android import AdbConnection diff --git a/devlib/trace/__init__.py b/devlib/collector/__init__.py similarity index 97% rename from devlib/trace/__init__.py rename to devlib/collector/__init__.py index 0922037..773c185 100644 --- a/devlib/trace/__init__.py +++ b/devlib/collector/__init__.py @@ -16,7 +16,7 @@ import logging -class TraceCollector(object): +class CollectorBase(object): def __init__(self, target): self.target = target diff --git a/devlib/trace/dmesg.py b/devlib/collector/dmesg.py similarity index 98% rename from devlib/trace/dmesg.py rename to devlib/collector/dmesg.py index 66b0b78..16166e5 100644 --- a/devlib/trace/dmesg.py +++ b/devlib/collector/dmesg.py @@ -18,7 +18,7 @@ import re from itertools import takewhile from datetime import timedelta -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase class KernelLogEntry(object): @@ -121,7 +121,7 @@ class KernelLogEntry(object): ) -class DmesgCollector(TraceCollector): +class DmesgCollector(CollectorBase): """ Dmesg output collector. diff --git a/devlib/trace/ftrace.py b/devlib/collector/ftrace.py similarity index 99% rename from devlib/trace/ftrace.py rename to devlib/collector/ftrace.py index b36f10f..b6e9181 100644 --- a/devlib/trace/ftrace.py +++ b/devlib/collector/ftrace.py @@ -23,7 +23,7 @@ import sys import contextlib from pipes import quote -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase from devlib.host import PACKAGE_BIN_DIRECTORY from devlib.exception import TargetStableError, HostError from devlib.utils.misc import check_output, which, memoized @@ -50,7 +50,7 @@ TIMEOUT = 180 CPU_RE = re.compile(r' Function \(CPU([0-9]+)\)') STATS_RE = re.compile(r'([^ ]*) +([0-9]+) +([0-9.]+) us +([0-9.]+) us +([0-9.]+) us') -class FtraceCollector(TraceCollector): +class FtraceCollector(CollectorBase): # pylint: disable=too-many-locals,too-many-branches,too-many-statements def __init__(self, target, diff --git a/devlib/trace/logcat.py b/devlib/collector/logcat.py similarity index 96% rename from devlib/trace/logcat.py rename to devlib/collector/logcat.py index 432b57a..ccc9e9a 100644 --- a/devlib/trace/logcat.py +++ b/devlib/collector/logcat.py @@ -16,10 +16,10 @@ import os import shutil -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase from devlib.utils.android import LogcatMonitor -class LogcatCollector(TraceCollector): +class LogcatCollector(CollectorBase): def __init__(self, target, regexps=None): super(LogcatCollector, self).__init__(target) diff --git a/devlib/trace/perf.py b/devlib/collector/perf.py similarity index 98% rename from devlib/trace/perf.py rename to devlib/collector/perf.py index d3209a5..0b83f52 100644 --- a/devlib/trace/perf.py +++ b/devlib/collector/perf.py @@ -19,13 +19,13 @@ import time from past.builtins import basestring, zip from devlib.host import PACKAGE_BIN_DIRECTORY -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase from devlib.utils.misc import ensure_file_directory_exists as _f PERF_COMMAND_TEMPLATE = '{binary} {command} {options} {events} sleep 1000 > {outfile} 2>&1 ' PERF_REPORT_COMMAND_TEMPLATE= '{binary} report {options} -i {datafile} > {outfile} 2>&1 ' -PERF_RECORD_COMMAND_TEMPLATE= '{binary} record {options} {events} -o {outfile}' +PERF_RECORD_COMMAND_TEMPLATE= '{binary} record {options} {events} -o {outfile}' PERF_DEFAULT_EVENTS = [ 'cpu-migrations', @@ -42,7 +42,7 @@ SIMPLEPERF_DEFAULT_EVENTS = [ DEFAULT_EVENTS = {'perf':PERF_DEFAULT_EVENTS, 'simpleperf':SIMPLEPERF_DEFAULT_EVENTS} -class PerfCollector(TraceCollector): +class PerfCollector(CollectorBase): """ Perf is a Linux profiling with performance counters. Simpleperf is an Android profiling tool with performance counters. @@ -82,7 +82,7 @@ class PerfCollector(TraceCollector): man perf-stat """ - def __init__(self, + def __init__(self, target, perf_type='perf', command='stat', @@ -216,7 +216,7 @@ class PerfCollector(TraceCollector): current_tries += 1 else: if current_tries >= max_tries: - self.logger.warning('''writing {}.data file took longer than expected, + self.logger.warning('''writing {}.data file took longer than expected, file may not have written correctly'''.format(label)) data_file_finished_writing = True report_command = self._build_perf_report_command(self.report_options, label) @@ -229,7 +229,7 @@ class PerfCollector(TraceCollector): if available_event == '': continue if 'OR' in available_event: - available_events.append(available_event.split('OR')[1]) + available_events.append(available_event.split('OR')[1]) available_events[available_events.index(available_event)] = available_event.split()[0].strip() # Raw hex event codes can also be passed in that do not appear on perf/simpleperf list, prefixed with 'r' raw_event_code_regex = re.compile(r"^r(0x|0X)?[A-Fa-f0-9]+$") diff --git a/devlib/trace/screencapture.py b/devlib/collector/screencapture.py similarity index 97% rename from devlib/trace/screencapture.py rename to devlib/collector/screencapture.py index 699b2c6..0a5ca64 100644 --- a/devlib/trace/screencapture.py +++ b/devlib/collector/screencapture.py @@ -19,7 +19,7 @@ import sys import threading import time -from devlib.trace import TraceCollector +from devlib.collector import BaseCollector from devlib.exception import WorkerThreadError @@ -66,7 +66,7 @@ class ScreenCapturePoller(threading.Thread): self.target.capture_screen(os.path.join(self.output_path, "screencap_{ts}.png")) -class ScreenCaptureCollector(TraceCollector): +class ScreenCaptureCollector(BaseCollector): def __init__(self, target, output_path=None, period=None): super(ScreenCaptureCollector, self).__init__(target) diff --git a/devlib/trace/serial_trace.py b/devlib/collector/serial_trace.py similarity index 97% rename from devlib/trace/serial_trace.py rename to devlib/collector/serial_trace.py index b991a54..5a29f6b 100644 --- a/devlib/trace/serial_trace.py +++ b/devlib/collector/serial_trace.py @@ -17,11 +17,11 @@ import shutil from tempfile import NamedTemporaryFile from pexpect.exceptions import TIMEOUT -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase from devlib.utils.serial_port import get_connection -class SerialTraceCollector(TraceCollector): +class SerialTraceCollector(CollectorBase): @property def collecting(self): diff --git a/devlib/trace/systrace.py b/devlib/collector/systrace.py similarity index 98% rename from devlib/trace/systrace.py rename to devlib/collector/systrace.py index a359360..bdea7c6 100644 --- a/devlib/trace/systrace.py +++ b/devlib/collector/systrace.py @@ -20,7 +20,7 @@ from shutil import copyfile from tempfile import NamedTemporaryFile from devlib.exception import TargetStableError, HostError -from devlib.trace import TraceCollector +from devlib.collector import CollectorBase import devlib.utils.android from devlib.utils.misc import memoized @@ -33,7 +33,7 @@ DEFAULT_CATEGORIES = [ 'idle' ] -class SystraceCollector(TraceCollector): +class SystraceCollector(CollectorBase): """ A trace collector based on Systrace