Repository: Theano/Theano

Issue:
Sub-profile for scan ops are not printed any more
Neither in the old or new back-end, but they are still there for CPU.


Discussion:
Actually, it prints "skipping empty profile", so the code for printing the profile seems to be there, but the right profile does not seem to be associated with the execution of scan.
Is this related to https://github.com/Theano/Theano/pull/5455?
I don't think so, the profile for the main function is still there, but the profile for the step function of scan is not, even in the old back-end.

Resolving patch:
diff --git a/theano/compile/profiling.py b/theano/compile/profiling.py
--- a/theano/compile/profiling.py
+++ b/theano/compile/profiling.py
@@ -9,30 +9,29 @@
 #
 from __future__ import absolute_import, print_function, division
 
-import logging
-
-__authors__ = "James Bergstra"
-__reviewer__ = "Razvan Pascanu"
-__copyright__ = "(c) 2011, Universite de Montreal"
-__license__ = "3-clause BSD License"
-__contact__ = "theano-dev <theano-dev@googlegroups.com>"
-
-__docformat__ = "restructuredtext en"
-
 import atexit
 import copy
+import logging
 import operator
 import os
 import sys
 import time
 from collections import defaultdict
+from six import iteritems
 
 import numpy as np
 
 import theano
-from six import iteritems
 from theano.gof import graph
 
+__authors__ = "James Bergstra"
+__reviewer__ = "Razvan Pascanu"
+__copyright__ = "(c) 2011, Universite de Montreal"
+__license__ = "3-clause BSD License"
+__contact__ = "theano-dev <theano-dev@googlegroups.com>"
+
+__docformat__ = "restructuredtext en"
+
 logger = logging.getLogger('theano.compile.profiling')
 
 theano_imported_time = time.time()
@@ -62,8 +61,9 @@ def _atexit_print_fn():
 
         # Reverse sort in the order of compile+exec time
         for ps in sorted(_atexit_print_list,
-                         key=lambda a:a.compile_time + a.fct_call_time)[::-1]:
-            if ps.fct_callcount >= 1 or ps.compile_time > 1:
+                         key=lambda a: a.compile_time + a.fct_call_time)[::-1]:
+            if (ps.fct_callcount >= 1 or ps.compile_time > 1 or
+                    getattr(ps, 'callcount', 0) > 1):
                 ps.summary(file=destination_file,
                            n_ops_to_print=config.profiling.n_ops,
                            n_apply_to_print=config.profiling.n_apply)
@@ -115,6 +115,7 @@ def _atexit_print_fn():
     if config.print_global_stats:
         print_global_stats()
 
+
 def print_global_stats():
     """
     Print the following stats:
@@ -132,7 +133,7 @@ def print_global_stats():
     else:
         destination_file = open(config.profiling.destination, 'w')
 
-    print('='*50, file=destination_file)
+    print('=' * 50, file=destination_file)
     print('Global stats: ',
           'Time elasped since Theano import = %6.3fs, '
           'Time spent in Theano functions = %6.3fs, '
@@ -143,7 +144,7 @@ def print_global_stats():
            total_graph_opt_time,
            total_time_linker),
           file=destination_file)
-    print('='*50, file=destination_file)
+    print('=' * 50, file=destination_file)
 
 
 class ProfileStats(object):
@@ -728,7 +729,7 @@ def summary_function(self, file):
               file=file)
 
         for node, t in sorted(self.linker_make_thunk_time.items(),
-                                 key=operator.itemgetter(1))[::-1][:5]:
+                              key=operator.itemgetter(1))[::-1][:5]:
             print('           Node %s time %es' % (node, t),
                   file=file)
         print('', file=file)
@@ -1131,7 +1132,7 @@ def min_memory_generator(executable_nodes, viewed_by, view_of):
 
             # Store the max of some stats by any function in this profile.
             max_sum_size = max(max_sum_size, sum_size)
-            
+
             def compute_max_stats(running_memory, stats):
                 (max_node_memory_size,
                  max_running_max_memory_size,


Test patch:
diff --git a/theano/tests/test_flake8.py b/theano/tests/test_flake8.py
--- a/theano/tests/test_flake8.py
+++ b/theano/tests/test_flake8.py
@@ -37,7 +37,6 @@
     "__init__.py",
     "tests/__init__.py",
     "compile/__init__.py",
-    "compile/profiling.py",
     "compile/sandbox/__init__.py",
     "compile/tests/__init__.py",
     "gpuarray/__init__.py",