diff --git a/ietf/settings.py b/ietf/settings.py index 636e75820..d337a6ff7 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -951,6 +951,10 @@ CHECKS_LIBRARY_PATCHES_TO_APPLY = [ 'patch/add-patch-already-patched-flag.patch', 'patch/fix-patch-no-chdir.patch', ] +if DEBUG: + CHECKS_LIBRARY_PATCHES_TO_APPLY += [ + 'patch/add-django-cprofile-filter.patch', + ] STATS_NAMES_LIMIT = 25 diff --git a/patch/add-django-cprofile-filter.patch b/patch/add-django-cprofile-filter.patch new file mode 100644 index 000000000..4c469ff4e --- /dev/null +++ b/patch/add-django-cprofile-filter.patch @@ -0,0 +1,40 @@ +--- django_cprofile_middleware/middleware.py.old 2018-04-04 06:32:29.282187502 -0700 ++++ django_cprofile_middleware/middleware.py 2018-04-04 06:44:00.126537763 -0700 +@@ -1,4 +1,5 @@ + import pstats ++import re + + try: + import cProfile as profile +@@ -14,6 +15,15 @@ + from django.utils.deprecation import MiddlewareMixin + + ++class Stats(pstats.Stats): ++ def filter_stats(self, regex): ++ oldstats = self.stats ++ self.stats = newstats = {} ++ filter = re.compile(regex) ++ for func, (cc, nc, tt, ct, callers) in oldstats.iteritems(): ++ if filter.search(pstats.func_std_string(func)): ++ newstats[func] = (cc, nc, tt, ct, callers) ++ + class ProfilerMiddleware(MiddlewareMixin): + """ + Simple profile middleware to profile django views. To run it, add ?prof to +@@ -62,8 +72,13 @@ + response['Content-Length'] = len(output) + else: + io = StringIO() +- stats = pstats.Stats(self.profiler, stream=io) +- stats.strip_dirs().sort_stats(request.GET.get('sort', 'time')) ++ stats = Stats(self.profiler, stream=io) ++ if request.GET.get('stripdirs', False): ++ stats = stats.strip_dirs() ++ filter = request.GET.get('filter', None) ++ if filter: ++ stats.filter_stats(filter) ++ stats.sort_stats(request.GET.get('sort', 'time')) + stats.print_stats(int(request.GET.get('count', 100))) + response = HttpResponse('
%s
' % io.getvalue()) + return response