gstreamer/tracer/tracer/analysis_runner.py
Stefan Sauer ee72bd1b09 tracer: parser: small speedup
Add a parser_perf test. Skip the extra filter stage and change the regex to
match on category=TRACE lines only.
Also flip the check in analysis_runner, since we only have a few tracer
classes in the beginning, the rest are tracer entries.
2016-12-25 11:38:28 +01:00

47 lines
1.4 KiB
Python

try:
from tracer.parser import Parser
except:
from parser import Parser
class AnalysisRunner(object):
"""
Runs several Analyzers over a log.
Iterates log using a Parser and dispatches to a set of analyzers.
"""
def __init__(self, log):
self.log = log
self.analyzers = []
def add_analyzer(self, analyzer):
self.analyzers.append(analyzer)
def handle_tracer_class(self, event):
for analyzer in self.analyzers:
analyzer.handle_tracer_class(event)
def handle_tracer_entry(self, event):
for analyzer in self.analyzers:
analyzer.handle_tracer_entry(event)
def is_tracer_class(self, event):
return (event[Parser.F_FILENAME] == 'gsttracerrecord.c' and
event[Parser.F_CATEGORY] == 'GST_TRACER' and
'.class' in event[Parser.F_MESSAGE])
def is_tracer_entry(self, event):
return (not event[Parser.F_LINE] and not event[Parser.F_FILENAME])
def run(self):
try:
for event in self.log:
# check if it is a tracer.class or tracer event
if self.is_tracer_entry(event):
self.handle_tracer_entry(event)
elif self.is_tracer_class(event):
self.handle_tracer_class(event)
#else:
# print("unhandled:", repr(event))
except StopIteration:
pass