Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#
# These functions will be run once per request, so make sure they are fast.
#
# If you need access to the environ use the `with_environ` decorator.
#
# Example:
# ...in appengine_config.py:
# def gae_mini_profiler_should_profile_production():
Expand All @@ -30,13 +32,26 @@ def _should_profile_development_default():
Can be overridden in appengine_config.py"""
return True

def with_environ(func):
"""Decorator to distinguish should_profile_*() methods that need access
to the environ"""
func._accept_environ = True
return func

_config = lib_config.register("gae_mini_profiler", {
"should_profile_production": _should_profile_production_default,
"should_profile_development": _should_profile_development_default})

def should_profile():
def should_profile(environ):
"""Returns true if the current request should be profiles."""
if util.dev_server:
return _config.should_profile_development()
func = _config.should_profile_development
else:
return _config.should_profile_production()
func = _config.should_profile_production

if getattr(func, '_accept_environ', False):
args = environ,
else:
args = tuple()

return func(*args)
2 changes: 1 addition & 1 deletion profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def __call__(self, environ, start_response):
CurrentRequestId.set(None)

# Never profile calls to the profiler itself to avoid endless recursion.
if (not config.should_profile() or
if (not config.should_profile(environ) or
environ.get("PATH_INFO", "").startswith("/gae_mini_profiler/")):
result = self.app(environ, start_response)
for value in result:
Expand Down