From 12a39199926da68be6e4103bdf0e3813f65c9dac Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 2 Aug 2015 20:34:28 -0700 Subject: [PATCH] Show intermediary compilation(s) when BLATHER is enabled This information can be useful for analyzing why/what is generated during each intermediary flow/subflow and task compilation call so include showing it when and only when the BLATHER level logging is on. Change-Id: I8e9508b8250533a4830fe78705d867139b1eab36 --- taskflow/engines/action_engine/compiler.py | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/taskflow/engines/action_engine/compiler.py b/taskflow/engines/action_engine/compiler.py index 22b130a8..50ce4eb1 100644 --- a/taskflow/engines/action_engine/compiler.py +++ b/taskflow/engines/action_engine/compiler.py @@ -372,6 +372,7 @@ class PatternCompiler(object): _FlowCompiler(self._compile, self._linker), _TaskCompiler(), ] + self._level = 0 def _compile(self, item, parent=None): """Compiles a item (pattern, task) into a graph + tree node.""" @@ -392,13 +393,28 @@ class PatternCompiler(object): " and/or recursive compiling is not" " supported" % (item, type(item))) self._history.add(item) + if LOG.isEnabledFor(logging.BLATHER): + LOG.blather("%sCompiling '%s'", " " * self._level, item) + self._level += 1 def _post_item_compile(self, item, graph, node): """Called after a item is compiled; doing post-compilation actions.""" + self._level -= 1 + if LOG.isEnabledFor(logging.BLATHER): + prefix = ' ' * self._level + LOG.blather("%sDecomposed '%s' into:", prefix, item) + prefix = ' ' * (self._level + 1) + LOG.blather("%sGraph:", prefix) + for line in graph.pformat().splitlines(): + LOG.blather("%s %s", prefix, line) + LOG.blather("%sHierarchy:", prefix) + for line in node.pformat().splitlines(): + LOG.blather("%s %s", prefix, line) def _pre_compile(self): """Called before the compilation of the root starts.""" self._history.clear() + self._level = 0 def _post_compile(self, graph, node): """Called after the compilation of the root finishes successfully.""" @@ -411,19 +427,6 @@ class PatternCompiler(object): raise exc.Empty("Root container '%s' (%s) is empty" % (self._root, type(self._root))) self._history.clear() - # NOTE(harlowja): this one can be expensive to calculate (especially - # the cycle detection), so only do it if we know BLATHER is enabled - # and not under all cases. - if LOG.isEnabledFor(logging.BLATHER): - LOG.blather("Translated '%s'", self._root) - LOG.blather("Graph:") - for line in graph.pformat().splitlines(): - # Indent it so that it's slightly offset from the above line. - LOG.blather(" %s", line) - LOG.blather("Hierarchy:") - for line in node.pformat().splitlines(): - # Indent it so that it's slightly offset from the above line. - LOG.blather(" %s", line) @fasteners.locked def compile(self):