Commit dbee7050 authored by Stefan Behnel's avatar Stefan Behnel

Make compiler pipeline a bit nicer to profile.

parent ba75e1df
...@@ -323,8 +323,15 @@ def insert_into_pipeline(pipeline, transform, before=None, after=None): ...@@ -323,8 +323,15 @@ def insert_into_pipeline(pipeline, transform, before=None, after=None):
# Running a pipeline # Running a pipeline
# #
_pipeline_entry_points = {}
def run_pipeline(pipeline, source, printtree=True): def run_pipeline(pipeline, source, printtree=True):
from .Visitor import PrintTree from .Visitor import PrintTree
exec_ns = globals().copy() if DebugFlags.debug_verbose_pipeline else None
def run(phase, data):
return phase(data)
error = None error = None
data = source data = source
...@@ -332,12 +339,19 @@ def run_pipeline(pipeline, source, printtree=True): ...@@ -332,12 +339,19 @@ def run_pipeline(pipeline, source, printtree=True):
try: try:
for phase in pipeline: for phase in pipeline:
if phase is not None: if phase is not None:
if not printtree and isinstance(phase, PrintTree):
continue
if DebugFlags.debug_verbose_pipeline: if DebugFlags.debug_verbose_pipeline:
t = time() t = time()
print("Entering pipeline phase %r" % phase) print("Entering pipeline phase %r" % phase)
if not printtree and isinstance(phase, PrintTree): # create a new wrapper for each step to show the name in profiles
continue phase_name = getattr(phase, '__name__', type(phase).__name__)
data = phase(data) try:
run = _pipeline_entry_points[phase_name]
except KeyError:
exec("def %s(phase, data): return phase(data)" % phase_name, exec_ns)
run = _pipeline_entry_points[phase_name] = exec_ns[phase_name]
data = run(phase, data)
if DebugFlags.debug_verbose_pipeline: if DebugFlags.debug_verbose_pipeline:
print(" %.3f seconds" % (time() - t)) print(" %.3f seconds" % (time() - t))
except CompileError as err: except CompileError as err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment