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

cpustates: Added the ability to configure how a missing start marker is handled.

cpustates can now handle the lack of a start marker in three ways:

 - try: If the start marker is present only the correct section of the trace
        will be used, if its not the whole trace will be used.
 - error: An error will be raised if the start marker is missing
 - ignore: The markers are ignored and the whole trace is always used.
This commit is contained in:
Sebastian Goscik
2016-06-06 16:07:01 +01:00
parent 1811a8b733
commit f276d4e39f
3 changed files with 72 additions and 33 deletions

View File

@@ -17,7 +17,7 @@ import re
import logging
from itertools import chain
from wlauto.utils.misc import isiterable
from wlauto.utils.misc import isiterable, memoized
from wlauto.utils.types import numeric
@@ -215,37 +215,38 @@ EMPTY_CPU_REGEX = re.compile(r'CPU \d+ is empty')
class TraceCmdTrace(object):
def __init__(self, filter_markers=True):
self.filter_markers = filter_markers
@property
@memoized
def has_start_marker(self):
with open(self.file_path) as fh:
for line in fh:
if TRACE_MARKER_START in line:
return True
return False
def parse(self, filepath, names=None, check_for_markers=True): # pylint: disable=too-many-branches,too-many-locals
def __init__(self, file_path, names=None, filter_markers=True):
self.filter_markers = filter_markers
self.file_path = file_path
self.names = names or []
def parse(self): # pylint: disable=too-many-branches,too-many-locals
"""
This is a generator for the trace event stream.
"""
inside_maked_region = False
filters = [re.compile('^{}$'.format(n)) for n in names or []]
if check_for_markers:
with open(filepath) as fh:
for line in fh:
if TRACE_MARKER_START in line:
break
else:
# maker not found force filtering by marker to False
self.filter_markers = False
with open(filepath) as fh:
inside_marked_region = False
filters = [re.compile('^{}$'.format(n)) for n in self.names or []]
with open(self.file_path) as fh:
for line in fh:
# if processing trace markers, skip marker lines as well as all
# lines outside marked region
if self.filter_markers:
if not inside_maked_region:
if not inside_marked_region:
if TRACE_MARKER_START in line:
inside_maked_region = True
inside_marked_region = True
continue
elif TRACE_MARKER_STOP in line:
inside_maked_region = False
continue
break
match = DROPPED_EVENTS_REGEX.search(line)
if match:
@@ -282,4 +283,7 @@ class TraceCmdTrace(object):
if isinstance(body_parser, basestring) or isinstance(body_parser, re._pattern_type): # pylint: disable=protected-access
body_parser = regex_body_parser(body_parser)
yield TraceCmdEvent(parser=body_parser, **match.groupdict())
else:
if self.filter_markers and inside_marked_region:
logger.warning('Did not encounter a stop marker in trace')