Source

middlewares / line_profiler.patch

Full commit
diff --git a/line_profiler.py b/line_profiler.py
--- a/line_profiler.py
+++ b/line_profiler.py
@@ -3,16 +3,17 @@
 
 import cPickle
 from cStringIO import StringIO
 import inspect
 import linecache
 import optparse
 import os
 import sys
+from decorator import decorator
 
 from _line_profiler import LineProfiler as CLineProfiler
 
 
 CO_GENERATOR = 0x0020
 def is_generator(f):
     """ Return True if a function is a generator.
     """
@@ -81,24 +82,25 @@ class LineProfiler(CLineProfiler):
                     finally:
                         self.disable_by_count()
                     yield item
             return f
 
     def wrap_function(self, func):
         """ Wrap a function to profile it.
         """
-        def f(*args, **kwds):
+        def f(_f, *args, **kwds):
             self.enable_by_count()
             try:
-                result = func(*args, **kwds)
+                result = _f(*args, **kwds)
             finally:
                 self.disable_by_count()
             return result
-        return f
+        # use decorator to keep the same arg signature on the function
+        return decorator(f, func)
 
     def dump_stats(self, filename):
         """ Dump a representation of the data to a file as a pickled LineStats
         object from `get_stats()`.
         """
         lstats = self.get_stats()
         f = open(filename, 'wb')
         try:
@@ -137,16 +139,18 @@ class LineProfiler(CLineProfiler):
             return func(*args, **kw)
         finally:
             self.disable_by_count()
 
 
 def show_func(filename, start_lineno, func_name, timings, unit, stream=None):
     """ Show results for a single function.
     """
+    if not timings:
+        return
     if stream is None:
         stream = sys.stdout
     print >>stream, "File: %s" % filename
     print >>stream, "Function: %s at line %s" % (func_name, start_lineno)
     template = '%6s %9s %12s %8s %8s  %-s'
     d = {}
     total_time = 0.0
     linenos = []