Skip to content

Commit

Permalink
Merge pull request #10 from ilyaGotfryd/NT-76-togglable-memory-profil…
Browse files Browse the repository at this point in the history
…ing-to-fluentd

NT-76 adding memory profiler exclusion flag
  • Loading branch information
Scott Stahl authored Mar 8, 2018
2 parents 585e855 + 71267d3 commit 6866f96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions turbogears/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def _expose(func, accept, allow_json, *args, **kw):

def expose(template=None, validators=None, allow_json=None, html=None,
format=None, content_type=None, inputform=None, fragment=False,
as_format="default", mapping=None, accept_format=None):
as_format="default", mapping=None, accept_format=None,
exclude_from_memory_profiling=False):
"""Exposes a method to the web.
By putting the expose decorator on a method, you tell TurboGears that
Expand Down Expand Up @@ -324,7 +325,8 @@ def expose(template=None, validators=None, allow_json=None, html=None,
applied to that arg
@keyparam inputform deprecated. A form object that generates the
input to this method
@keyparam exclude_from_memory_profiling allows to exclude individual end points from memory profiling. Can be
used for performance or in case profiling generates errors
"""
if html:
template = html
Expand Down Expand Up @@ -354,7 +356,8 @@ def expose(func, *args, **kw):
*args, **kw)
else:
request.in_transaction = True
output = profile_expose_method(_run_with_transaction, accept, args, func, kw)
output = profile_expose_method(_run_with_transaction, accept, args, func, kw,
exclude_from_memory_profiling)
return output
func.exposed = True
func._ruleinfo = []
Expand Down
4 changes: 2 additions & 2 deletions turbogears/memory_profiler_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def toggle_memory_profile_logging(_thread_log):
_thread_log.info(' SET MEMORY_PROFILE_LOGGING_ON={}'.format(not memory_profile_logging_on))


def profile_expose_method(profiled_method_wrapper, accept, args, func, kw):
def profile_expose_method(profiled_method_wrapper, accept, args, func, kw, exclude_from_memory_profiling):
"""
Targeted to profile a specific method that wraps HTTP request processing endpoints into database context.
:param profiled_method_wrapper: method wrapped around profiled call to be passed in to memory profiler
Expand All @@ -114,7 +114,7 @@ def profile_expose_method(profiled_method_wrapper, accept, args, func, kw):
:param kw: kwargs of a function that is being wrapped by a profiled method
:return: output of a profiled method without modification
"""
if get_memory_profile_logging_on():
if not exclude_from_memory_profiling and get_memory_profile_logging_on():
profile_output = {'output': {}}
memory_profile = memory_usage((_profile_me,
(profile_output, profiled_method_wrapper, func, accept, args, kw),
Expand Down

0 comments on commit 6866f96

Please sign in to comment.